是oracle里的存储过程
v_str_his_table_name varchar2(100);--是一个变量
v_str_his_table_name := 'aaa'
select * from v_str_his_table_name

解决方案 »

  1.   

    使用 动态sql语句就可,网上有很多的例子
      

  2.   

    我来举个例子吧SQL> select * from t;        F1         F2
    ---------- ----------
             1          6
             2          7
             3          8
             4          9
             5         10
             6         11已选择6行。SQL> create or replace procedure show_t
      2  as
      3  v_str_his_table_name varchar2(100):='T';
      4  str                  varchar2(100);
      5  type   t_cursor is ref cursor;
      6  cursor1 t_cursor;
      7  REC    t%rowtype;
      8  sqlstr1 varchar2(600);
      9  begin
     10  sqlstr1:='select * from '||v_str_his_table_name;
     11  open cursor1 for sqlstr1;
     12  loop
     13  fetch cursor1 into rec;
     14  exit when cursor1%notfound;
     15  str:=lpad(rec.f1,8,' ')||lpad(rec.f2,8,' ');
     16  dbms_output.put_line(str);
     17  end loop;
     18  close cursor1;
     19  end;
     20  /过程已创建。SQL> set serveroutput on size 1000000
    SQL> call show_t();
    1       6
    2       7
    3       8
    4       9
    5      10
    6      11调用完成。
      

  3.   

    create or replace package types as 
    type cursorType is ref cursor; 
    end; create or replace procedure getemps(v_str_his_table_name varchar2, p_cursor in out types.cursorType )
    as
    str_sql varchar2(500); 
    begin
      str_sql := 'select * from '||v_str_his_table_name ;
      open productsinfo for str_sql;
    end;