Oracle基本查詢

來源:互聯網
上載者:User

標籤:通過   where   行編輯   設定   資料   儲存   軟體   nes   class   

本例的操作前期都在控制台完成,後期會使用用戶端。 
 1 SQL> --設定行寬 2 SQL> show linesize 3 linesize 80 4 SQL> set linesize  150 5 SQL> --設定列寬 6 SQL> col ename format a8 7 SQL> col sal for 9999 8 //col是column的縮寫,代表列,在sqlplus中比sql方便的是支援縮寫 9 //for是format的縮寫,10 //a代表一個符號位,8代表長度11 //9代表一個數字記號位,9999代表該列的列寬為4個數字長度
1 SQL> --查詢員工資訊:員工號 姓名 月薪 年薪 獎金 年度營收2 SQL> select empno,ename,sal,sal*12,comm,sal*12+comm3 //可以直接在語句中進行計算
 1 /* 2 SQL> SQL中的null值: 3 SQL> 1. 包含null的運算式都為null 4 SQL> 2. null永遠!=null 5 SQL> *、 6 SQL> */ 7 SQL> select empno,ename,sal,sal*12,comm,sal*12+nvl(comm,0) 8 在實際使用的過程中,如果 某個運算式包含空值,那麼這個運算式的結果也為null; 9 不能通過=號來判斷資料是否為空白,應該用is10 錯誤: where comm=null;11 正確:where comm is null;
 1 NVL(a,b) 2 nvl函數表示如果a為空白,那麼取值為b,不為空白,取原值。 3 例如: 4 SQL> select empno,ename,sal,sal*12,comm,sal*12+nvl(comm,0) 5   2  from emp; 6 拓展: 7 SQL> ed 8 使用預設的記事本軟體開啟上一條sql語句進行編輯 9 儲存關閉後10 SQL> /11 使用/來執行儲存的語句,也就是執行上一條語句
1 去除重複2 SQL> --distinct 去掉重複記錄3 SQL> select deptno from emp;有重複4 SQL> select distinct deptno from emp;沒有重複5 去重兩個作用與兩個列6 SQL> select distinct deptno,job from emp;7 上一行的語句意思是:去除部門號和職位都相同的資料8  
 1 SQL> --串連符 || 2 SQL> -- concat 3 SQL> select concat(‘Hello‘,‘  World‘) from dual; 4 CONCAT(‘HELL                                                                                                                                           5 ------------                                                                                                                                           6 Hello  World 7 SQL> --dual表:偽表 8 dual是資料庫提供的偽表,要查詢的操作不屬於任何的表時,就需要使用此表進行佔位。 9 SQL> select 3+2 from dual;10        3+2                                                                                                                                            11 ----------                                                                                                                                            12          5                                                                                                                                            SQL> select ‘Hello‘||‘  World‘  字串 from dual;13 字串                                                                                                                                                14 ------------                                                                                                                                          15 Hello  World16 SQL> --查詢員工資訊:***的薪水是****17 SQL> select ename||‘的薪水是‘||sal 資訊 from emp;18 資訊                                                                                                                                                  19 ----------------------------------------------------------                                                                                            20 SMITH的薪水是800 

 

 

Oracle基本查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.