Question

TOAD, SQL Editor, and EXEC'ing a Stored Procedure?

Asked by: lisfolks

I'm using TOAD for Oracle.  I'm trying to execute a stored procedure with two parameters - one IN and one OUT.  It looks like this:

   PROCEDURE get_stuff (
      parm_1   IN       VARCHAR2,
      parm_2   OUT      currefcursor)

In the SQL Editor window in TOAD, I've tried various things to no avail.  I'm sure this is something simple that I'm missing, 'cause I've tried all sorts of things I've seen in other solutions here at Experts Exchange, but can't get past various errors.  Here's what I think should work from what I've seen here:

     var p1 VARCHAR2 := 'some text';
     var p2 currefcursor;
     
     EXEC get_stuff( :p1, :p2 );

When I run this, though, the SQL Editor pops up a window titled 'Variables' that appears to be looking for a value.  No matter whether I put something in the 'Value' textbox or not, when I click OK, it says:

    ORA-00900: invalid SQL statement

and highlights the 'var' in front of p1.

Please tell me what I'm missing!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-10-12 at 13:51:44ID22022720
Tags

toad

,

procedure

,

stored

,

sql

Topic

Oracle 3rd Party Tools

Participating Experts
3
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Oracle and Toad
    Hi, I am using Toad 7.6.0.11 Standard Addition for the first time and I want to create 2 new tablespaces but I can't see how to do this; there doesn't appear to be any menu option that I can see that allows you to create a 'tablespace'... Can you help...? Thanks Ian
  2. Executing a Stored Proc in Toad
    How do I execute a stored proc in Toad similar to the way it executes in SQL Server Query Analyzer where I would just say Exec procMyTest '01','CID' I have a package and a proc and I want to execute the same above hardcoding the parameters to return a result
  3. Oracle and Toad - Cursor Return Help
    Hello all. I am working with Oracle Db through Toad. I am having a great deal of trouble trying to execute procedures that return generic cursor return set. What I am trying to do is like in SQL Server just run the proc like EXEC proc_.... Parameter pass and return the re...
  4. Spooling in Toad
    how do i spool the output data from a storeprocedure to File.i am using toad with oracle
  5. how to create Oracle package in TOAD
    How do I create an Oracle (10i) package in TOAD (7.3)?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: drs66Posted on 2006-10-12 at 16:31:30ID: 17720294

try this, sqlplus will behave different than toad.

declare
p1 VARCHAR2 := 'some text';
p2 currefcursor;
     
begin
get_stuff(p1, p2);
end;
/

execute as script in toad.

good luck,
daniels

 

by: drs66Posted on 2006-10-12 at 16:42:36ID: 17720331

actually, i take that back..  your syntax should be correct if you just execute as script from within toad.

good luck,
daniels

 

by: drs66Posted on 2006-10-12 at 16:44:07ID: 17720335

as long as your ref cursor is properly pre-defined it looks ok.

thx,
dan

 

by: drs66Posted on 2006-10-12 at 16:56:15ID: 17720365

but somehow you need to initialize the ref cursor; that is why it's asking for param values.

good luck,
daniels

 

by: MohanKNairPosted on 2006-10-13 at 00:46:26ID: 17722053

Using sql*plus

SQL> var p1 VARCHAR2;
SQL> var p2 REF CURSOR;
SQL> BEGIN :p1:='some text'; END;
/
SQL> EXEC get_stuff( :p1, :p2 );

 

by: sujith80Posted on 2006-10-13 at 02:34:03ID: 17722415

well,
I think you are executing a procedure that is defined in a package. And "currefcursor" is a type defined in the package. You cannot invoke the procedure from the sql editor the way you are trying here.

the call should be like

declare
p1 VARCHAR2 := 'some text';
p2 <package_name>.currefcursor;
begin
 <package_name>.get_stuff(p1, p2);
end;
/

 

by: lisfolksPosted on 2006-10-13 at 14:46:30ID: 17727940

For dan, running your suggestion as a script gives me this:

    Bind variable "p1" not declared.
    Bind variable "p2" not declared.
    ORA-01008: not all variables bound

For MohanKNair, running your suggestion as a script gives me this:

    Bind variable "p2" not declared.
    PL/SQL procedure successfully completed.
    ORA-01008: not all variables bound

For sujith80, running your suggestion as a script gives me this:

    ORA-06550: line 2, column 4:
    PLS-00215: String length constraints must be in range (1 .. 32767)
    ORA-06550: line 3, column 4:
    PLS-00201: identifier 'PKG_SOME_PKG.CURREFCURSOR' must be declared
    ORA-06550: line 3, column 4:
    PL/SQL: Item ignored
    ORA-06550: line 5, column 38:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 5, column 3:
    PL/SQL: Statement ignored

You're right that I'm using a package.  So my code looked like this when I ran your suggestion:

    declare
    p1 VARCHAR2 := 'some text';
    p2 PKG_SOME_PKG.currefcursor;
    begin
     PKG_SOME_PKG.get_stuff(p1, p2);
    end;

I tried adding a length to VARCHAR2 like VARCHAR2(200), which fixed the length constraints part of the error, so it became this:

    ORA-06550: line 3, column 4:
    PLS-00201: identifier 'PKG_SOME_PKG.CURREFCURSOR' must be declared
    ORA-06550: line 3, column 4:
    PL/SQL: Item ignored
    ORA-06550: line 5, column 38:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 5, column 3:
    PL/SQL: Statement ignored


For all:  I may or may not try more over the weekend, so please be patient if I don't get back with you for a couple of days.  Please do continue to assist, though - I appreciate your help!

 

by: drs66Posted on 2006-10-13 at 14:49:03ID: 17727964

post up the pkg code as well as the get_stuff code; i'll play around with it.

thx,
daniels

 

by: sujith80Posted on 2006-10-16 at 03:35:39ID: 17737567

Here:
    declare
    p1 VARCHAR2 := 'some text';
    p2 PKG_SOME_PKG.currefcursor;
    begin
     PKG_SOME_PKG.get_stuff(p1, p2);
    end;

You should know where "currefcursor" is defined. It is not a standard declaration. It must be defined in one of your packages.
Otherwise if you just want to test your code you can change the above declaraion as :

    declare
    p1 VARCHAR2(200) := 'some text';
    p2 sys_refcursor;
    begin
     PKG_SOME_PKG.get_stuff(p1, p2);
    end;

 

by: lisfolksPosted on 2006-10-16 at 08:17:03ID: 17739529

Here's a summary of the procedure code within the package:

   PROCEDURE get_stuff (
      p1_parm   IN       VARCHAR2,
      p2_parm   OUT      currefcursor) IS
   BEGIN
      OPEN p2_parm FOR
         SELECT   ...
         .
         .  (uses p1_parm for a value in the WHERE clause)
         .
   END get_stuff;

I didn't write the procedure - it's been around awhile, being used by some applications.  It seems to work fine for the applications.  I want to see the data that should be returned by the procedure, so I can understand its relationship to the applications that use it.  There is a view in the FROM that I don't have access to, but I would expect a different error message if it was failing because of that.  From the messages I'm getting, Toad (or Oracle, actually) seems just to dislike my syntax.  Aargh!

'currefcursor' is used in many of the procedures included in this package.  I don't see it defined anywhere, though.

And, sujith80, I tried both of your suggestions earlier in this thread - see my response from 10/14, 4:46pm, above, for the results...

Thanks!

 

by: lisfolksPosted on 2006-10-16 at 08:29:51ID: 17739646

Oh, and another note:  even if I just try (either with 'Execute statement' or 'Execute as script') -

EXEC PKG_SOME_PKG.get_stuff('some text', NULL);


I get:

ORA-06550: line 1, column 7:
PLS-00201: identifier 'PKG_SOME_PKG.get_stuff' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

???

 

by: sujith80Posted on 2006-10-17 at 06:37:14ID: 17747470

Thats strange.

Do this

desc currefcursor
desc PKG_SOME_PKG

 

by: lisfolksPosted on 2006-10-17 at 14:51:34ID: 17752567

From the two 'desc' statements, got this:

    Error: object currefcursor does not exist

    Error: object PKG_SOME_PKG does not exist

Is this a security issue?  Even though the application can run the sp, perhaps I can't manually run it via TOAD?

 

by: drs66Posted on 2006-10-17 at 16:52:50ID: 17753166

the ref cursor and pkg are not visible to the session your running from.  are then owned by a different user?

daniels

 

by: lisfolksPosted on 2006-10-17 at 17:09:07ID: 17753243

I didn't think so - I'm taking over support of this package since the person who wrote it has left the company.  I'm using a team id to try to access it.  However, the procedure I'm trying to run references a view that I don't have access to.  I thought if I ran the procedure from the package via TOAD, it would have access and be able to return data.  I guess not.

I'm thinking the applications that use it probably utilize a special user id that gives them rights to run the procedures in the package.  I'm new to stored procedures, obviously.  From my programming background, I know this kind of thing is done on servers for applications, but I didn't know it could be done for databases (and, I'm assuming this is the case).  Does that make sense?

 

by: lisfolksPosted on 2006-10-18 at 12:04:39ID: 17759625

Thanks for working on this with me, you all!

I've closed the question and will work with our DBA to ensure my accesses are correct.  You've shown some good examples of how to run a package and its procedures, so this might be helpful to someone else as well.

 

by: sujith80Posted on 2006-10-19 at 01:31:15ID: 17764018

Mr: lisfolks

I dont understand how my answer becomes an "assisted answer",
Thats what exactly I asked you to check by the desc command, whether the package you are using is existing in your scope.

 

by: lisfolksPosted on 2006-10-19 at 20:51:15ID: 17771424

You're right, sujith80, that your suggestion helped me to figure out what was happening.  I wanted to split the points, though, and I could only choose one "accepted answer".  With my comment just above your "assisted answer", I had by then pretty much figured out that it was a security issue.  Both your and dan's answers pretty much confirmed my suspicions.  Your response gave me another step to try (running the 'desc' commands), but didn't explain what the purpose of the step was.  Dan's answer made the results a little clearer.  If I were an Experts-Exchange user looking for a solution to a similar problem, I'd be scrolling down looking for those 'assisted' and 'accepted' answers.  So, yours gives the user the heads up that the 'desc' commands might give them a clue, while dan's answer pretty much sums up what my results from those commands showed.

I appreciate the assistance from everyone who responded, and everybody gave me some clues - and I learned from you all while you were responding.  I do, at the least, offer you my sincerest thanks for taking the time to work on my question.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...