我一直坚持这个错误。你能否在下面的代码中说明错误是什么?这是在为变量输入的过程中编写的。感谢。
execute immediate 'Create or replace view '||p_viewname||' AS
select * from (
select NAME, CODETYPE, CODE
from HLIDEV_VIEWS.V_CONCEPT
WHERE HLIDEV_VIEWS.V_CONCEPT.CONCEPTTYPE = '''||p_concepttype||'''
)
pivot
(
max(code)
for codetype in ('||all_codetypes||')
)';
更新:以下是我看到的错误。
EXEC "HLIDEV_VIEWS"."FinalCreatePOAView" ('POA_CONCEPT_TYPE','PresentOnAdmission')
Error report -
ORA-00911: invalid character
ORA-06512: at "HLIDEV_VIEWS.FinalCreatePOAView", line 39
ORA-06512: at line 1
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
答案 0 :(得分:1)
使用execute immediate完全可以做到的。你只是在某处有语法错误,或者表格确实不存在。
尝试将您正在构建的字符串写入DBMS_OUTPUT.PUT_LINE,而不是将其发送到EXECUTE IMMEDIATE。然后,尝试在SQL * Plus中将该字符串作为命令运行。这应该突出错误。
FWIW,我的数据库中没有你的对象,但是我写了一个与你的相同格式的EXECUTE IMMEDIATE,它在Oracle 11g2中工作正常。
DECLARE
p_view_name VARCHAR2(61) := 'VXSMIMMCP.MATT_V';
p_region_code VARCHAR2(30) := 'R01';
p_all_port_codes VARCHAR2(400) := '''P01'',''P02'',''P03''';
BEGIN
EXECUTE IMMEDIATE
'Create or replace view '
|| p_view_name
|| ' AS select * from ( select REGION_CODE, account_number , port_code from APPS.XXCUS_ACCOUNTS WHERE APPS.XXCUS_ACCOUNTS.REGION_CODE = '''
|| p_region_code
|| ''' ) pivot ( min(account_number) for port_code in ('
|| p_all_port_codes
|| ') )' ;
END;
答案 1 :(得分:0)
感谢@MatthewMcPeak和@MahendarMahi的意见。突然,我的代码开始正常工作,它以我想要的方式创建了视图。我唯一做的是,正如@MahendarMahi建议的那样,我移除了枢轴并运行它以查看相同的错误,然后更换了枢轴,错误消失了。我确信代码没有变化,但无论如何它现在都很奇怪。再次感谢你的时间。