Unix and SQLPlus shell scripts [message #249267] |
Tue, 03 July 2007 19:57 |
Danielle3
Messages: 7 Registered: July 2007
|
Junior Member |
|
|
I know that there are many threads on this subject to begin with, however I still can't seem to figure this out even after scouring the internet for answers. I would appreciate it if someone could assist me with my specific script, thanks ahead of time for your patience...
Okay, I have a Unix (Sun Solaris 10) script that needs to query one of my Oracle tables for a value and then use those results in other commands elsewhere in the same script. Most of the examples that I have seen using SQLPlus use "HERE" files to extract data, however I continue to get an error while trying to embed a "HERE" file within my parent script. I will post it here, hopefully it will help.
<snipped>
#Oracle variables
oracleUID='DW'
oraclePass='password'
#Call SqlPlus to get vaulues from Oracle using a here file then populate the variables
#(finaldestinationfolder reportperfdest passphrase, ...)
sqlplus -s oracleUID/oraclePass@noah << !EOSQL | \
awk -F: '{printf("%s ", $1); printf("%s ", $2 ); printf("%s ", $3 )}' | \
read finaldestinationfolder reportperfdest passphrase
WHENEVER SQLERROR exit 5
set define on
set heading off
set pagesize 0
set feedback off
set echo off
column passphrase format a90
set linesize 100
SELECT CASE RDP.REPORT_DESTINATION
WHEN 'MC' THEN RDP.MEMBERCONNECT_FOLDER
WHEN 'SF' THEN RDP.SAFELINK_FOLDER
ELSE 'UNKNOWN' END ||
':'||RDP.REPORT_DESTINATION||':'||CP.PASSPHRASE
FROM SACORP.MCI, DW.CLIENT_PASSPHRASE CP, DW_REF.EI_REPORT_DEST_PREF RDP
WHERE MCI.PSC_ID = RDP.PSC_ID
AND RDP.PSC_ID(+) = CP.PSC_ID
AND CP.EFFECTIVE_DATE = TRUNC(SYSDATE, 'MM')
AND MCI.CLIENT_ID = $clientid;
exit 0
!EOSQL
#End of here file and call into Oracle
<snipped>
Any advice would be great!
Thanks in advance,
Danielle
[Updated on: Wed, 04 July 2007 01:20] by Moderator Report message to a moderator
|
|
|
|
|
Re: Unix and SQLPlus shell scripts [message #249279 is a reply to message #249267] |
Tue, 03 July 2007 21:58 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
>How would I use Perl to accomplish this task?
By not having to resort to HERE script, by being able to directly invoking SQL statement via DBI/DBD.
The errors you post contain lines NUMBERS, but posted code does not show any.
What you don't realize is the the termination string "!EOSQL" MUST exist without intervening white space. It MUST the 1st characters on the line; leftmost.
sqlplus << EOF
/ as sysdba
set term on echo on
select 'This works' from dual;
exit
EOF
+ sqlplus
SQL*Plus: Release 10.2.0.2.0 - Production on Tue Jul 3 19:56:54 2007
Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
Enter user-name:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> SQL>
'THISWORKS
----------
This works
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
[Updated on: Tue, 03 July 2007 21:59] by Moderator Report message to a moderator
|
|
|
|
Re: Unix and SQLPlus shell scripts [message #249286 is a reply to message #249267] |
Tue, 03 July 2007 23:29 |
Danielle3
Messages: 7 Registered: July 2007
|
Junior Member |
|
|
I am now getting the following error, though if I try to login to SQLPlus without using a script it works just fine... Any thoughts?
invalid username/password; logon denied
ERROR ORA-12162 TNS net service name is incorrectly specified
SP2-0306 Invalid option.
Usage CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> = <username>[/<password>][@<connect_identifier>] | /
SP2-0157 unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[Updated on: Wed, 04 July 2007 01:19] by Moderator Report message to a moderator
|
|
|
|
|
|