1. 程式人生 > >oracle儲存過程筆記

oracle儲存過程筆記

儲存過程是oracle資料庫中的過程化程式語言(progress language),可以用來編寫包含sql語句的程式。

塊結構:

儲存過程可劃分為稱為塊的結構,一般包含如下結構:

[DECLARE  
    declaration_statements
]
BEGIN
    executable_statements
    [EXCEPTION  
        WHEN condition_statement THEN
        exception_handling_statements
    ]   
END 

例如列印student表中資訊:

declare
  id     student.id%type
;
name student.NAME%type; course student.COURSE%type; score student.SCORE%type; class student.CLASS%type; cursor test_cursor is select * from STUDENT; begin open test_cursor; loop fetch test_cursor into id, name, course, score, class; exit when test_cursor%NOTFOUND; DBMS_OUTPUT.PUT_LINE( 'name:'
|| name || ' ,course:' || course || ' ,score:' || score || ' ,class:' || class ); end loop; exception when false then DBMS_OUTPUT.PUT_LINE( '這裡有異常' ); END ;