0

我正在用 pl/sql 编写程序。当我运行程序时出现错误。这里我附上了程序。

code

PROCEDURE get_CDR_rs_phone (CDR_recordset OUT SYS_REFCURSOR)AS 
BEGIN 
  OPEN CDR_recordset FOR
   SELECT  zkv.CISCOCUIC_TBL.FLD_callingPartyNumber FROM  zkv.CISCOCUIC_TBL; 

END get_CDR_rs_phone;
/

getting error when i run this proc
4

1 回答 1

1

将您的程序创建为

CREATE OR REPLACE PROCEDURE get_cdr_rs_phone (
    cdr_recordset    OUT sys_refcursor
)
AS
BEGIN
    OPEN cdr_recordset FOR
        SELECT  zkv.ciscocuic_tbl.fld_callingpartynumber
          FROM  zkv.ciscocuic_tbl;
END get_cdr_rs_phone;
/

并执行你的程序

variable r refcursor;

DECLARE

BEGIN

  get_cdr_rs_phone (:r);  
END;
/

print r

更新 1

如果您的过程仅执行选择,您可以使用返回 sys_refcursor 的函数来执行此操作,并且该函数可以从 sql 语句中执行。

创建函数为

CREATE OR REPLACE FUNCTION get_cdr_rs_phone_func
    RETURN sys_refcursor
AS
    out_cursor   sys_refcursor;
BEGIN
    OPEN out_cursor FOR
          SELECT    zkv.ciscocuic_tbl.fld_callingpartynumber
              FROM  zkv.ciscocuic_tbl;
    END get_cdr_rs_phone;

    RETURN out_cursor;
EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
        --raise error

    WHEN OTHERS
    THEN
        --raise error

END get_cdr_rs_phone_func;
/

并将此函数称为

select get_cdr_rs_phone_func from dual;
于 2012-11-19T11:09:00.890 回答