can nested SQl be run in Unix Script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can nested SQl be run in Unix Script?
# 1  
Old 09-20-2005
can nested SQl be run in Unix Script?

can nested SQl be run in Unix Script?

I tried some and found only simply sql(one select) can work well in unix script.
# 2  
Old 09-21-2005
If you mean:

a) can this nested SQL be run in a shell script?
Code:
{
sqlplus un/pw <<EOF
select col_a
       , col_b
from   table_a a
where exists (
      select 1 
      from   table_b b 
      where a.col_a = b.col_b
);
EOF
} | while read COL_A COL_B
do
   echo $COL_A $COL_B
done

Answer: Yes


or


b) can this nested SQL be run in a shell script?

Code:
{
sqlplus un/pw <<EOF
select col_a
from   table_a a;
EOF | while read COL_A
do
    sqlplus un/pw <<EOF
select col_c
from   table_b
where col_a = ${COL_A};
EOF 
} | while read COL_B
    do
        echo ${COL_B}
    done
done

Answer: Yes

Last edited by tmarikle; 09-21-2005 at 12:13 AM..
# 3  
Old 09-21-2005
how about:
select x,y
from (select blah1,blah2) a ,(select blah1,blah2 ) b
where a.blah1=b.blah1;

mine one doesnt work at all.
# 4  
Old 09-21-2005
Yes, you can. I'll post proof momentarily.
# 5  
Old 09-21-2005
what is problem with mine one. the output file was always empty, how can I test where is the problem
# 6  
Old 09-21-2005
Code:
{
typeset IFS='
'
sqlplus -s un/pw <<EOF
select t.table_name, c.column_name
 from
   (select table_name
          ,column_name
    from   all_tab_columns) c
  ,(select table_name
    from   all_tables) t
where t.table_name = c.table_name
and   t.table_name = 'PLAN_TABLE'
;
EOF
} | while read line
do
    echo "$line"
done

TABLE_NAME                     COLUMN_NAME
------------------------------ ------------------------------
PLAN_TABLE                     STATEMENT_ID
PLAN_TABLE                     TIMESTAMP
PLAN_TABLE                     REMARKS
PLAN_TABLE                     OPERATION
PLAN_TABLE                     OPTIONS
PLAN_TABLE                     OBJECT_NODE
PLAN_TABLE                     OBJECT_OWNER
...

27 rows selected.

# 7  
Old 09-21-2005
Quote:
Originally Posted by YoYo
how about:
select x,y
from (select blah1,blah2) a ,(select blah1,blah2 ) b
where a.blah1=b.blah1;

mine one doesnt work at all.
I need a real example. "x" and "y" are not in your sub selects so this example is problematic. Also "(select blah1, blah2)" is incomplete.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Sqlplus - Capture the sql statement about to run and execution status

Greetings Experts, I am on AIX using ksh. Created a unix script which generates the CREATE OR REPLACE VIEW ... and GRANT .. statements, which are placed in a single .txt file. Now I need to execute the contents in the file (there are around 300 view creation and grant statements) in Oracle and... (4 Replies)
Discussion started by: chill3chee
4 Replies

2. Shell Programming and Scripting

Run sql query after ssh in UNIX

I am running this test.ksh on server1. It successfully logins to server2 but runs the queries of query.sql on server1. query.sql is present in both server1 and server2 Can anybody please help. I need to run queries on server2 itself.:confused: Below is the test script... (10 Replies)
Discussion started by: shruthimithra
10 Replies

3. Shell Programming and Scripting

run sql queries from UNIX shell script.

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX? :confused: (1 Reply)
Discussion started by: 24ajay
1 Replies

4. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

5. Shell Programming and Scripting

Time taken to run a SQL script

Hello I am asked to run around 5-6 SQL queries in a shell script and take a note of the time taken to execute each query to a file. How do I get the time taken to run the individual SQL queries (2 Replies)
Discussion started by: vat1kor
2 Replies

6. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

7. Shell Programming and Scripting

Run Sql plus in shell script

Hello, I want to connect to ssh, run a query, and store that into a variable in the shell script. Also I need to pass the variable back to php to display the query results. I have created a public/private key pair for ssh connection and that is working fine. Also I am able to run query in the... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

8. Shell Programming and Scripting

Nested SQL queries within Shell script

Hi, Would someone know if I can fire nested sql queries in a shell script? Basically what I am trying to do is as follows: my_sql=$(sqlplus -s /nolog<<EOF|sed -e "s/Connected. *//g" connect... (2 Replies)
Discussion started by: shrutihardas
2 Replies

9. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

10. Shell Programming and Scripting

Nested Case in UNIX script

Hi I wanted to know if we can write a nested case in UNIX script. Something like following - Case ${sDB} in Srvr1) case ${sSchema} Sch1) DBusr=Username1 DBPwd=Pwd1 ;; Sch2) DBusr=Username2 ... (1 Reply)
Discussion started by: sumeet
1 Replies
Login or Register to Ask a Question