简体   繁体   English

SQL 命令在动态 sql 查询 oracle 中没有正确结束?

[英]SQL command not properly ended in dynamic sql query oracle?

I get an error我收到一个错误

SQL command not properly ended SQL 命令未正确结束

Although the p_sql variable contains a valid SQL query that works without execute and loop.尽管p_sql变量包含一个有效的 SQL 查询,该查询无需执行和循环即可工作。 Maybe this is due to the limitations of execute immediate也许这是由于execute immediate的限制

declare

p_sql clob;

begin

​for naprav in (select naprav_name from naprav)

​ ​ ​loop​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​

​ ​ ​ ​ ​ ​ for pokaz in (select * from pokaz)

​ ​ ​ ​ ​ ​ ​loop

​ ​ ​ ​ ​ ​ ​ ​ ​for group_level in (select * from group_level)

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​loop

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ p_sql := '

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ insert into from_cost_lab_with_love

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ with cte as (

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ select

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ pokaz.i_id_pokaz || ' as i_id_pokaz,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ pokaz.pokaz_measure || ' as pokaz_measure,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ pokaz.pokaz_describe || ' as "Описание показателя",

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ naprav.naprav_name || ' as "Блок данных",

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ group_level.level_name || ' as level_name,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ group_level.tb_id || ' as tb_id,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ group_level.gosb_id || ' as gosb_id,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ group_level.org_id || ' as org_id,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ' ||​ pokaz.pokaz_formula || ' over(' || group_level.partition_column || ') as fact_amt,' --показатель

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ||​ pokaz.pokaz_formula || ' over(' || group_level.partition_column || ') as fc_amt_1,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ row_number() over(' || group_level.partition_column || ' order by BE) as rnk

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ 0 as plan_amt,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ TO_DATE(CONCAT(CONCAT(FINANSOVYJ_GOD,CONCAT(''0'',KVARTAL*3 - 3)),''01''), ''yyyymmdd'') as period_begin,​ --начало квартала

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ LAST_DAY(TO_DATE(CONCAT(CONCAT(FINANSOVYJ_GOD,CONCAT(''0'',KVARTAL*3)),''01''), ''yyyymmdd'')) as period_end, --конец квартала

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ LAST_DAY(TO_DATE(CONCAT(CONCAT(FINANSOVYJ_GOD,CONCAT(''0'',MESJATS)), ''01''), ''yyyymmdd'')) as rep_date, --дата измерений

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ TO_DATE(CURRENT_DATE, ''dd.mm.yy'') as load_date,

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ 0 as execution

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ from erp_trips

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ )

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ select *

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ from cte

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ where rnk=1;';

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ dbms_output.put_line(p_sql);

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​execute immediate p_sql;

​ ​ ​ ​ ​ ​ ​ ​end loop;

​ ​ ​ ​ ​end loop;

​ ​ ​end loop;

end;

The semicolon ( ; ) isn't part of the SQL syntax - it's a terminating character used by tools like SQL*Plus to signify the input is over and the SQL statement should be executed.分号 ( ; ) 不是 SQL 语法的一部分 - 它是 SQL*Plus 等工具用来表示输入结束并且应该执行 SQL 语句的终止字符。 When you execute an SQL statement directly (eg, with execute immediate ), you don't need it (read: it's wrong to have it).当您直接执行 SQL 语句时(例如,使用execute immediate ),您不需要它(阅读:拥有它是错误的)。 Remove it, and you should fine.删除它,你应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM