Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:19:26+00:00 2026-06-03T07:19:26+00:00

I would like to execute the anonymous PL/SQL and need to get the resultset

  • 0

I would like to execute the anonymous PL/SQL and need to get the resultset object. I got the code which can be done by using cursors inside the PL/SQL block.

But the PL/SQL block itself will come from the database as text. So I can’t edit that PL/SQL block. And it will return only two values whose column names will be same always. It will return list of 2 column combination values.

Here I am giving sample PL/SQL.

BEGIN

RETURN 'select distinct fundname d, fundname r from <table> where condition order by 1';

EXCEPTION
   WHEN OTHERS THEN
    RETURN 'SELECT ''Not Available'' d, ''Not Available'' r FROM dual';
END;

Any reply will be so helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:19:27+00:00Added an answer on June 3, 2026 at 7:19 am

    Here is a self contained example of how to “execute the anonymous PL/SQL and get the resultset object”

    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Types;
    
    import oracle.jdbc.OracleTypes;
    
    public class CallPLSQLBlockWithOneInputStringAndOneOutputStringParameterAndOneOutputCursorParameter {
    
        public static void main(String[] args) throws Exception {
    
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    
            // Warning: this is a simple example program : In a long running application,
            // error handlers MUST clean up connections statements and result sets.
    
            final Connection c = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "manager");
            String plsql = "" +
            " declare " +  
            "    p_id varchar2(20) := null; " +
            "    l_rc sys_refcursor;" +
            " begin " +
            "    p_id := ?; " +
            "    ? := 'input parameter was = ' || p_id;" +
            "    open l_rc for " +
            "        select 1 id, 'hello' name from dual " +
            "        union " +
            "        select 2, 'peter' from dual; " +
            "    ? := l_rc;" +
            " end;";
    
            CallableStatement cs = c.prepareCall(plsql);
            cs.setString(1, "12345");
            cs.registerOutParameter(2, Types.VARCHAR);
            cs.registerOutParameter(3, OracleTypes.CURSOR);
    
            cs.execute();
    
            System.out.println("Result = " + cs.getObject(2));
    
            ResultSet cursorResultSet = (ResultSet) cs.getObject(3);
            while (cursorResultSet.next ())
            {
                System.out.println (cursorResultSet.getInt(1) + " " + cursorResultSet.getString(2));
            } 
            cs.close();
            c.close();
        }
    }
    

    The above example query “select 1 id, ‘hello’ name from dual union select 2, ‘peter’ from dual;” can be replaced by any query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to execute a method which can only be called once my
I would like to execute some kind of subquery with my fetchedresultscontroller. I've got
I have a jar file that I would like to execute using PHP, but
I would like to store lengthy .sql scripts in my solution and execute them
I have multiple UIViews, UIButtons etc. and would like to execute some specific code
I would like to execute multiple statements on one line in SQL Server 2005.
I've got a pretty stubborn executable that I would like to execute sequentially multiple
Friends, I have a dynamic sql query that I would like to execute and
I would like to execute a simple sql line each time a new connection
I would like to execute WScript.Shell command using Run and set it to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.