8 Replies Latest reply: Jul 28, 2013 7:37 AM by 4280d4a5-e01a-4515-a3fb-ce430d118bf8 RSS

    i meet a problem when create table in a for loop

    4280d4a5-e01a-4515-a3fb-ce430d118bf8

      procedure table_init(param1_ varchar2) creates a table named param1_

      create or replace

      procedure table_init(param1_ varchar2) authid current_user   as

      t_name varchar2(100):=param1_;

      begin

      execute immediate

      ' create table ' || t_name || '

      (

      日期 date not null,

      代码 varchar2(20) not null,

      最新 number,

      换手率 number,

      总额 number,

      今开 number,

      最高 number,

      最低 number,

      市盈率 varchar2(20),

      市销率 varchar2(20),

      委买价 number,

      委卖价 number,

      内盘 number,

      外盘 number,

      均价 number,

      委比 number,

      委差 number,

      成交笔数 number,

      成交方向 varchar2(20),

      市净率 number,

      总市值 number,

      流通市值 number

       

      ) '

      ;

      end table_init;

       

       

      it passed test by code bellow

       

      declare

      xx varchar2(40);

      begin

      xx:='nihao';

      table_init(xx);

      table_init('zhongguo');

      table_init('xiaopengyou');

      end;

       

      but when i use table_init() in the for loop bellow,  problem rises...

      declare

      cursor stock is select * from "股票";

      rec stock%rowtype;

      tmp varchar2(100);

      begin

      for rec in stock loop

      tmp:=rec."表名";

      dbms_output.put_line(tmp);

      table_init(tmp);

      end loop;

      end;

       

      why? how can i create mutiple  tables whose name are stored in another table?