DB2 删除并创建表
我试图确保当我运行存储过程时它会检查表是否存在,如果存在则删除它然后重新创建表。使用以下存储过程
CREATE PROCEDURE PROCEDURE1 ()
DYNAMIC RESULT SETS 1
P1: BEGIN
if( exists(
select 1 from syscat.tables where tabschema = 'AELUM' and tabname = 'ROOTNODES'
)) then
drop table AELUM.ROOTNODES ;
CREATE TABLE "AELUM"."ROOTNODES" (
"UID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE CACHE 20 NO ORDER ),
"NODENAME" VARCHAR(255),
"HASCHILD" INTEGER,
"CHILDTABLE" VARCHAR(255)
)
DATA CAPTURE NONE;
**-->>ALTER TABLE "AELUM"."ROOTNODES" ADD CONSTRAINT "ROOTNODES_PK" PRIMARY KEY ("UID");
end if;
END P1
现在上面标记的点**-->>不被数据工作室喜欢。我不确定这个说法有什么问题。请帮忙
I'm trying to ensure when i run a stored procedure it checks if a table exists and if it does it drops it then re-creates the table. Using the following stored proc
CREATE PROCEDURE PROCEDURE1 ()
DYNAMIC RESULT SETS 1
P1: BEGIN
if( exists(
select 1 from syscat.tables where tabschema = 'AELUM' and tabname = 'ROOTNODES'
)) then
drop table AELUM.ROOTNODES ;
CREATE TABLE "AELUM"."ROOTNODES" (
"UID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 NO CYCLE CACHE 20 NO ORDER ),
"NODENAME" VARCHAR(255),
"HASCHILD" INTEGER,
"CHILDTABLE" VARCHAR(255)
)
DATA CAPTURE NONE;
**-->>ALTER TABLE "AELUM"."ROOTNODES" ADD CONSTRAINT "ROOTNODES_PK" PRIMARY KEY ("UID");
end if;
END P1
Now the point labeled above **-->> isn't liked by data studio. I am not sure what is wrong with this statement. please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定 DB2,但在 Oracle 中,您无法在标准 PL/SQL 中执行 DDL。相反,您必须将 DDL 作为
VARCHAR2
并执行EXECUTE IMMEDIATE
语句。Not sure about DB2, but in Oracle you cannot perform DDL in standard PL/SQL. Instead, you have to put the DDL as a
VARCHAR2
and perform anEXECUTE IMMEDIATE
statement.