oracle 數據庫小知識總結

  1. 在黑窗口中導出所寫的語句:
    spool e:/aa.sql;(在開始的時候執行,e:/aa.sql是保存文件的路徑和名稱)
    spool off;(在想要結束的時候使用)mysql

  2. 顯示用戶:show user;sql

  3. 更改用戶:conn 用戶名/密碼@服務名; 
        若是是以管理員的身份登陸的話能夠這樣:
        conn sys/aa as sysdba;數據庫

  4. 解鎖:
        alter user scott account unlock;ide

  5. 修改密碼:
        alter user scott identified by 新密碼;sqlserver

  6. 將刪除的權利賦予某個角色:
        grant delete on tablename to 角色;server

  7. 顯示錯誤:
        show error;rem

  8. 打開Oracle的運行環境:
    開始-->運行-->cmd-->sqlpluscmd

  9. 添加惟一約束:it

    在建立表的時候直接添加table

         create table table_name(

    column1 datatype null/not null,

    ……

    constraint unique_name unique(column1……))

    在建立以後添加約束:

        alter table table_name add constraint unique_name unique(column1,column2……)

  10. 表中添加一列: alter table tablename add (column datatype [default value][null/not null],….);

  11. 修改字段的語法:alter table tablename modify (column datatype [default value][null/not null],….);

  12. 刪除字段的語法:alter table tablename drop (column);

  13. 刪除sequence :drop sequence SEQ_NAME;

  14. 導入導出數據庫:
    exp AAA/AAA@130.251.101.4/orcl file=e:\AAA0904.dmp owner=(AAA);
    imp AAA/AAA@130.251.101.92/orcl full=y file=e:\AAA(init).dmp ignore=y;

  15. 主鍵是拼接:
    <selectKey resultClass="String" keyProperty="id">
                SELECT 'CG-'|| to_char(current_timestamp,'yyyyMMdd')||'-'||lpad(to_char(SEQ_NAME.nextval),3,'0') FROM DUAL
    </selectKey>

  16. 建立序列:

    create sequence SEQ_NAME
    increment by 1
    start with 1
     maxvalue 999
     minvalue 1
    cycle
     cache 20
    order;

  17. 數據相加減:SELECT isnull(A,0)-isnull(B,0) AS 結果 FROM 表  --sqlserver語法SELECT nvl(A,0)-nvl(B,0) AS 結果 FROM 表  --Oracle語法SELECT ifnull(A,0)-ifnull(B,0) AS 結果 FROM 表  --mysql語法 NVL( total , 0)  +   NVL( money, 0)---Oracle  或者  DB2 ISNULL( total , 0)  +   ISNULL( money, 0)-- SQL  Server IFNULL( total , 0)  +  IFNULL( money, 0)--MySQL  或者 SQLite   

相關文章
相關標籤/搜索