posts - 11, comments - 0, trackbacks - 0, articles - 0

          Oracle命令

          Posted on 2011-04-29 10:02 HsiangYu 閱讀(151) 評論(0)  編輯  收藏 所屬分類: Oracle
          1.  1、set linesize 100;  設置長度  
          2.  2、set pagesize 30;   設置每頁顯示數目  
          3.  3、ed a.sql  打開記事本    
          4.  4、@ a 執行文件a中的代碼,可指定文件的路徑 @d:a.txt  
          5.  5、conn 用戶名/密碼  根據用戶名和密碼連接數據庫 如果連接超級管理員(sys) 則應加上as sysdba;  
          6.  6、show user; 顯示當前連接的用戶  
          7.  7、select * from tab;  得到當前用戶下的所有表  
          8.  8、desc temp; 查看表結構  
          9.  9、/  繼續執行上一個查詢語句  
          10.     clear scr;  清屏  
          11.   
          12. 字符函數  
          13. 10、select upper('coolszy'from dual; 將小寫字母轉換成大寫,dual 為一虛表  
          14. 11、select lower('KUKA'from dual; 將大寫字母轉換成小寫  
          15. 12、select initcap('kuka'from dual; 將首字母大寫   
          16. 13、select concat('Hello',' world'from dual; 連接字符串,但沒有||好用select concat('Hello','world'from dual;  
          17. 14、select substr('hello',1,3) from dual; 截取字符串  
          18. 15、select length('hello'from dual; 求字符串長度  
          19. 16、select replace('hello','l','x'from dual; 替換字符串   
          20. 17、select substr('hello',-3,3) from dual; 截取后三位  
          21.   
          22. 數值函數  
          23. 18、select round(789.536) from dual; 四舍五入,舍去小數  
          24. 19、select round(789.536,2) from dual; 保留兩位小數  
          25. 20、select round(789.536,-1) from dual; 對整數進行四舍五入  
          26. 21、select trunc(789.536) from dual; 舍去小數,但不進位  
          27. 22、select trunc(789.536,2) from dual;  
          28. 23、select trunc(789.536,-2) from dual;  
          29. 24、select mod(10,3) from dual; 返回10%3的結果  
          30.   
          31. 日期函數  
          32. 25、select sysdate from dual; 返回當前日期  
          33. 26、select months_between(sysdate,'16-6月 -08'from dual; 返回之間的月數  
          34. 27、select add_months(sysdate,4) from dual; 在日期上加上月數  
          35. 28、select next_day(sysdate,'星期一'from dual; 求下一個星期一  
          36. 29、select last_day(sysdate) from dual; 求本月的最后一天  
          37.   
          38.   
          39. 轉換函數  
          40. 30、select to_char(sysdate,'yyyy'year,to_char(sysdate,'mm'),to_char(sysdate,'dd'from dual;  
          41. 31、select to_char(sysdate,'yyyy-mm-dd'from dual;  
          42. 32、select to_char(sysdate,'fmyyyy-mm-dd'from dual; 取消月 日 前面的0  
          43. 33、select to_char('20394','99,999'from dual; 分割錢 9表示格式  
          44. 34、select to_char('2034','L99,999'from dual; 加上錢幣符號  
          45. 35、select to_number('123')*to_number('2'from dual;  
          46. 36、select to_date('1988-07-04','yyyy-mm-dd'from dual;   
          47.   
          48. 通用函數  
          49. 37、select nvl(null,0) from dual; 如果為null,則用0代替  
          50. 38、select decode(1,1,'內容是1',2,'內容是2',3,'內容是3'from dual; 類似于 switch...case...  
          51.   
          52. 事務處理  
          53. 39、commit;  提交事務  
          54. 40、rollback; 回滾事務  
          55.   
          56.   
          57. 41、select rownum from table; 在沒一列前面顯示行號  
          58. 42、drop table 表名 cascade constraint   
          59.     on delete casecade 當父表中的內容被刪除后,子表中的內容也被刪除  
          60.   
          61. 43、desc表名 顯示表的結構  
          62. 44、create user [username] identified by [password] 創建新的用戶  
          63. 45、grant 權限1、權限2...to 用戶  給創建用戶權限  
          64.  ex:grant create session to [username] 此時只能連接到數據庫  
          65.     grant connect,resource to [username] 此時權限能滿足要求  
          66. 46、alter user [username] identified by [password] 修改用戶密碼  
          67. 47、alter user [username] password expired 下次登錄時提示修改密碼  
          68. 48、alter user [username] account lock  鎖住用戶  
          69. 49、alter user [username] account unlock  解鎖鎖用戶  
          70. 50、grant select,delete on scott.emp to [username] 把scott下emp表的兩個權限給用戶  
          71. 51、revoke select ,delete on scott.emo from [username] 回收權限 

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 仪征市| 化德县| 福贡县| 奇台县| 丹东市| 海盐县| 三河市| 昭觉县| 贡嘎县| 东港市| 奉新县| 九寨沟县| 汽车| 宜章县| 迁西县| 南康市| 巨野县| 中江县| 广东省| 阿拉善左旗| 清水河县| 上高县| 义乌市| 固阳县| 汽车| 伊金霍洛旗| 利辛县| 白沙| 堆龙德庆县| 大厂| 水富县| 孟津县| 响水县| 奇台县| 东兰县| 克东县| 建水县| 敦化市| 乌什县| 肇源县| 梁河县|