我有一个包裹
create or replace package core_utils is
TYPE CONSULTA IS REF CURSOR;
function getCursor(par in varchar2 default null) return core_utils.CONSULTA;
end core_utils;
create or replace package body core_utils is
function getCursor(par in varchar2 default null) return core_utils.CONSULTA
is
c core_utils.CONSULTA;
begin
OPEN c FOR
select d.aplicacio,d.nom
from variables_def d
where d.global='S'
and d.nom like par
order by d.nom;
return c;
end;
end core_utils;
通话就像..
@GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
m=[:]
...
m.sql =Sql.newInstance(m.url, m.username, m.password, m.driver)
m.sql.call('{? = call core_utils.getCursor(?)}', [Sql.????? ,par]) { resu->
//
.............
.............
}
当然,“呼叫”不是您应使用的过程。我没有找到任何对我有帮助的例子。
答案 0 :(得分:0)
/**************************************
inspiration
https://stackoverflow.com/questions/20242512/how-to-get-cursor-from-oracle-using-groovy
plsql
--------------------------------------
begin
-- Call the function
:result := core_utils.getcursor(par => :par);
end;
========================================================================
oracle
create or replace package core_utils is
TYPE CONSULTA IS REF CURSOR;
function getCursor(par in varchar2 default null) return core_utils.CONSULTA;
end core_utils;
----------------------------------------------
create or replace package body core_utils is
function getCursor(par in varchar2 default null) return core_utils.CONSULTA
is
c core_utils.CONSULTA;
begin
OPEN c FOR
select d.aplicacio,d.nom
from variables_def d
where d.global='S'
and d.nom like par
order by d.nom;
return c;
end;
end core_utils;
========================================================================
*/
@GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
import oracle.jdbc.OracleTypes;
import groovy.sql.OutParameter;
import java.sql.ResultSet;
m=[:]
//@Grab('com.oracle:ojdbc7')
m.CURSOR_PARAMETER = new OutParameter() {
public int getType() {
return OracleTypes.CURSOR;
}
};
m.url = "jdbc:oracle:thin:@server.empresa.es:1522:SERV"
m.username = "user"
m.password = "pass"
m.driver = "oracle.jdbc.driver.OracleDriver"
m.sql =Sql.newInstance(m.url, m.username, m.password, m.driver)
m.test={par ->
def wresu=m.sql.callWithAllRows('{? = call core_utils.getCursor(?)}',[m.CURSOR_PARAMETER,par]) { ResultSet rs ->
//
println rs
while (rs.next()) {
println rs.getString("APLICACIO")
}
}
wresu;
}
m.test("%BA%")