Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Sqlplus variable UNIX

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-10-2017   -   Original Discussion by Francesco_IT
Francesco_IT Francesco_IT is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 20 October 2017, 7:05 AM EDT
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Sqlplus variable UNIX

hi guys
i have a sqlplus :


Code:
sqlplus -s  username/password << EOF
@mysql.sql
EOF

in mysql.sql there is a count of a table, i want to write in a variabile unix.
how can i do?
Thanks a lot
Regards
Francesco.
Sponsored Links
    #2  
Old Unix and Linux 10-10-2017   -   Original Discussion by Francesco_IT
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 18 November 2017, 7:33 PM EST
Location: Zürich
Posts: 8,821
Thanks: 366
Thanked 1,196 Times in 1,022 Posts
You could try:

Code:
somevar=$(sqlplus ...
EOF)

You'll need some directives in your SQL to throw away everything in the output except the value you're looking for.

SQL is / was a bit funny with file descriptors if I remember, and it's been a while since I've used it, so can't guarantee that will work.
Sponsored Links
    #3  
Old Unix and Linux 10-10-2017   -   Original Discussion by Francesco_IT
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 17 November 2017, 12:53 PM EST
Location: Lancashire, UK
Posts: 3,365
Thanks: 1,453
Thanked 665 Times in 598 Posts
Could i suggest that you get your credentials moved too?

Something more like:-

Code:
somevar=$(sqlplus <<EOSQL
username/password
@my.sql
EOSQL)

This will, of course, take ALL the output fromt he sqlplus command, so you might need to think about that. Perhaps add the -s flag to suppress much of the informational output might help you there.



Robin
    #4  
Old Unix and Linux 10-10-2017   -   Original Discussion by Francesco_IT
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 17 November 2017, 10:54 AM EST
Posts: 462
Thanks: 4
Thanked 101 Times in 93 Posts
For a task like that the file descriptors shouldn't be a problem.
I do not see why a heredoc is needed, sqlplus can process a sql-commandfile if told so:

Code:
$ a=$(sqlplus -s /nolog @a.sql)
$ echo "$a"

10-OCT-17
$ cat a.sql
set heading off
connect / as sysdba;
select sysdate from dual;
exit

Using bash on Debian 9, Oracle XE.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print huge values in sqlplus variable in UNIX? bhaski2012 Shell Programming and Scripting 6 06-28-2013 04:23 PM
Passing the unix variable to sqlplus Anaramkris Shell Programming and Scripting 5 09-04-2008 04:25 PM
select count(*) in sqlplus into variable unix shell struggle UNIX for Dummies Questions & Answers 2 03-27-2008 12:12 AM
passing unix variable to sqlplus without a file name sakthi.abdullah UNIX for Advanced & Expert Users 3 12-12-2006 06:35 AM
How to pass unix variable to SQLPLUS chiru UNIX for Advanced & Expert Users 1 06-10-2006 03:11 AM



All times are GMT -4. The time now is 01:02 AM.