Oracle資料庫零散知識03

來源:互聯網
上載者:User

標籤:

 

 

21,預存程序,簡化複雜操作,增加資料獨立性,提高安全性,提高效能

與函數建立對比:

create or replace function fun_01(v_01 in number)    return number--必須要求有傳回值    as    result number;    begin    result := power(v_01,2);    return result;    end;    /Function created.select fun_01(9) from dual; FUN_01(9)----------        81

  

預存程序建立樣本,不要求有傳回值:

create or replace procedure pro_01(v_01 in number)    as    result number;    begin    result := power(v_01,2);    dbms_output.put_line(result);    end;    /Procedure created.execute pro_01(9);81PL/SQL procedure successfully completed.

  

22,觸發器,一種特殊的預存程序

create table log_tab--建立一個日誌表    (    l_id number(3),    l_old varchar2(20),--刪除和已更新的主鍵    l_type varchar2(10),--執行的操作類型    l_new varchar2(20),--添加和已更新的主鍵    l_date date,--更改的日期    constraint pk_log_tab primary key(l_id)    );Table created.

  

create sequence log_tab_id--建立一個序列    minvalue 100    maxvalue 300    start with 100    increment by 1;Sequence created.

  

create or replace trigger tr_student02--建立一個觸發器    after insert or update or delete –後插入更新刪除    on student02--針對student02表    for each row—針對行觸發    begin    case    when inserting then—插入觸發    insert into log_tab values    (   log_tab_id.nextval,   null,   ‘insert‘,   :new.sno,--匯入inserted表中資料   sysdate);   when deleting then—刪除觸發   insert into log_tab values   (   log_tab_id.nextval,   :old.sno,--匯入deleted表中資料   ‘delete‘,   null,   sysdate);   when updating then—更新觸發   insert into log_tab values   (   log_tab_id.nextval,   :old.sno,   ‘update‘,   :new.sno,   sysdate);   end case;  end;

  

delete from student02 where rownum = 1;insert into student02(sno,sname,ssex) values(123,‘hook‘,‘m‘); update student02 set sname = ‘tokl‘ where sno = 123; select * from log_tab;      L_ID L_OLD                L_TYPE     L_NEW                L_DATE---------- -------------------- ---------- -------------------- ---------       101 109                  delete                          28-OCT-15       102                      insert     123                  28-OCT-15       103 123                  update     123                  28-OCT-15

 

23,Oracle別名as使用的時候,不能使用在表上,只能使用在列上,表使用空格別名。。

24,萬用字元‘_‘使用的時候,如果欄位使用的char型,固定長度,需要用萬用字元補全

25,排序 空值在前在後  nulls first ..nulls last

Oracle資料庫零散知識03

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.