立即执行无法将结果绑定到变量中
Posted
技术标签:
【中文标题】立即执行无法将结果绑定到变量中【英文标题】:Execute immediate can't bind result into a variable 【发布时间】:2015-04-07 15:03:16 【问题描述】:没有进入 tables_found 过程将运行,但我需要检查该表是否存在于我的数据库中。
CREATE OR replace PROCEDURE dropdb(tables_found out number) IS
BEGIN
execute immediate 'SELECT COUNT(*) into tables_found FROM user_tables where table_name=''USERS''';
if (tables_found = 1) then
execute immediate ' drop table users';
END IF;
END dropdb;
错误日志:
ora-00905 缺少关键字
【问题讨论】:
【参考方案1】:应该是这个
Execute immediate 'SELECT COUNT(*) FROM user_tables where table_name=''USERS''' into tables_found;
甚至更好:
Execute immediate 'SELECT COUNT(*) FROM user_tables where table_name=:name' into tables_found using 'USERS';
【讨论】:
【参考方案2】:试试:
execute immediate 'SELECT COUNT(*) into :x FROM user_tables
where table_name=''USERS'''
USING OUT tables_found ;
如果上面的方法不行,试试这个:
execute immediate 'DECLARE x NUMBER; BEGIN SELECT COUNT(*) into x
FROM user_tables
where table_name=''USERS'';
:tables := x END'
USING OUT tables_found ;
【讨论】:
以上是关于立即执行无法将结果绑定到变量中的主要内容,如果未能解决你的问题,请参考以下文章