BEGIN
execute immediate '
BEGIN
ALTER TABLE EMPRESA ADD CONSTRAINT pk_empresa_id PRIMARY KEY (EMPRESA_ID);
ALTER TABLE CLIENTE ADD CONSTRAINT pk_cliente_id PRIMARY KEY (CLIENTE_ID);
END';
END;
我想在PL / SQL中执行类似的操作,但它会引发错误。
我该怎么做?
答案 0 :(得分:2)
问题是你不能直接在PLSQL中运行DDL。您可以在单独的execute immediates中运行它们:
BEGIN
execute immediate 'ALTER TABLE EMPRESA ADD CONSTRAINT pk_empresa_id PRIMARY KEY (EMPRESA_ID)';
execute immediate 'ALTER TABLE CLIENTE ADD CONSTRAINT pk_cliente_id PRIMARY KEY (CLIENTE_ID)';
END;
/