Select 在 plsql for 循环中使用内连接查询失败
Select query using inner join in plsql for loop fails
这是我的 plsql 块
BEGIN
FOR c IN ( SELECT T.table_name FROM user_tables T INNER JOIN (SELECT distinct to_char(SYSTEM_DATE,'yyyymmdd') as sys_date FROM *) ON T.table_name LIKE '%' || sys_date || '%' )
LOOP
EXECUTE IMMEDIATE 'DROP TABLE ' || c.table_name || ' CASCADE';
END LOOP;
END;
出现缺少关键字错误
Error report:
ORA-00905: missing keyword
ORA-06512: at line 4
00905. 00000 - "missing keyword"
*Cause:
*Action:
你能告诉我代码中有什么问题吗?
如果你看看 Standard DOCS
你会明白你需要将 DROP
语句写成 -
DROP TABLE TABLE_NAME CASCADE CONSTRAINTS;
您的 SQL 缺少 CONSTRAINTS
关键字
DROP TABLE ' || c.table_name || ' CASCADE
是 PostgreSQL
中的工作语句
DROP TABLE name [, ...] [ CASCADE | RESTRICT ]
但不在 Oracle 中,它不需要 CASCADE 或 CASCADE CONSTRAINTS
子句:
Specify CASCADE CONSTRAINTS to drop all referential integrity constraints that refer to primary and unique keys in the dropped table. If you omit this clause, and such referential integrity constraints exist, then the database returns an error and does not drop the table.
这是我的 plsql 块
BEGIN
FOR c IN ( SELECT T.table_name FROM user_tables T INNER JOIN (SELECT distinct to_char(SYSTEM_DATE,'yyyymmdd') as sys_date FROM *) ON T.table_name LIKE '%' || sys_date || '%' )
LOOP
EXECUTE IMMEDIATE 'DROP TABLE ' || c.table_name || ' CASCADE';
END LOOP;
END;
出现缺少关键字错误
Error report:
ORA-00905: missing keyword
ORA-06512: at line 4
00905. 00000 - "missing keyword"
*Cause:
*Action:
你能告诉我代码中有什么问题吗?
如果你看看 Standard DOCS
你会明白你需要将 DROP
语句写成 -
DROP TABLE TABLE_NAME CASCADE CONSTRAINTS;
您的 SQL 缺少 CONSTRAINTS
关键字
DROP TABLE ' || c.table_name || ' CASCADE
是 PostgreSQL
DROP TABLE name [, ...] [ CASCADE | RESTRICT ]
但不在 Oracle 中,它不需要 CASCADE 或 CASCADE CONSTRAINTS
子句:
Specify CASCADE CONSTRAINTS to drop all referential integrity constraints that refer to primary and unique keys in the dropped table. If you omit this clause, and such referential integrity constraints exist, then the database returns an error and does not drop the table.