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 6387199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:07:17+00:00 2026-05-25T03:07:17+00:00

I’m sure what I want is very simple but I cannot figure out how.

  • 0

I’m sure what I want is very simple but I cannot figure out how.

I want :

  • To declare some variables and initialize them to certain values
  • To excecute a number of selects (predicated by the above variable values) and see the results as if i had executed the results straight on the sqlplus command line

I believe it’s necessary to use the block structure in order that I may declare and make use of variables within the predicates of the queries. Although the examples shown here are quite simple in the real case there are numberous, much more complex SELECT’s.

I tried doing this (forgetting about predicates for a moment) …

DECLARE
    EMP_EMPLOYEE_ID_IN  VARCHAR2(12);
BEGIN
    EXECUTE IMMEDIATE 'SELECT * FROM DEPT WHERE DEPNO';
END;
/

… but when I do that I get to execute the select without seeing the output.

I’ve also tried this …

DECLARE
    EMP_EMPLOYEE_ID_IN  VARCHAR2(12);
BEGIN
    SELECT * FROM DEPT;
END;
/

… but then I get …

PLS-00428: an INTO clause is expected in this SELECT statement

… I really don’t want to have to declare a variable for every column which would appear in my output.

Can anyone tell me how I can execute the SELECTs but simply and easily see the output as if I were on the sqlplus command line, ie to see the same output as if I did this

SQL> SELECT * FROM DEPT;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

Thanks



I have now tested the answer given by Shannon Severance below and found that it will do what I want.

For the sake of later readers I thought it might be useful to show the complete script here.

set line 32000;
set trimspool on;
var V_CURSOR1 REFCURSOR;
var V_CURSOR2 REFCURSOR;
var V_CURSOR3 REFCURSOR;
DECLARE
    DEPT_NUM_IN     VARCHAR2(12);
BEGIN
    DEPT_NUM_IN :=  '10';
    OPEN :V_CURSOR1 FOR SELECT * FROM DEPT;
    OPEN :V_CURSOR2 FOR SELECT * FROM DEPT ORDER BY LOC;
    OPEN :V_CURSOR3 FOR SELECT * FROM DEPT WHERE DEPTNO = DEPT_NUM_IN ORDER BY LOC;
END;
/
print V_CURSOR1
print V_CURSOR2
print V_CURSOR3
  • 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-05-25T03:07:18+00:00Added an answer on May 25, 2026 at 3:07 am

    From sqlplus, other tools may be different.

    First declare a sqlplus refcursor variable

    SQL> var l_cursor refcursor
    

    Then open that cursor within a PL/SQL block, where you will have access to declared variables and everything:

    SQL> edit
    Wrote file afiedt.buf
    
      1  declare
      2      l_number number;
      3  begin
      4      open :l_cursor for select table_name from all_tables where rownum < 10;
      5* end;
    SQL> /
    
    PL/SQL procedure successfully completed.
    

    Notice above that the refcursor variable is prepended with a :, this is because we are binding a sqlplus variable into the PL/SQL anonymous block

    Next, use the SQLPLUS print command:

    SQL> print l_cursor
    
    TABLE_NAME
    ------------------------------
    ICOL$
    CON$
    UNDO$
    PROXY_ROLE_DATA$
    FILE$
    UET$
    IND$
    SEG$
    COL$
    
    9 rows selected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

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.