【问题标题】:How to call PL/SQL fucntion with REF_CURSOR using JPA or JDBC [duplicate]如何使用 JPA 或 JDBC 使用 REF CURSOR 调用 PL/SQL 函数 [重复]
【发布时间】:2020-05-05 01:14:16
【问题描述】:

我在 PL/SQL 中创建了函数,它返回我的架构中所有表的名称。

CREATE OR REPLACE FUNCTION dbINFO
return sys_refcursor AS 
table_info sys_refcursor;
begin
    open table_info
        for select table_name from all_tables where owner = 'HOMEUSER';

        return table_info;
end;

我想使用 JDBC 或 JPA 来调用它。

我该怎么做?我几乎尝试了所有方法都没有结果。

【问题讨论】:

标签: java spring oracle jpa jdbc


【解决方案1】:

在您的任何实体类上创建命名本机查询。

@NamedNativeQuery(name="getAllTablesOwnedByHomeUser",
callable=true , query = "{? = call dbINFO()}",
resultClass = Pojo.class) //Pojo is class whch u r using 2 map resltset.


 //Field name in Pojo class and Table columns name should match which are returned 
   // by the cursor

现在使用您的 EntityManager 调用命名查询,如下所示。

  EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
TypedQuery<Pojo.class> q = em.createNativeQuery("getAllTablesOwnedByHomeUser",Pojo.class);
List<Pojo> tables = q.getResultList();
em.getTransaction().commit();
em.close();

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2020-09-21
    相关资源
    最近更新 更多