Home >Database >Mysql Tutorial >Oracle 动态查询EXECUTE IMMEDIATE select into使用方法

Oracle 动态查询EXECUTE IMMEDIATE select into使用方法

WBOY
WBOYOriginal
2016-06-07 14:53:572419browse

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' 会报错。标红的都是要注意的地方

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn