If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > PLsql cursor not opening when called in script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-30-11, 09:10
Dharv Dharv is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
PLsql cursor not opening when called in script

Hi All,

I have a part of script as below

temp=`sqlplus -s $1 << EOF
set feedback off verify off heading off pagesize 0 linesize 100
SELECT xx_pkg.xx_fuc
FROM dual;
exit;
EOF`

My cursor will update a table based on cursor fetched records, and return no of rows updated.
Now my function is getting called and all operation are done except the cursor for loop. When i executed this (select xx_pkg....) in sql promt it is working as expected. My package is in abc schema and i am connecting to the same scema in unix.
Please help. Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 01-01-12, 09:18
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
I am not sure that you can extend the back tick operator over multiple lines.
Try this way, by putting the sql statements into a file.
Code:
#select.sql
set feedback off verify off heading off pagesize 0 linesize 100
SELECT xx_pkg.xx_fuc
FROM dual;
exit;
Then use
Code:
temp=`sqlplus $1 < select.sql`
Reply With Quote
  #3 (permalink)  
Old 01-03-12, 14:07
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Quote:
Originally Posted by kitaman View Post
I am not sure that you can extend the back tick operator over multiple lines.
Yes you can extend the back tick over several lines.

Quote:
Originally Posted by Dharv View Post
... Etc ...
Now my function is getting called and all operation are done except the cursor for loop.
... Etc ...
Please help. Thanks in advance
We cannot help on what we cannot see! We don't know what code are you refering to as "cursor for loop".
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 01-03-12, 14:47
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Quote:
Yes you can extend the back tick over several lines.
I ain't never tried that in 25 years, cuz its bad form.
Reply With Quote
  #5 (permalink)  
Old 01-03-12, 15:45
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Check it out:
Code:
==> cat m0
ORACLE_SID=orcl
ORAENV_ASK=NO
. /usr/local/bin/oraenv
temp=`sqlplus -s / << EOF
set feedback off verify off heading off pagesize 0 linesize 100
SELECT 'Calling xx_pkg.xx_fuc at '||systimestamp
FROM dual;
exit;
EOF`

echo $temp

==> ./m0
Calling xx_pkg.xx_fuc at 03-JAN-12 03.44.28.327677 PM -05:00
==>
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #6 (permalink)  
Old 01-03-12, 16:40
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Why do you need the backtick if the only use of the temp variable is to echo it?
m0 could be simplified to
Code:
ORACLE_SID=orcl
ORAENV_ASK=NO
. /usr/local/bin/oraenv
sqlplus -s / << EOF
set feedback off verify off heading off pagesize 0 linesize 100
SELECT 'Calling xx_pkg.xx_fuc at '||systimestamp
FROM dual;
exit;
EOF
or
Code:
ORACLE_SID=orcl
ORAENV_ASK=NO
. /usr/local/bin/oraenv
temp=`sqlplus -s / << EOF >/tmp/output
set feedback off verify off heading off pagesize 0 linesize 100
SELECT 'Calling xx_pkg.xx_fuc at '||systimestamp
FROM dual;
exit;
EOF

cat /tmp/output
If you need to save the output or separate it from other processes within the same procedure.
Reply With Quote
  #7 (permalink)  
Old 01-03-12, 16:49
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Thumbs down

Quote:
Originally Posted by kitaman View Post
Why do you need the backtick if the only use of the temp variable is to echo it?
I posted an EXAMPLE script for the OP to demonstrate that backtick's can span several lines...
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #8 (permalink)  
Old 01-03-12, 16:59
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
I wasn't trying to be smart, I had seen that technique used in several other threads, and wondered why.
Reply With Quote
  #9 (permalink)  
Old 01-04-12, 10:24
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Quote:
Originally Posted by kitaman View Post
I wasn't trying to be smart, I had seen that technique used in several other threads, and wondered why.
Mainly because of the "<<EOF" thing, it allows sql commands to start at beginning of the line -- and -- you get the results in a variable that can be more easily analyzed.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Last edited by LKBrwn_DBA; 01-04-12 at 10:27.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On