0

在 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 而不是函数。本教程仍然是实际的吗?

4

2 回答 2

1

在 Oracle 中,存储过程不能返回值,而函数可以返回值。这就是您收到该错误的原因。您可以使用我的测试存储过程和常规代码进行验证...

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<<
    }
于 2013-11-11T00:00:54.190 回答
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
}
于 2013-03-18T09:30:04.040 回答