从 Oracle JDBC 瘦驱动程序执行 PL/SQL 开始/结束过程
我正在尝试创建 Oracle PL/SQL 过程并通过 Oracle JDBC(瘦驱动程序)执行它们。这是完整的 PL/SQL 脚本:
begin
for i in (select owner, constraint_name, table_name from all_constraints where owner = 'SCHEMA' and status = 'ENABLED') LOOP
execute immediate 'alter table SCHEMA.'||i.table_name||' disable constraint SCHEMA.'||i.constraint_name||'';
end loop;
end;
/
begin
for i in (select table_name from all_tables where owner = 'SCHEMA') LOOP
execute immediate 'truncate table SCHEMA.'||i.table_name||'';
end loop;
end;
/
begin
for i in (select owner, constraint_name, table_name from all_constraints where owner = 'SCHEMA' and status = 'DISABLED') LOOP
execute immediate 'alter table SCHEMA.'||i.table_name||' enable constraint SCHEMA.'||i.constraint_name||'';
end loop;
end;
/
在 java 中,我按“/”进行拆分,因此每个开始结束块都在单独的语句中执行。执行该语句的 java 代码是:
CallableStatement c = dbc.getConnection().prepareCall(sqlStatement);
c.executeUpdate();
我收到以下错误:
java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
ORA-06512: at line 3
如何格式化它并在 JDBC 中执行 PL/SQL?
更新:澄清一下,所有三个语句在执行时都没有分割的“/”分隔符。
更新: Oracle 服务器是以下版本:Oracle Database 11g 版本 11.2.0.1.0 - 64 位生产
I am trying to create Oracle PL/SQL procedures and execute them via Oracle JDBC (thin driver). Here is the full PL/SQL script:
begin
for i in (select owner, constraint_name, table_name from all_constraints where owner = 'SCHEMA' and status = 'ENABLED') LOOP
execute immediate 'alter table SCHEMA.'||i.table_name||' disable constraint SCHEMA.'||i.constraint_name||'';
end loop;
end;
/
begin
for i in (select table_name from all_tables where owner = 'SCHEMA') LOOP
execute immediate 'truncate table SCHEMA.'||i.table_name||'';
end loop;
end;
/
begin
for i in (select owner, constraint_name, table_name from all_constraints where owner = 'SCHEMA' and status = 'DISABLED') LOOP
execute immediate 'alter table SCHEMA.'||i.table_name||' enable constraint SCHEMA.'||i.constraint_name||'';
end loop;
end;
/
In java I am splitting on '/' so each begin end block is executed in a separate statement. The java code to execute the statement is:
CallableStatement c = dbc.getConnection().prepareCall(sqlStatement);
c.executeUpdate();
I'm receiving the following error:
java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
ORA-06512: at line 3
How do I format this and execute the PL/SQL in JDBC?
Updated: To clarify, all three statements are executed without the '/' delimiter that is split on.
Updated: The oracle server is the following version: Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在“enable /diable”约束中,您不应添加架构名称(您的“SCHEMA”)。
从手册中:
ALTER TABLE
您的示例:
测试查询
结果
正确的动态sql
上一次查询结果
In the "enable /diable" constraint you shouldn't add the schema name (your'SCHEMA).
From the manual:
ALTER TABLE
Your example:
Test Query
Result
Correct dynamic sql
Previous query result