我正在尝试为物化视图脚本创建解释计划:
EXECUTE DBMS_ADVISOR.TUNE_MVIEW('TASK_V_APPLEBANANA', '
CREATE MATERIALIZED VIEW V_APPLEBANANA
BUILD IMMEDIATE REFRESH FAST START WITH (sysdate) NEXT (sysdate+1*60/(60*60*24)) WITH rowid AS
SELECT A.f, B.f
FROM Apple a join Banana b
on a.id = b.fid
GROUP BY A.f, B.f
');
然而,SQL开发人员给了我:
Error report:
ORA-06550: line 1, column 52:
PLS-00103: Encountered the symbol "; END;" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternat
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:...
我不确定"; END;"
隐含的位置以及如何克服此错误。物化视图脚本工作正常,但整个执行过程失败。
答案 0 :(得分:2)
除非您明确添加延续字符,否则SQL*Plus execute
command都必须在一行上。当你这样做时(假设你在它自己的行上有一个引号;如果你在第一行有三个你得到ORA-01756):
EXECUTE DBMS_ADVISOR.TUNE_MVIEW('TASK_V_APPLEBANANA',
'
CREATE MATERIALIZED VIEW V_APPLEBANANA
BUILD IMMEDIATE REFRESH FAST START WITH (sysdate) NEXT (sysdate+1*60/(60*60*24)) WITH rowid AS
SELECT A.f, B.f
FROM Apple a join Banana b
on a.id = b.fid
GROUP BY A.f, B.f
');
仅将第一行转换为匿名块,如下所示:
BEGIN DBMS_ADVISOR.TUNE_MVIEW('TASK_V_APPLEBANANA',; END;
...这解释了您看到的错误消息。
你可以尝试将整个事情强行放在一条线上;或使用连续字符(默认情况下超支):
EXECUTE DBMS_ADVISOR.TUNE_MVIEW('TASK_V_APPLEBANANA',-
'-
CREATE MATERIALIZED VIEW V_APPLEBANANA-
BUILD IMMEDIATE REFRESH FAST START WITH (sysdate) NEXT (sysdate+1*60/(60*60*24)) WITH rowid AS -
SELECT A.f, B.f-
FROM Apple a join Banana b-
on a.id = b.fid -
GROUP BY A.f, B.f-
');
或者用一个更简单的例子:
SQL > exec dbms_output.put_line('-
> hel-
> lo-
> ');
可以工作并获得输出:
hel lo
请注意已添加的额外空间;你有足够的空白,因为这对你正在做的事情无关紧要,但对于其他分裂字符串来说可能是一个问题。
但是,跳过SQL * Plus速记并写一个完整的匿名块可能要简单得多:
BEGIN
DBMS_ADVISOR.TUNE_MVIEW('TASK_V_APPLEBANANA',
'
CREATE MATERIALIZED VIEW V_APPLEBANANA
BUILD IMMEDIATE REFRESH FAST
START WITH (sysdate) NEXT (sysdate+1*60/(60*60*24))
WITH rowid AS
SELECT A.f, B.f
FROM Apple a join Banana b
on a.id = b.fid
GROUP BY A.f, B.f
');
END;
/
...特别是如果你从其他地方删除了大部分代码而不是真的想要操纵它只是为了满足execute
的限制。