SQL求助: 在写SQL语句时,我想要调用其他表查询的结果拼接上一个字符串作为表名,但是执行语句时,

2024-12-01 18:47:12
推荐回答(1个)
回答1:

declare
v_tbl_nm varchar2(30);
v_sql varchar2(4000);
v_result varchar2(4000);
begin
select table_name into v_tbl_nm from USER_TABLES where TABLE_NAME = (SELECT * FROM(SELECT concat(demo,'HISTORY') FROM HISTORY order by recordtime)where rownum=1);
v_sql :='select LYO_3_DB5_DBD84 from ' || v_tbl_nm ;
execute immediate v_sql into v_result;
dbms_output.put_line(v_result);
end;