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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:13:31+00:00 2026-06-05T02:13:31+00:00

In Sql Server, often times when I’m testing the body of a stored procedure,

  • 0

In Sql Server, often times when I’m testing the body of a stored procedure, I copy the body into SSMS, DECLARE the variables at the top of the page, set them to some sample values, and execute the body as-is.

For Example, if my proc is

CREATE PROC MySampleProc
    @Name   VARCHAR(20)
AS
    SELECT @Name

Then my test sql would be

DECLARE @Name VARCHAR(20)
SET     @Name = 'Tom'

    SELECT @Name

What is the Oracle PL/SQL equivalent to this?

This is the closest that I’ve come up with, but I’m getting “PLS-00428: an INTO clause is expected in this SELECT statement”

DECLARE
   myname varchar2(20);
BEGIN
     myname := 'Tom';

     select myname from DUAL;
END;

This is a better example of what I’m really trying to do:

DECLARE
   myname varchar2(20);
BEGIN
     myname := 'Tom';

     SELECT *
     FROM   Customers
     WHERE  Name = myname;
END;

But again, it wants an ‘INTO’ when really I just want the records printed on the screen, not stored in another table….

RESOLVED:

Thanks to @Allan, I’ve got it working well enough. Oracle SQL Developer apparently remembers the parameter values you supply it with. PL/SQL Developer, however, wants nothing to do with this….

enter image description here

If you “Run As Script”, it will abide by your defaults, but it will only return results as ASCI text, not in a grid/spreadsheet

enter image description here

  • 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-05T02:13:32+00:00Added an answer on June 5, 2026 at 2:13 am

    Revised Answer

    If you’re not calling this code from another program, an option is to skip PL/SQL and do it strictly in SQL using bind variables:

    var myname varchar2(20);
    
    exec :myname := 'Tom';
    
    SELECT *
    FROM   Customers
    WHERE  Name = :myname;
    

    In many tools (such as Toad and SQL Developer), omitting the var and exec statements will cause the program to prompt you for the value.


    Original Answer

    A big difference between T-SQL and PL/SQL is that Oracle doesn’t let you implicitly return the result of a query. The result always has to be explicitly returned in some fashion. The simplest way is to use DBMS_OUTPUT (roughly equivalent to print) to output the variable:

    DECLARE
       myname varchar2(20);
    BEGIN
         myname := 'Tom';
    
         dbms_output.print_line(myname);
    END;
    

    This isn’t terribly helpful if you’re trying to return a result set, however. In that case, you’ll either want to return a collection or a refcursor. However, using either of those solutions would require wrapping your code in a function or procedure and running the function/procedure from something that’s capable of consuming the results. A function that worked in this way might look something like this:

    CREATE FUNCTION my_function (myname in varchar2)
         my_refcursor out sys_refcursor
    BEGIN
         open my_refcursor for
         SELECT *
         FROM   Customers
         WHERE  Name = myname;
    
         return my_refcursor;
    END my_function;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often times in my SQL Server database, I'll declare a CreatedDate field. It is
SQL Server a stored procedure written in C# on the .NET 2.0 framework that
SQL Server 2005 Profiler shows that a Stored Procedure (SP) was called and what
SQL Server 2008 I have a query with several local variables that does some
I quite often use the regular expression search and replace in SQL Server Management
When executing scripts in SQL Server Management Studio, messages are often generated that display
I have trouble to update some rows in SQL Server (2005 and 2008). Often,
SQL Server 2005/2008, db=user=schema=owner='John', ASP.net 2.0.50727, vb, IIS7 I'm moving website from one server
SQL Server 2008 allows us to validate XML against an existing XML Schema Collection
SQL Server 2008 Profiler always profiles all databases. I want to restrict profiling or

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.