从Java运行sqlplus脚本的简单方法 [英] Simple way to run sqlplus script from java
问题描述
我有一个包含sqlplus特定脚本的sql文件:它包含/或;作为语句终止符,执行存储过程的EXEC等.
I've got sql file that contains sqlplus specific script: it includes / or ; as statement terminators, EXEC to execute stored procedures, etc.
我需要从Java(jdbc)执行此脚本,而无需sqlplus.
I need to execute this script from java (jdbc) without the need for sqlplus.
sql ant任务/maven sql插件无法处理不同的终止符或EXEC命令.
sql ant task / maven sql plugin can't handle the different terminators or EXEC commands.
您知道不运行sqlplus的任何好方法吗?
Do you know any good way to do so without running sqlplus ?
推荐答案
我们遇到了同样的问题...简而言之,目前还没有现成的解决方案:如果打开 Maven 源,您会看到他们使用的是基于正则表达式的简单脚本拆分器,该脚本拆分器适用于简单脚本,但通常在例如存储过程.
We've bumped into the same problem... In brief, there are no ready solutions for that: if you open Ant or Maven sources, you'll see they are using a simple regexp-based script splitter which is fine for simple scripts, but usually fails on e.g. stored procedures.
确实有用于PL/SQL的ANTLR解析器,例如 Alexandre Porcelli的解析器-非常接近,但仍不能用作嵌入式解决方案.
There are indeed ANTLR parsers for PL/SQL, such as Alexandre Porcelli's one—those are very close, but still not ready to be used as a drop-in solution.
We ended up writing yet another ad hoc splitter which is aware of some sqlplus commands like /
and EXIT
— it's still ugly, but works for most of our scripts.
这篇关于从Java运行sqlplus脚本的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!