简体   繁体   English

在Oracle查询中出现“ FROM”错误

[英]getting 'FROM' error in oracle query

I'm getting this error on the below query. 我在以下查询中收到此错误。 The query is to modify a constraint 查询是修改约束

SELECT 'EXEC DROP_CONSTRAINTS('RTK_TYUVOICE_SYSTEM','IOA_WRTYOICE');' FROM DUAL
                                                   *

ERROR at line 1: 第1行发生错误:

ORA-00923: FROM keyword not found where expected

Please advise on how to overcome this when I execute the above query from sql/nolog 当我从sql / nolog执行上述查询时,请提出如何克服此问题的建议

Either double quotes in the string 字符串中的双引号

SELECT 'EXEC DROP_CONSTRAINTS(''RTK_TYUVOICE_SYSTEM'',''IOA_WRTYOICE'');' as txt FROM DUAL;

TXT                                                        
------------------------------------------------------------
EXEC DROP_CONSTRAINTS('RTK_TYUVOICE_SYSTEM','IOA_WRTYOICE'); 

or use the (from 10g) quoted string 或使用(从10g起)带引号的字符串

SELECT q'[EXEC DROP_CONSTRAINTS('RTK_TYUVOICE_SYSTEM','IOA_WRTYOICE');]' as txt FROM DUAL;

TXT                                                        
------------------------------------------------------------
EXEC DROP_CONSTRAINTS('RTK_TYUVOICE_SYSTEM','IOA_WRTYOICE');

You are trying to modify a constraint using a statement I hope, and are not looking to just print your statement. 您正在尝试使用希望的语句来修改约束,而不仅仅是打印您的语句。

In that case, you need to make use of Execute Immediate statement, which helps to execute DDL statements on the fly in a procedure. 在这种情况下,您需要使用Execute Instant语句,这有助于在过程中快速执行DDL语句。

BEGIN
EXECUTE IMMEDIATE 'ALTER TABLE ANAL2 DROP CONSTRAINT SYS_C008611' ;
END;
/

Any valid DDL statement (like create, alter, drop etc) can be squeezed in the EXECUTE IMMEDIATE statement, using their correct syntactic formation. 任何有效的DDL语句(如create,alter,drop等)都可以使用其正确的语法形式在EXECUTE IMMEDIATE语句中进行压缩。

Alternatively, you could just mention, if the given SQL is static, as 或者,您可以只提及如果给定的SQL是静态的,则为

ALTER TABLE ANAL2 DROP CONSTRAINT SYS_C008611

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

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