在groovy教程中:http://groovy.codehaus.org/Database+features
有关于手续的部分。当我尝试这个例子时:
The same example again but with a GString variation:
def first = 'Sam'
sql.call("{$Sql.VARCHAR = call FullName($first)}") { name ->
assert name == 'Sam Pullara'
}
我有例外:
Chyba: ORA-06550: line 1, column 13:
PLS-00222: no function with name 'FULLNAME' exists in this scope
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00222: no function with name 'FULLNAME' exists in this scope
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
是的,这是异常的,因为我只得到了程序FULLNAME,我想要调用的不是函数。这个教程仍然是实际的吗?
答案 0 :(得分:1)
在Oracle中,存储过程无法返回值,函数可以返回值。这就是你得到那个错误的原因。您可以使用我的测试存储过程和groovy代码验证...
CREATE OR REPLACE PROCEDURE test_procedure
( string_in IN OUT VARCHAR2 ) IS
BEGIN
string_in := 'hi ' || string_in ;
END;
import groovy.sql.Sql
Sql sql = Sql.newInstance("jdbc:oracle:thin:@hostname:1521:dbname", username","password","oracle.jdbc.driver.OracleDriver")
def first="Wade"
sql.call '{call test_procedure(?)}',
[Sql.inout(Sql.VARCHAR(first))],
{ test ->
println ">>" + test + "<<"; // >>hi Wade<<
}
答案 1 :(得分:0)
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes
Sql sql = Sql.newInstance("jdbc:oracle:thin:@hostname:1521:dbname", "username","password","oracle.jdbc.driver.OracleDriver")
dept_id = 50
sql.call('{? = call FullName(?)}', [Sql.VARCHAR, 'Sam']) { name->
println name
}