2

没有进入 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 缺少关键字

4

2 回答 2

0

应该是这个

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';
于 2015-04-07T15:12:03.370 回答
0

尝试:

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 ;
于 2015-04-07T15:16:53.767 回答