Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

sql - Array in IN() clause oracle PLSQL

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. Let me show how i am crating plcListchar string array in JAVA.

 String array[] = {"o", "l"}; 
 ArrayDescriptor des = ArrayDescriptor.createDescriptor("CHAR_ARRAY", con);
 ARRAY array_to_pass = new ARRAY(des,con,array);            
 callStmtProductSearch.setArray(4, array_to_pass);

for crating CHAR_ARRAY,

create or replace type CHAR_ARRAY as table of varchar2;

i want use plcListchar in IN clause. the following is my Stored Procedure.

CREATE OR REPLACE PROCEDURE product_search(
            status IN varchar2, 
            plcList IN varchar2,
            i_culture_id IN number,
            plcListchar IN CHAR_ARRAY,
            status_name OUT  varchar2, 
            culture_code  OUT varchar2)
AS  
    CURSOR search_cursor IS
    SELECT p.status_name, p.culture_code
                FROM PRISM_ITEM_cultures@prism p
                WHERE p.publishable_flag=1 
                AND p.isroll =0 
                AND status = '-1'
                AND p.plc_status IN ( ??);
 BEGIN
           OPEN search_cursor;
           FETCH search_cursor INTO status_name, culture_code ;
           CLOSE search_cursor;
 END;

Could you please suggest me how to use, if you like to suggest any other logic, it is great.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...