我正在使用一些PL / SQL调用数据库链接,并且逗号和管道有问题。我尝试了多种组合,但一直收到语法错误。
我在各处尝试了多个逗号,但无济于事:-(
declare
v_sql varchar2(4000);
s_sql varchar2(4000);
l_dblink varchar2(100) := 'DB1';
begin
for c in (select * from my_table)
loop
if
c.blue_table is not null
then v_sql :=
'select count(*) from' ||c.schema||'.'||c.table||'@'||'l_dblink;
execute immediate v_sql into s_sql;
dbms_output.put_line(s_sql);
end if;
end loop;
end;
/
我希望它在表“ my_table”中循环。放在一起'SCHEMA.TABLE_NAME'并给我一个行数。
答案 0 :(得分:1)
您有一些小语法问题
declare
v_sql varchar2(4000);
s_sql pls_integer; -- better to use a numeric type variable for returning result of "count"
l_dblink varchar2(100) := 'DB1';
begin
for c in (select * from my_table) loop
if c.blue_table is not null then
v_sql := 'select count(*) from ' || c.schema || '.' || c.table || '@' ||l_dblink;
--^ "space needed" [^ quote is removed ]
execute immediate v_sql into s_sql;
dbms_output.put_line(s_sql);
end if;
end loop;
end;
答案 1 :(得分:0)
我对此进行了一些更改,意识到它仍然无法正常工作,在这里这些人的帮助下,我进行了整理。谢谢。
declare
v_sql varchar2(4000);
s_sql varchar2(4000);
l_dblink varchar2(100) := 'DB1';
begin
for c in (select * from my_table)
loop
if
c.blue_table is not null
then
execute immediate' select count(*) from '||c.schema||'.'||c.table|| '@' ||l_dblink into s_sql;
dbms_output.put_line(s_sql);
end if;
end loop;
end;
/