我遇到了以下错误:
ORA-00923:未在预期位置找到FROM关键字
在尝试构建plsql脚本时:
declare
yearmonth varchar2(20) := &yearmonth ;
begin
execute IMMEDIATE 'CREATE TABLE tbl_board_new_method AS
with a as (
select u.*,case when ooo.terminal_number is not null then "BOX" else "NOBOX" end ISBOX from (
select q.*,
CASE WHEN substr(i.min_trn_date, 0, 8) IS NOT NULL AND substr(i.min_trn_date, 0, 8) < coalesce( substr(i.install_date, 0, 8) , q.install_date ) THEN
coalesce( substr(i.min_trn_date, 0, 8) , q.install_date, substr(i.install_date, 0, 8)) ELSE
coalesce(q.install_date,
substr(i.install_date, 0, 8),
substr(i.min_trn_date, 0, 8)) END f_install_date,
nvl(q.disable_date, substr(i.disable_date, 0, 8)) f_disable_date,
q.pos_model pos_model1,
q.pos_brand pos_brand1,
q.pos_brand_model pos_brand_model1 ,
CASE
WHEN UPPER(q.pos_model) IN
(:COMBO,
"DIALUP",
"LAN",
"BRANCH") THEN
"POS"
ELSE
CASE
WHEN UPPER(q.pos_model) IN
("PCPOS", "TYPICAL") THEN
"PCPOS"
ELSE
CASE
WHEN UPPER(q.pos_model) IN
("MPOS(BT/INTERNET)",
"MPOS") THEN
"MPOS"
ELSE
CASE
WHEN UPPER(q.pos_model) =
"GPRS" THEN
"GPRS"
ELSE
CASE
WHEN UPPER(q.pos_model) =
"IPG" THEN
"IPG"
ELSE
"POS"
END
END
END
END
from trg.tbl_merchant_info q
left join trg.mvw_terminal_indicators i on (q.terminal_number = i.terminal_number)
where coalesce(q.install_date,
substr(i.install_date, 0, 8),
substr(i.min_trn_date, 0, 8)) is not null
and
CASE WHEN substr(i.min_trn_date, 0, 8) IS NOT NULL AND substr(i.min_trn_date, 0, 8) < substr(i.install_date, 0, 8) THEN
coalesce( substr(i.min_trn_date, 0, 8) , q.install_date, substr(i.install_date, 0, 8)) ELSE
coalesce(q.install_date,
substr(i.install_date, 0, 8),
substr(i.min_trn_date, 0, 8)) END <= '||yearmonth||'||30
and (nvl(q.disable_date, substr(i.disable_date, 0, 8)) is null OR nvl(q.disable_date, substr(i.disable_date, 0, 8)) >='||yearmonth||'||01
)
and (trim(q.pos_model) is null or
not
(upper(q.pos_model) like "%MPOS%" ))
--- union
UNION
select q.*,
CASE WHEN substr(i.min_trn_date, 0, 8) IS NOT NULL AND substr(i.min_trn_date, 0, 8) < coalesce( substr(i.install_date, 0, 8) , q.install_date ) THEN
coalesce( substr(i.min_trn_date, 0, 8) , q.install_date, substr(i.install_date, 0, 8)) ELSE
coalesce(q.install_date,
substr(i.install_date, 0, 8),
substr(i.min_trn_date, 0, 8)) END f_install_date,
nvl(q.disable_date, substr(i.disable_date, 0, 8)) f_disable_date,
q.pos_model pos_model1,
q.pos_brand pos_brand1,
q.pos_brand_model pos_brand_model1 ,
CASE
WHEN UPPER(q.pos_model) IN
("COMBO",
"POS",
"DIALUP",
"LAN",
"BRANCH") THEN
"POS"
ELSE
CASE
WHEN UPPER(q.pos_model) IN
("PCPOS", "TYPICAL") THEN
"PCPOS"
ELSE
CASE
WHEN UPPER(q.pos_model) IN
("MPOS(BT/INTERNET)",
"MPOS") THEN
"MPOS"
ELSE
CASE
WHEN UPPER(q.pos_model) =
"GPRS" THEN
"GPRS"
ELSE
CASE
WHEN UPPER(q.pos_model) =
"IPG" THEN
"IPG"
ELSE
"POS"
END
END
END
END
END FINAL_POS_MODEL
from trg.tbl_merchant_info q
left join trg.mvw_terminal_indicators i
on (q.terminal_number = i.terminal_number)
WHERE q.terminal_number IN (SELECT terminalno FROM trg.fct_total_aggrigate_daily d WHERE substr(trn_date,0,6) = substr('||yearmonth||',0,6) )
) u left join (select * from trg.mvw_terminal_indicators ooo
where ooo.box_install is not null and (box_uninstall is null or substr(ooo.box_uninstall,0,8)>= '||yearmonth||'||01) ) ooo on (ooo.terminal_number = u.terminal_number )
a.terminal_number = t111.terminalno (+) and a.terminal_number = tt211.terminalno (+) and
a.terminal_number = ttt311.terminalno (+) and a.terminal_number = tttt411.terminalno (+) and a.terminal_number = ttttt511.terminalno (+)
)
--, pre AS (
select terminalid,
case when m.scale_install is not null then 1 else 0 end scale_install ,
yearmonth
from p left join trg.mvw_terminal_indicators m on (p.terminal_number = m.terminal_number)';
end ;
2条答案
按热度按时间bwitn5fc1#
问题的一部分是sql中的双引号字符串被认为是标识符。这里是一个小测试。
你的查询太大了,我无法分析,但是大多数问题可能是双引号。(''''--〉其中四个用单引号表示),然后,在编写sql命令时该变量用于将单引号放入命令中,其中有varchar类型的值。否则Oracle尝试查找标识符。关于...
添加:除了双引号之外,代码还有一些其他问题。我从你的问题中提取了它,并将其结构化以使其更具可读性。下面的代码中注解了问题,有些代码缺失,有些错误,有些我无法理解。下面是结构化版本,问题在[26,45,107,116,124,125,126,127,127,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129125]和在主SELECT [行128 - 138]你会知道的东西,我没有抓住,也许使它的工作...
仍然存在双引号问题,但可以使用任何文本编辑器解决。声明变量以保存SQL代码字符串,声明sq变量并将'''作为其值,并将["]替换为['||平方||']。然后打印代码(DBMS_OUTPUT),复制它,检查它并运行它。可能会有更多的更正要做,但你会得到错误消息,什么地方有问题。
pb3s4cty2#
你可以使用带引号的字符串,像这样:
Oracle documentation here