Oracle資料庫的遊標Cursor和預存程序 PL/SQL

來源:互聯網
上載者:User

Oracle資料庫的遊標和預存程序

spool abc.log                  --開始記錄日誌

create or replace procedure db.PROC_FIRST(FLAG OUT INTERGER,
     T_DATE IN VARCHAR2)

AS

  varno varchar2(20);
  varprice varchar2(20);

CURSOR mycur(vartype number) is
  select emp_no,emp_zc from cus_emp_basic
  where com_no = vartype;
 
BEGIN
  if NOT mycur%ISOPEN then
  open mycur(043925);
  end if;
  FETCH mycur INTO varno,varprice;
  WHILE mycur%FOUND
  LOOP

      dbms_output.put_line(varno||','||varprice);
      if mycur%rowcount=2 then
        EXIT;
     end if;
     fetch mycur into varno,varprice;
  END LOOP;
  CLOSE mycur;

 

  EXCEPTION   WHEN OTHERS THEN
ROLLBACK;

  end;

spool off

  記錄並不儲存在資料庫中,它與變數一樣,儲存在記憶體空間中,在使用記錄時候,要首先定義記錄結構,然後聲明記錄變數。可以把PL/SQL記錄看作是一個使用者自訂的資料類型。

EXECUTE IMMEDIATE sqlstr;

它解析並馬上執行動態SQL語句或非運行時建立的PL/SQL塊.動態建立和執行SQL語句效能超前


PL/SQL的系統變數及CURSOR:

遊標屬性:
%ISOPEN
%FOUND
%NOTFOUND
%ROWCOUNT

異常:

SQLCODE() 錯誤號碼
SQLERRM() 錯誤資訊
NO_DATA_FOUND

相關文章

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.