2016-03-10 28 views
-1
SELECT 'ALTER TABLE ' || uc.table_name || ' DROP CONSTRAINT ' || uc.constraint_name FROM user_constraints uc WHERE constraint_type = 'R'; 

回报即某些语句,我可以手动执行,如:甲骨文:从选定的字符串执行查询

ALTER TABLE APPLICATIONUSERROLE DROP CONSTRAINT APP_APPUSERROLE_FK1      
ALTER TABLE APPLICATIONUSERROLE DROP CONSTRAINT USER_APPUSERROLE_FK1      
ALTER TABLE APPLICATIONUSERROLE DROP CONSTRAINT ROLE_APPUSERROLE_FK1 

我有什么做的,自动执行呢?

比如我想:

EXECUTE IMMEDIATE (SELECT 'ALTER TABLE ' || uc.table_name || ' DROP CONSTRAINT ' || uc.constraint_name FROM user_constraints uc WHERE constraint_type = 'R'); 

但那不工作的抛出一些错误。

在此先感谢。

回答

0
begin 
    for i in (SELECT 'ALTER TABLE ' || uc.table_name || ' DROP CONSTRAINT ' || uc.constraint_name as sql_text FROM user_constraints uc WHERE constraint_type = 'R') 
    loop 
     execute immediate i.sql_text; 
    end loop; 
end; 
+0

感谢,但抛出:PLS-00103:出现符号 “SQL” – Powerslave

+0

我编辑的职位。尝试用户sql_text别名,而不是sql – SkyWalker

+0

谢谢,现在抛出:PLS-00302:组件'sql_text'必须声明;) – Powerslave