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

Execute immediate can't bind result into a variable

如果不进入 tables_found 过程将 运行 但我需要检查我的数据库中是否存在此 table 。

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 missing keyword

一定是这个

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 ;