Home >Database >Mysql Tutorial >Oracle 动态查询EXECUTE IMMEDIATE select into使用方法
create or replace procedure TEST_TABLE is l_table_name varchar2(50); query_stat varchar2(100); l_zyq t_djjcxx.zyq%type; l_jh varchar2(20); l_djjcxx t_djjcxx%rowtype; begin l_jh :='7874'; select name into l_table_name from TESTA; DBMS_OUT
create or replace procedure TEST_TABLE is
l_table_name varchar2(50);
query_stat varchar2(100);
l_zyq t_djjcxx.zyq%type;
l_jh varchar2(20);
l_djjcxx t_djjcxx%rowtype;
begin
l_jh :='7874';
select name into l_table_name from TESTA;
DBMS_OUTPUT.put_line(l_table_name);
query_stat := 'select * from '|| l_table_name||' where jh=:l_jh';
EXECUTE IMMEDIATE query_stat into l_djjcxx using l_jh;
DBMS_OUTPUT.put_line(l_djjcxx.zyq);
end TEST_TABLE;
query_stat里面如果写成 select zyq into l_zyq from '|| l_table_name||' where jh=:l_jh' 会报错。标红的都是要注意的地方