你把它放在sql window里边,是可以执行出来的,不是无效sql语句。另外dual是系统虚拟的表,select * from dual查询没有意义,最好是这样:select 1 as field1 from dual;
这些我做过测试了,不管放什么测试也是如此,就是不得行。就是要提示无效sql语句
如果动态sql是一个查询语句,那么需要 into declare text dual.dummy%type; begin execute immediate 'select * from dual' into text; dbms_output.put_line(text); end; /
execute immediate后面可以执行DDL和DML语句,执行DDL语句的时候,直接执行就可以; 执行DML语句的时候,要加上INTO语法: DECLARE resu NUMBER(2) := 0; BEGIN execute immediate 'select 1 from dual' INTO resu ; dbms_output.put_line(resu); end;
declare strSql varchar2(2000); begin strSql:='select t1.channel_name,('; strSql:=strSql||'select count(*) from cms_channel t where t.channel_id like ''substr(t1.channel_id,0,1)%'''; strSql:=strSql||')num from cms_channel t1 where t1.channel_level = 1'; execute immediate strSql; end; 再帮我看一下这条数据那里有问题,看不到执行结果.java.sqlException 报无效索引列
begin execute immediate 'select * from dual' ; end;
declare strSql varchar2(2000); begin strSql:='select t1.channel_name,('; strSql:=strSql||'select count(*) from cms_channel t where t.channel_id like ''substr(t1.channel_id,0,1)%'''; strSql:=strSql||')num from cms_channel t1 where t1.channel_level = 1'; execute immediate strSql; end;红色t1.channel_id ,表cms_channel中多行数据channel_id 的值不止一个吧,跑当行数据,右值不固定,1对N
declare
text dual.dummy%type;
begin
execute immediate 'select * from dual' into text;
dbms_output.put_line(text);
end;
/
执行DML语句的时候,要加上INTO语法:
DECLARE
resu NUMBER(2) := 0;
BEGIN
execute immediate 'select 1 from dual' INTO resu ;
dbms_output.put_line(resu);
end;
begin
strSql:='select t1.channel_name,(';
strSql:=strSql||'select count(*) from cms_channel t where t.channel_id like ''substr(t1.channel_id,0,1)%''';
strSql:=strSql||')num from cms_channel t1 where t1.channel_level = 1';
execute immediate strSql;
end;
再帮我看一下这条数据那里有问题,看不到执行结果.java.sqlException 报无效索引列
execute immediate 'select * from dual' ;
end;
begin
strSql:='select t1.channel_name,(';
strSql:=strSql||'select count(*) from cms_channel t where t.channel_id like ''substr(t1.channel_id,0,1)%''';
strSql:=strSql||')num from cms_channel t1 where t1.channel_level = 1';
execute immediate strSql;
end;红色t1.channel_id ,表cms_channel中多行数据channel_id 的值不止一个吧,跑当行数据,右值不固定,1对N