Array in IN() clause oracle PLSQL

后端 未结 1 961
臣服心动
臣服心动 2020-11-30 10:00

I am passing String array(plcListchar) to Stored Procedure, i would like to use this String array in IN() clause.

i can not use plcListchar directly in IN() clause.

相关标签:
1条回答
  • 2020-11-30 10:31

    Assuming that your collection is defined in SQL, not just in PL/SQL, you can use the TABLE operator (the definition you posted isn't syntactically valid-- you'd need to specify a length for the VARCHAR2)

    AND p.plc_status IN (SELECT column_value
                           FROM TABLE( plcListchar ))
    

    Since I don't have your tables, an example using the SCOTT schema

    SQL> create type ename_tbl is table of varchar2(30);
      2  /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    l_enames ename_tbl := ename_tbl( 'KING', 'SMITH' );
      3  begin
      4    for i in (select *
      5                from emp
      6               where ename in (select column_value
      7                                 from table( l_enames )))
      8    loop
      9      dbms_output.put_line( 'ENAME = ' || i.ename );
     10    end loop;
     11* end;
    SQL> /
    ENAME = KING
    ENAME = SMITH
    
    PL/SQL procedure successfully completed.
    
    0 讨论(0)
提交回复
热议问题