oracle 基本查詢語句及例項

2021-07-02 13:25:56 字數 1381 閱讀 9681

1、查詢所有列

select * from 表名;

2、查詢表結構

desc 表名;

3、查詢指定列

select ename,sal,job from 表名;

4、oracle中檢視所有表和字段

獲取表:

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='使用者名稱'

5、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;

6、模糊查詢 like

%:表示任意0到多個字元  ;  _ : 表示任意單個字元

如何顯示首字母為s的員工姓名及工資

select eaname, sal from 表名 where eaname like 's%' ;

如何顯示第三個字母為o的所有員工姓名及工資

select eaname, sal from 表名 where eaname like '__o%';

7、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的基本查詢語句

1 查詢語句 語法格式 select from table where codition 注 1 table指定表名 2 column用於指定列名 3 expression用於指定表示式 4 alias用於指定列的別名 5 condition用於指定查詢條件 6 distinct用於去除重複列 2 ...

Oracle查詢語句

select sysdate from dual dual 臨時的表,使語法結構完整,沒有什麼意義。oracle中的select語句必須要有from 而sql2008中可以沒有。起別名 起別名 as起別名,不用加雙引號.加空格起別名,要加雙引號 select name as 姓名 from stud...

Oracle查詢語句

列出所有部門的詳細資訊和部門人數。這裡需要部門的詳細資訊和部門人數,顯然需要我們進行表的連線 那麼這裡我們先貼出兩張表長啥樣 像這樣的關於兩張表的連線,那麼我們一般先一張一張來 比如這裡我們可以先解決部門的詳細資訊 然後解決部門人數 select deptno,count 1 人數 from emp...