PL / SQL无法使用简单的SQL?

时间:2015-08-26 11:45:25

标签: sql oracle plsql

oracle中的新手。我想要执行一个简单的程序,

DECLARE 
  PC1 NUMBER;
  POC VARCHAR2(32767);
  P_YEAR NUMBER;
  P_RESULT_SET SYS_REFCURSOR;
  P_RESULT NUMBER;

BEGIN 
  PC1 := 608077;
  POC := '00000015517515';
  P_YEAR := 2016;
  P_RESULT_SET := NULL;
  P_RESULT := NULL;

  Sch.ABC(PC1, POC, P_YEAR ,:P_RESULT_SET, P_RESULT );

  COMMIT; 
END;

错误,

Error report -
ORA-06550: line 15, column 3:
PLS-00306: wrong number or types of arguments in call to 'GET_EXPIRED_LIC_MV'
ORA-06550: line 15, column 3:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

程序正文是,

create or replace PROCEDURE     ABC(POC IN NUMBER,
                                                   PC   IN VARCHAR2,
                                                   P_YEAR         IN NUMBER,
                                                   P_RESULT_SET   OUT SYS_REFCURSOR,
                                                   P_RESULT       OUT NUMBER)AS
BEGIN

OPEN  P_RESULT_SET FOR  SELECT  XX.CCC,XX.CODE,
                        SUM(XX)JAN, 
                        SUM(XX)FEB,
                        SUM(XX)MAR,
                        SUM(XX)ARP,
                        SUM(XX)MAY,
                        SUM(XX)JUN,
                        SUM(XX)JUL,
                        SUM(XXX)AUG,
                        SUMXXX)SEP,
                        SUM(XXX)OCT,
                        SUM(XX)BOV,
                        SUM(XX)DEC


  FROM XXXXXX                                                                                                   
END;

我还想查看参数值。

1 个答案:

答案 0 :(得分:2)

如果您的光标将返回任何表格行,那么您的循环将如下所示。

    DECLARE 
      PC1 NUMBER;
      POC VARCHAR2(32767);
      P_YEAR NUMBER;
      P_RESULT_SET SYS_REFCURSOR;
      P_RESULT NUMBER;
    P_sref table_name%rowtype;

    BEGIN 
      PC1 := 608077;
      POC := '00000015517515';
      P_YEAR := 2016;
      P_RESULT_SET := NULL;
      P_RESULT := NULL;
    Sch.ABC(PC1, POC, P_YEAR ,P_RESULT_SET, P_RESULT );
    loop 
    fetch P_RESULT_SET into P_sref ;
    exit when P_RESULT_SET%notfound;
    dbms_output.put_line(P_sref .col1||' '||P_sref.col2 etc)
    end loop
      COMMIT; 
    END;

或者如果它返回某些列,则

     DECLARE 
      PC1 NUMBER;
      POC VARCHAR2(32767);
      P_YEAR NUMBER;
      P_RESULT_SET SYS_REFCURSOR;
      P_RESULT NUMBER;
    P_sref1 table_name1.column_name%rowtype;
    P_sref2 table_name2.column_name%rowtype;
--declare the variable names with the same data types of variable whic is returned by a cursor
     BEGIN 
      PC1 := 608077;
      POC := '00000015517515';
      P_YEAR := 2016;
      P_RESULT_SET := NULL;
      P_RESULT := NULL;
    Sch.ABC(PC1, POC, P_YEAR ,P_RESULT_SET, P_RESULT );
    loop 
    fetch P_RESULT_SET into P_sref1,P_sref2 ;
    exit when P_RESULT_SET%notfound;
    dbms_output.put_line(P_sref1||' '||P_sref2 etc)
    end loop
      COMMIT; 
    END;