Get resultset from oracle stored procedure

前端 未结 7 2321
生来不讨喜
生来不讨喜 2020-11-27 13:38

I\'m working on converting a stored procedure from SQL server to Oracle. This stored procedure provides a direct resultset. I mean that if you call the stored procedure in

7条回答
  •  一整个雨季
    2020-11-27 14:23

    Hi I know this was asked a while ago but I've just figured this out and it might help someone else. Not sure if this is exactly what you're looking for but this is how I call a stored proc and view the output using SQL Developer.
    In SQL Developer when viewing the proc, right click and choose 'Run' or select Ctrl+F11 to bring up the Run PL/SQL window. This creates a template with the input and output params which you need to modify. My proc returns a sys_refcursor. The tricky part for me was declaring a row type that is exactly equivalent to the select stmt / sys_refcursor being returned by the proc:

    DECLARE
      P_CAE_SEC_ID_N NUMBER;
      P_FM_SEC_CODE_C VARCHAR2(200);
      P_PAGE_INDEX NUMBER;
      P_PAGE_SIZE NUMBER;
      v_Return sys_refcursor;
      type t_row is record (CAE_SEC_ID NUMBER,FM_SEC_CODE VARCHAR2(7),rownum number, v_total_count number);
      v_rec t_row;
    
    BEGIN
      P_CAE_SEC_ID_N := NULL;
      P_FM_SEC_CODE_C := NULL;
      P_PAGE_INDEX := 0;
      P_PAGE_SIZE := 25;
    
      CAE_FOF_SECURITY_PKG.GET_LIST_FOF_SECURITY(
        P_CAE_SEC_ID_N => P_CAE_SEC_ID_N,
        P_FM_SEC_CODE_C => P_FM_SEC_CODE_C,
        P_PAGE_INDEX => P_PAGE_INDEX,
        P_PAGE_SIZE => P_PAGE_SIZE,
        P_FOF_SEC_REFCUR => v_Return
      );
      -- Modify the code to output the variable
      -- DBMS_OUTPUT.PUT_LINE('P_FOF_SEC_REFCUR = ');
      loop
        fetch v_Return into v_rec;
        exit when v_Return%notfound;
        DBMS_OUTPUT.PUT_LINE('sec_id = ' || v_rec.CAE_SEC_ID || 'sec code = ' ||v_rec.FM_SEC_CODE);
      end loop;
    
    END;
    

提交回复
热议问题