现有个公共模块:
往过程prc_aaa传入嵌套表参数,该嵌套表是个指标集合。
TYPE type_table IS TABLE OF varchar2(10);
v_varry_tabel := type_table('0001', '0002');在prc_aaa内,需要动态执行一句sql, 其中的一个动态条件是查表varrytable的数据项的指标需是传入嵌套表内指标:
V_sql_str     := 'insert into varrytableaaaa 
                             select t.nameid 
                               from varrytable t 
                              where t.code =:1 ';
  
    EXECUTE IMMEDIATE V_sql_str;=
    using v_str;问题一:怎么把此处的v_str及传入参数的嵌套表传入 :1 ?
问题二:传入的指标应该使用in操作符,请问动态SQL中,in怎么写?

解决方案 »

  1.   

    Create Table test As 
    Select '0001' code, 'AA' nameid From dual
    Union All 
    Select '0002', 'BB' From dual
    Union All 
    Select '0003', 'CC' From dual
    Union All 
    Select '0004', 'DD' From dual;Create Table test_1 As Select * From test Where 1 = 0;
    Declare
      Type Type_Table Is Table Of Varchar2(10);
      v_Varry_Tabel Type_Table := Type_Table('0001', '0002');
      v_Sql_Str Varchar2(4000);
    Begin
      For i In 1 .. v_Varry_Tabel.Count Loop
        v_Sql_Str := 'insert into test_1 
      select *
      from test t 
      where t.code =:1 ';
        Execute Immediate v_Sql_Str Using v_Varry_Tabel(i);
      End Loop;
      Commit;
    End;
    这样可以不??
      

  2.   

    在动态执行的时候,不希望使用FOR循环来执行,希望能一次性的把整个嵌套表的内容传入,
    我想的是也可以在传入前拼接成一个大的字串,'0001', '0002'这样。
    但是几次拼接都没有成功。
      

  3.   

    还是希望使用循环拼接,拼成大的字串,
    动态SQL中使用IN的方式传字串。
      

  4.   


    -------------定义类型
    CREATE OR REPLACE Type Type_Table Is Table Of Varchar2(10);
    ------------定义过程
    create or replace procedure ins_p (p_value Type_Table) is  
      
    Begin
      insert into test_1
        select *
          from test t
         where t.code in (select * from table(p_value));
         commit;
    end;
    -----------测试过程
    Declare  
      v_Varry_Tabel Type_Table := Type_Table('0001', '0002');
      v_Sql_Str     Varchar2(4000);
    Begin
    ins_p(v_Varry_Tabel);
    end;
    --------------