Oracle Pl/SQL 之 儲存過程

starive發表於2014-02-08
建立一個儲存過程的語法:
create [or replace] procedure 過程名
            [(引數名 [IN | OUT | IN OUT] 資料型別  ...]

{IS  | AS}
        {說明部分}
begin
         語句序列
         [exception 例外處理]
end [過程名]



  1. CREATE TABLE Student
  2.        (Sno CHAR(9) PRIMARY KEY,
  3.         Sname CHAR(20) NOT NULL, 
  4.         Ssex CHAR(4),
  5.         Sage SMALLINT,
  6.         Sdept CHAR(20)) tablespace gaospace;






例子:
建立一個新增學生的儲存過程。

  1. create or replace procedure addnewstudent(
  2. p_sno student.sno%type,
  3. p_sname student.sname%type,
  4. p_ssex student.ssex%type,
  5. p_sage student.sage%type,
  6. p_sdept student.sdept%type)
  7. As
  8. begin
  9. insert into student values(p_sno, p_sname, p_ssex, p_sage, p_sdept);
  10. commit;
  11. end addnewstudent;



呼叫:

  1. begin
  2.  addnewstudent('0209','趙利','男',21,'cs');
  3. end;




引數型別:

這裡肯定是傳入引數 IN: 

  1. create or replace procedure addnewstudent2(
  2. p_sno IN student.sno%type,
  3. p_sname IN student.sname%type,
  4. p_ssex IN student.ssex%type,
  5. p_sage IN student.sage%type,
  6. p_sdept IN student.sdept%type)
  7. As
  8. begin
  9. insert into student values(p_sno, p_sname, p_ssex, p_sage, p_sdept);
  10. commit;
  11. end addnewstudent2;


  12. begin
  13.  addnewstudent2('0210','趙五','男',21,'cs');
  14. end;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26435490/viewspace-1077848/,如需轉載,請註明出處,否則將追究法律責任。

相關文章