SQL> declare
v_b number;
v_a varchar2(30);
begin
v_b := 999;
select a into v_a from t_8 where b=v_b;
dbms_output.put_line('value of column a is:'||v_a);
end;
/ 2 3 4 5 6 7 8 9
value of column a is:ddd
PL/SQL procedure successfully completed.
对象名称不能使用变量
会报错
可以使用字符串连接的方式
v_table_name := ‘t_888’;
v_sql := 'create table '||v_table_name;
SQL> declare
v_b number;
v_a varchar2(30);
v_table_name varchar2(30) :='t_8';
begin
v_b := 999;
select a into v_a from v_table_name where b=v_b;
dbms_output.put_line('value of column a is:'||v_a);
end;
/
2 3 4 5 6 7 8 9 10 select a into v_a from v_table_name where b=v_b;
*
ERROR at line 7:
ORA-06550: line 7, column 25:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 7, column 2:
PL/SQL: SQL Statement ignored