立即执行无法将结果绑定到变量中



Without into-tables_find过程将运行,但我需要检查数据库中是否存在此表。

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缺少关键字

必须是这个

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';

尝试:

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 ;

相关内容

  • 没有找到相关文章

最新更新