ORACLE常用函數實例

1、set linesize 100;  設置長度   

 2、set pagesize 30;   設置每頁顯示數目   

 3、em a.sql  打開記事本     

 4、@ a 執行文件a中的代碼,可指定文件的路徑 @d:a.txt   

 5、conn 用戶名/密碼  根據用戶名和密碼連接數據庫 如果連接超級管理員(sys) 則應加上as sysdba;   

 6、show user; 顯示當前連接的用戶   

 7、select * from tab;  得到當前用戶下的所有表   

 8、desc temp; 查看錶結構   

 9、/  繼續執行上一個查詢語句   

    clear scr;  清屏   

  

字符函數   

10、select upper('coolszy'from dual; 將小寫字母轉換成大寫,dual 爲一虛表   

11、select lower('KUKA'from dual; 將大寫字母轉換成小寫   

12、select initcap('kuka'from dual; 將首字母大寫    

13、select concat('Hello',' world'from dual; 連接字符串,但沒有||好用select concat('Hello','world'from dual;   

14、select substr('hello',1,3) from dual; 截取字符串   

15、select length('hello'from dual; 求字符串長度   

16、select replace('hello','l','x'from dual; 替換字符串    

17、select substr('hello',-3,3) from dual; 截取後三位   

  

數值函數   

18、select round(789.536) from dual; 四捨五入,捨去小數   

19、select round(789.536,2) from dual; 保留兩位小數   

20、select round(789.536,-1) from dual; 對整數進行四捨五入   

21、select trunc(789.536) from dual; 捨去小數,但不進位   

22、select trunc(789.536,2) from dual;   

23、select trunc(789.536,-2) from dual;   

24、select mod(10,3) from dual; 返回10%3的結果   

  

日期函數   

25、select sysdate from dual; 返回當前日期   

26、select months_between(sysdate,'16-6月 -08'from dual; 返回之間的月數   

27、select add_months(sysdate,4) from dual; 在日期上加上月數   

28、select next_day(sysdate,'星期一'from dual; 求下一個星期一   

29、select last_day(sysdate) from dual; 求本月的最後一天   

  

  

轉換函數   

30、select to_char(sysdate,'yyyy'year,to_char(sysdate,'mm'),to_char(sysdate,'dd'from dual;   

31、select to_char(sysdate,'yyyy-mm-dd'from dual;   

32、select to_char(sysdate,'fmyyyy-mm-dd'from dual; 取消月 日 前面的0   

33、select to_char('20394','99,999'from dual; 分割錢 9表示格式   

34、select to_char('2034','L99,999'from dual; 加上錢幣符號   

35、select to_number('123')*to_number('2'from dual;   

36、select to_date('1988-07-04','yyyy-mm-dd'from dual;    

  

通用函數   

37、select nvl(null,0) from dual; 如果爲null,則用0代替   

38、select decode(1,1,'內容是1',2,'內容是2',3,'內容是3'from dual; 類似於 switch...case...   

  

事務處理   

39、commit;  提交事務   

40、rollback; 回滾事務   

  

  

41、select rownum from table; 在沒一列前面顯示行號   

42、drop table 表名 cascade constraint    

    on delete casecade 當父表中的內容被刪除後,子表中的內容也被刪除   

  

43、desc表名 顯示錶的結構   

44、create user [username] identified by [password] 創建新的用戶   

45、grant 權限1、權限2...to 用戶  給創建用戶權限   

 ex:grant create session to [username] 此時只能連接到數據庫   

    grant connect,resource to [username] 此時權限能滿足要求   

46、alter user [username] identified by [password] 修改用戶密碼   

47、alter user [username] password expired 下次登錄時提示修改密碼   

48、alter user [username] account lock  鎖住用戶   

49、alter user [username] account unlock  解鎖鎖用戶   

50、grant select,delete on scott.emp to [username] 把scott下emp表的兩個權限給用戶   

51、revoke select ,delete on scott.emo from [username] 回收權限



http://www.cnblogs.com/vic_lu/archive/2010/08/28/1811097.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章