Is it possible to pass parameters to the called sql script from sqlplus script?...

Posted on 2008-10-14
Last Modified: 2013-12-07
  I can't find anywhere the answer so I hope you will help...
I run  in sqlplus  query with cursor. I need to pass each row from the cursor as parameter to the called script....Is it actually possible?
   CURSOR c_schema IS
    select dschema from x.process_control where process_name = '....' order by schema;
      v_schema    process_control.db_schema%TYPE;
   OPEN c_schema;
      FETCH c_schema INTO v_schema;
       If v_schema <> '' then
       @connecting_schema v_schema;   ????????????   
     EXIT WHEN c_schema%NOTFOUND;
    CLOSE c_schema;

Open in new window

Question by:Neilami
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
LVL 74

Expert Comment

ID: 22711473
there are two standard ways to do this.

first,  open your cursor and pass it is as a reference cursor to your procedure which would then do the fetching and processing of each row itself.

that would look like this...

      v_cur  SYS_REFCURSOR;
      OPEN v_cur FOR SELECT ..... <your query here>;


second,  simply fetch the values and pass them into your procedure.  I recommend using the FOR cursor loop instead of while/end.   That would look like this...

     for x in (select co1, col2, col3...  <your query here>) loop
     end loop;
LVL 29

Expert Comment

ID: 22711773

Also, unless the "@connecting_schema v_schema;   ????????????  " is a valid set of PL/SQL statements, an SQL*Plus command would not recognized by PL/SQL. You would need to convert it to a stored procedure and use sdstuber's recommendation.


Author Comment

ID: 22714884
so, somehow, still not clear answer....if i don't want to create any procedure , is it impossible? If yes, how exactly...?
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

LVL 74

Accepted Solution

sdstuber earned 250 total points
ID: 22714916
no, it is not possible to use pl/sql to call sqlplus scripts.

you could instead,  use shell scripting to iterate through values and call sqlplus with those parameters.  
LVL 74

Expert Comment

ID: 22714930
or, take the code out of your scripts and embed it within the anonymous pl/sql block.

Author Comment

ID: 22715033
yeah, the parameter was suppose to be the name of the schema, under which would the sql connect to database and run other file...and here we come to my question that nobody answer :)....again...

but anyways thx sdstuber
LVL 74

Expert Comment

ID: 22715214
sorry, "it's not possible" is the answer.

pl/sql is simply not the tool for doing what you're asking.

if you used a procedure instead of scripts it could work,  or if you use shell scripting it will work, or if you use external procedures or java stored procedures to invoke sqlplus it would work.  But given what the constraints you requested, it's not possible.

Author Comment

ID: 22715407
sorry, with that not answered question i meant the other question that i posted the link to....I already accept your "no,impossible" first time ;)....btw congratulation to marriage....Alles gute!
LVL 74

Expert Comment

ID: 22717469
thank you!
LVL 29

Expert Comment

ID: 22724259

-- OR --

You could try something like this:

-- ---------------------------------------------------------------------
-- Execute on all schema
set pages 0 feed off ver off term off
spo /tmp/schema_exec.sql
Select "@connecting_schema "||Dschema
 From X.Process_Control
Where Process_Name = '....'
Order By Schema;
spo off

Open in new window


Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 32
sql query help 15 50
creating a permanent table from  the results of a select statement in sql server 2016 5 30
Get data from two MySQL tables 6 20
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question