The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Execute oracle query determined at runtime from a unix script infyanurag Shell Programming and Scripting 4 02-01-2008 03:54 AM
Script executing sql query kingluke Shell Programming and Scripting 2 01-23-2008 09:57 AM
executing a SQL query in shell script lijju.mathew Shell Programming and Scripting 1 05-17-2007 08:29 AM
Executing Sql Query Using Shell Script ragha81 Shell Programming and Scripting 14 07-31-2006 11:15 AM
Executing a SQL query from a shell script 98_1LE UNIX for Dummies Questions & Answers 3 03-22-2002 11:29 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
Question Need Unix script for executing oracle query

Hi All,
This is Ravi. I am new in Unix platform. I need unix script for executing oracle query.
Requirement:-
1. We had 2 tables 1 is source table 2 is target table.

Example:- Ravi1(Source Table) 100000 records
Ravi2(Target Table) 50000 records
Fallouts 50000
I was successfully got this result in in sqlplus.

But now i want to run this script in unix mechine. While executing this script in unix the fallouts should automatically it will store in fallouts table(Major issue for me).

So i don't know how to execute this query so i would appreciate if any one send that unix AWK script to me.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
Code:

#!/bin/bash
sqlplus -s /nolog << EOF

CONNECT $DB_USER/$DB_PASSWORD

Your sql query here
................
.............

end;
/
EOF
Reply With Quote
  #3 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Location: MUMBAI, INDIA
Posts: 25
Execute SQL Query from Unix.

Hi Ravi,

You can execute any SQL Statement from HERE..

##############################################

sqlplus -l USERNAME/PASSWORD@DB_SCHEMA <<EOF
insert into ODS_T_CFS_DUMP(FILE_NAME, REGION_ID, SDP_ID, SEQUENCE_ID, TOTAL_RECORDS) values ('$file','$region_id','$sdp_id','$sequence_id', '$cos_records');

Select 1 from dual;
select "Hello Ravi" from dual;
EXIT
EOF

###############################################
Reply With Quote
  #4 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
Question Thanks thana

I will explain my total requirement:-
We are developed script in PL/SQL. In the PL/SQL script i was got the fallout report(no. of rows records not extracted well).

Now client he was asking us like we want to execute the script in unix mechine. He was asking like while executing the PL/SQL script in unix the fallouts should be automatically store in Fallout table.Is it possible.

give me your mail id i will send my PL/SQL that will easy for both to understand.



Quote:
Originally Posted by thana View Post
Code:

#!/bin/bash
sqlplus -s /nolog << EOF

CONNECT $DB_USER/$DB_PASSWORD

Your sql query here
................
.............

end;
/
EOF
Reply With Quote
  #5 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
Question Thanks hanu

I will explain my total requirement:-
We are developed script in PL/SQL. In the PL/SQL script i was got the fallout report(no. of rows records not extracted well).

Now client he was asking us like we want to execute the script in unix mechine. He was asking like while executing the PL/SQL script in unix the fallouts should be automatically store in Fallout table.Is it possible.

give me your mail id i will send my PL/SQL that will easy for both to understand.


Quote:
Originally Posted by hanu_oracle View Post
Hi Ravi,

You can execute any SQL Statement from HERE..

##############################################

sqlplus -l USERNAME/PASSWORD@DB_SCHEMA <<EOF
insert into ODS_T_CFS_DUMP(FILE_NAME, REGION_ID, SDP_ID, SEQUENCE_ID, TOTAL_RECORDS) values ('$file','$region_id','$sdp_id','$sequence_id', '$cos_records');

Select 1 from dual;
select "Hello Ravi" from dual;
EXIT
EOF

###############################################
Reply With Quote
  #6 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
Exclamation Need Unix script for executing oracle query

DECLARE CURSOR np IS
SELECT * FROM np_classes;

total_rows_np NUMBER;

CURSOR idb IS
SELECT * FROM dl_class;

total_rows_idb NUMBER;

expFallouts NUMBER;

BEGIN
FOR x IN np LOOP
total_rows_np := np% ROWCOUNT ;
END LOOP;

FOR y IN idb LOOP
total_rows_idb := idb% ROWCOUNT;
END LOOP;

IF total_rows_np > 0 AND total_rows_idb >0 THEN

expFallouts := total_rows_np - total_rows_idb;
dbms_Output.new_line;
dbms_output.put_line('DL_ CLASS');
dbms_Output.new_line;
dbms_output.put_line('total rows np :' ||To_Char(total_rows_np ));
dbms_output.put_line('total rows idb :' ||To_Char(total_rows_idb));
dbms_output.put_line('Expected Fallouts :' ||To_Char(expFallouts));
Dbms_Output.new_line;
ELSE
Dbms_Output.new_line;
dbms_output.put_line('DB Empty');
END IF;
END;


This is a Snippet code so please give idea how i want to execute this query in unix mechine.


Quote:
Originally Posted by thana View Post
Code:

#!/bin/bash
sqlplus -s /nolog << EOF

CONNECT $DB_USER/$DB_PASSWORD

Your sql query here
................
.............

end;
/
EOF
Reply With Quote
  #7 (permalink)  
Old 03-21-2008
Registered User
 

Join Date: Mar 2008
Posts: 15
Exclamation Need Unix script for executing oracle query

DECLARE CURSOR np IS
SELECT * FROM np_classes;

total_rows_np NUMBER;

CURSOR idb IS
SELECT * FROM dl_class;

total_rows_idb NUMBER;

expFallouts NUMBER;

BEGIN
FOR x IN np LOOP
total_rows_np := np% ROWCOUNT ;
END LOOP;

FOR y IN idb LOOP
total_rows_idb := idb% ROWCOUNT;
END LOOP;

IF total_rows_np > 0 AND total_rows_idb >0 THEN

expFallouts := total_rows_np - total_rows_idb;
dbms_Output.new_line;
dbms_output.put_line('DL_ CLASS');
dbms_Output.new_line;
dbms_output.put_line('total rows np :' ||To_Char(total_rows_np ));
dbms_output.put_line('total rows idb :' ||To_Char(total_rows_idb));
dbms_output.put_line('Expected Fallouts :' ||To_Char(expFallouts));
Dbms_Output.new_line;
ELSE
Dbms_Output.new_line;
dbms_output.put_line('DB Empty');
END IF;
END;


Please check this query and tell me how i want to execute this code in unix mechine.

Quote:
Originally Posted by hanu_oracle View Post
Hi Ravi,

You can execute any SQL Statement from HERE..

##############################################

sqlplus -l USERNAME/PASSWORD@DB_SCHEMA <<EOF
insert into ODS_T_CFS_DUMP(FILE_NAME, REGION_ID, SDP_ID, SEQUENCE_ID, TOTAL_RECORDS) values ('$file','$region_id','$sdp_id','$sequence_id', '$cos_records');

Select 1 from dual;
select "Hello Ravi" from dual;
EXIT
EOF

###############################################
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0