oracle基本的查询语句,oracle 基本查询语句及实例
1、查詢所有列
select * from 表名;
2、查詢表結構
desc 表名;
3、查詢指定列
select ename,sal,job from 表名;
4、racle中查看所有表和字段
獲取表:
select table_name from user_tables; //當前用戶的表
select table_name from all_tables; //所有用戶的表
select table_name from dba_tables; //包括系統表
select table_name from dba_tables where owner='用戶名'
user_tables:
table_name,tablespace_name,last_analyzed等
dba_tables:
ower,table_name,tablespace_name,last_analyzed等
all_tables:
ower,table_name,tablespace_name,last_analyzed等
all_objects:
ower,object_name,subobject_name,object_id,created,last_ddl_time,timestamp,status等
獲取表字段:
select * from user_tab_columns where Table_Name='用戶表';
select * from all_tab_columns where Table_Name='用戶表';
select * from dba_tab_columns where Table_Name='用戶表';
user_tab_columns:
table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
all_tab_columns :
ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
dba_tab_columns:
ower,table_name,column_name,data_type,data_length,data_precision,data_scale,nullable,column_id等
獲取表注釋:
select * from user_tab_comments
user_tab_comments:table_name,table_type,comments
相應的還有dba_tab_comments,all_tab_comments,
這兩個比user_tab_comments多了ower列。
獲取字段注釋:
select * from user_col_comments
user_col_comments:table_name,column_name,comments
相應的還有dba_col_comments,all_col_comments,
這兩個比user_col_comments多了ower列。
5、鎖定oracle用戶及解除鎖定
alter user scott account lock
alter user scott account unlock
6、where字句
select * from 表名 where 字段>數值;
select * from 表明 where to_char(字段,'yyyy-mm-dd')>'1982-1-1'; ? ?to_char轉換函數
select * from 表明 where to_char(字段,'yyyy')='1980';
select * from 表明 where to_char(字段,'mm')='4';
顯示工資在2000到2500工資
select * from 表名 where 字段>=2000 and 字段<=2500;
select * from 表明 where 字段 between 2000 and 2500;
7、模糊查詢 like
%:表示任意0到多個字符 ?; ?_ : 表示任意單個字符
如何顯示首字母為S的員工姓名及工資
select eaname, sal from 表名 where eaname like 'S%' ;
如何顯示第三個字母為O的所有員工姓名及工資
select?eaname, sal from 表名 where eaname like '__O%';
8、where語句使用 in
如何顯示empno 為 123,345,678的雇員情況
1、select * from ?表明 where empno=123 or?empno=345 or?empno=678;
select * from 表明 where empno in (123,345,678);
2、is null 空值查詢
select * from 表明 where 字段名 is null ;
3、oracle邏輯運算符
查詢工資高于500或是崗位為MSN的雇員,同時還要滿足他們的姓名首字母大學J
select * from 表明 where (sal>500 or job='MSN') and (enname like 'J%' );
總結
以上是生活随笔為你收集整理的oracle基本的查询语句,oracle 基本查询语句及实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle双机冷备方案,Oracle
- 下一篇: MATLAB观察系统响应,基于MATLA