如何运行Oracle数据库中的Select语句重新调整的查询
我正在使用Oracle数据库,并且有此查询,该查询会
(SELECT 'ALTER TABLE drop CONSTRAINT '
||constraint_name
||' ;'
FROM user_constraints
WHERE constraint_type = 'R'
AND table_name = 'PRINCIPALS_ROLES'
AND r_constraint_name =
(
SELECT constraint_name
FROM user_constraints
WHERE table_name = 'PRINCIPALS'
AND constraint_type= 'P' ))
在运行此查询时生成 Alter Table 语句,我将获得以下输出。
ALTER TABLE drop CONSTRAINT PRINCIPAL_ID_FKEY ;
现在,我想在生成此查询的同一SQL语句中运行上述查询。我们该怎么做?我不想使用声明(> gt; gt; gt; gt;开始 - >结束。 我希望我的查询是一个可执行的查询。
I am using Oracle database and I have this query which generates Alter Table statement
(SELECT 'ALTER TABLE drop CONSTRAINT '
||constraint_name
||' ;'
FROM user_constraints
WHERE constraint_type = 'R'
AND table_name = 'PRINCIPALS_ROLES'
AND r_constraint_name =
(
SELECT constraint_name
FROM user_constraints
WHERE table_name = 'PRINCIPALS'
AND constraint_type= 'P' ))
When I run this query I get below output.
ALTER TABLE drop CONSTRAINT PRINCIPAL_ID_FKEY ;
Now I want to run the above query in the same sql statement that generated this query. How can we do this? I Dont want to use stored procedure like Declare --> Begin --> End.
I want my query to be a single executable query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,并不是所有的梦想成真。恐怕这是其中之一。因为,您描述的是一个经典的动态SQL示例,需要某种PL/SQL。示例显示了一个存储过程,因此您只使用一个语句才能运行 can 。
样品表:
虚拟程序;您可能想重复使用它,因此您至少将表名称作为参数传递。
测试:
如果一切顺利,
principals_roles
现在只能具有其主要密钥约束:Unfortunately, not all dreams come true; I'm afraid this is one of these. Because, what you described is a classic dynamic SQL example which requires PL/SQL of some kind; example shows a stored procedure so you kind of can run it using just a single statement.
Sample tables:
Dummy procedure; you'd probably want to reuse it, so you'd then pass at least table name as a parameter.
Testing:
If everything went OK,
principals_roles
should now have only its primary key constraint:您有一个ddl并执行它将需要即时的动态执行,不能在单个语句中完成。您将至少需要2个语句,并且执行即时需要
开始结束
块。You have a DDL and executing it will require dynamic execute immediate, which can't be done in a single statement. You will need at least 2 statements and the execute immediate requires a
BEGIN END
block.