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?
# 15  
Old 09-21-2005
but why I added that line and it still doesnt work.
# 16  
Old 09-21-2005
That is a good question but, as you can see, I added my query to your PL/SQL block and the results changed from no output to output.

I can think of two possibilities:
1. You mistyped it. The text must be as follows: SET SERVEROUTPUT ON. Note that there are no spaces between SERVER and OUTPUT.

2. Your query results in no rows. Try my code block as a test to prove it to yourself that it works. The only requirement is that you have an EXPLAIN PLAN table defined. If you do not, change PLAN_TABLE to something you do have in your schema.

Last edited by tmarikle; 09-21-2005 at 01:08 PM..
# 17  
Old 09-21-2005
I had thought probably I mistyped something,however, I checked it again and again, the answer is no.

is it possible to cause this problem because of the system?

one more difference is i got count(*) in the query and u havent.

Last edited by YoYo; 09-21-2005 at 04:50 PM..
# 18  
Old 09-21-2005
No, it isn't a system problem. I would guess that your query returns no rows at this point.

Try my example above and remember to change "REM #### LINE COMMENTED OUT #### set serveroutput on" to "set serveroutput on" and change "un/pw" to something meaningful on to your database.
# 19  
Old 09-21-2005
You must have edited your message after I read it. The COUNT(*) isn't going to change anything either but now you have given me a thought of how we can test your query.

Place "SELECT COUNT(*), COUNT(*), repeat for total number of columns you are fetching FROM (" before your your first SELECT keyword and place ")" at your SQL's semi-colon ;.

This will prove how many rows your query is return.

Example with my query:
Code:
    cursor cs is
        select count(*), count(*) from (
         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'
        );

This will always return one row; mine is "112,112". If your query returns no rows, you'll get "0,0" always.

Last edited by tmarikle; 09-21-2005 at 05:03 PM..
# 20  
Old 09-21-2005
many thanks for your help. i have sorted out. silly mistake.
cheers.
# 21  
Old 09-22-2005
Hi,
When I tried the example above , evrything is working fine.. but one extra blank line is getting printed... how can I avoid that..

Shihab
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