2013-01-22 76 views
1
CREATE TYPE PROD_RPT_DTL IS object 
(
    DIVISION_ID NUMBER(6), 
    DIVISION_NM VARCHAR2(100), 
    DEPT_ID NUMBER(10), 
    DEPT_NM VARCHAR2(100), 
    WORK_FLOOR_ID NUMBER(10), 
    ........................... 
)/ 
CREATE TYPE PROD_RPT_DTL_TABLE is TABLE OF PROD_RPT_DTL 

- >過程返回PROD_RPT_DTL_TABLE類型是oracle的動態sql

PROCEDURE sp_GetAllInQtyDetailForCutting(V_PROD_RPT_DTL out PROD_RPT_DTL_TABLE); 

- >現在我的程序正在執行像下面的代碼東西

DECLARE 
    v_PROD_RPT_DTL PROD_RPT_DTL_TABLE:=PROD_RPT_DTL_TABLE(); 
    vv_PROD_RPT_DTL PROD_RPT_DTL_TABLE:=PROD_RPT_DTL_TABLE(); 
    WHEREClause varchar2(500); 
    QUERY VARCHAR2(2000); 
    CUR SYS_REFCURSOR; 
BEGIN 
    --calling procedure to return valued in v_PROD_RPT_DTL 
    sp_GetAllInQtyDetailForCutting(v_PROD_RPT_DTL); 
    WHEREClause := ' Where division_id=1'; ; 
    --> now v_PROD_RPT_DTL is a nested table and i have to apply some dynamic filter on it. 
    QUERY := 'SELECT * bulk collect INTO vv_PROD_RPT_DTL FROM Table(cast(v_PROD_RPT_DTL AS PROD_RPT_DTL_TABLE))' || WHEREClause ; 
    open cur for QUERY; 
    ................................................. 
END ; 

當我運行整個事情我得到錯誤

ORA-00904: "V_PROD_RPT_DTL": invalid identifier 
ORA-06512: at "SCHEMA.PKG_PROD_REP_MDL", line 52 
ORA-06512: at line 4 ! 

第52行是QUERY:= ......

請問我的PL/SQL有什麼問題請指教。

回答

1

做這樣的事情:

SQL> create procedure sp_getallinqtydetailforcutting(v_prod_rpt_dtl out prod_rpt_dtl_table) 
    2 is 
    3 begin 
    4 V_PROD_RPT_DTL := PROD_RPT_DTL_TABLE(PROD_RPT_DTL(1, 'a', 1, 'a', 1), 
    5           PROD_RPT_DTL(2, 'a', 1, 'a', 1), 
    6           PROD_RPT_DTL(1, 'b', 1, 'a', 1)); 
    7 end; 
    8/

Procedure created. 

SQL> declare 
    2  v_prod_rpt_dtl prod_rpt_dtl_table; 
    3  whereclause varchar2(500); 
    4  CUR SYS_REFCURSOR; 
    5 begin 
    6  --calling procedure to return valued in v_PROD_RPT_DTL 
    7  sp_GetAllInQtyDetailForCutting(v_PROD_RPT_DTL); 
    8  WHEREClause := ' Where division_id=1'; 
    9  open CUR for 'SELECT PROD_RPT_DTL(DIVISION_ID , DIVISION_NM, ' 
10     || 'DEPT_ID, DEPT_NM, WORK_FLOOR_ID) FROM Table(:b1)' 
11     || WHEREClause using v_PROD_RPT_DTL; 
12  fetch cur bulk collect into v_PROD_RPT_DTL; 
13  close cur; 
14 
15  for idx in 1..v_PROD_RPT_DTL.count 
16  loop 
17  dbms_output.put_line(v_PROD_RPT_DTL(idx).DIVISION_ID 
18        || ',' || v_PROD_RPT_DTL(idx).DIVISION_NM); 
19  end loop; 
20 end; 
21/
1,a 
1,b 

PL/SQL procedure successfully completed.