LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-10-2023, 01:15 PM   #1
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
loops with SQL (oracle)


Hey folks,
I need some guidance on loops with SQL (in Oracle more specifically).
In bash, this works:
Code:
while read a
do
echo $a
done < filename
So, trying to do something similar with SQL:
Code:
while read a
do
sqlplus user/password@"$a" 
"show pdbs;"
done < filename
But it does not seem to work. No errors either.

For troubleshooting, I tried "echo" as follows and it looks correct.

So, trying to do something similar with SQL:
Code:
while read a
do
echo sqlplus user/password@"$a" 
done < filename
And, above loop with echo shows sqlplus entry correctly, so am bit puzzled with this.
What am I missing?

Last edited by dc.901; 01-10-2023 at 01:26 PM.
 
Old 01-10-2023, 02:22 PM   #2
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Original Poster
Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Nevermind, figured things out; here's what worked for me if someone else come along looking for similar solution (or can point me to a better solution)

Code:
while read a
do
echo $a
sqlplus user/password@"$a" << EOF
show pdbs;
EOF
done < filename

Last edited by dc.901; 01-10-2023 at 03:35 PM.
 
Old 01-11-2023, 04:37 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
To answer your original question, the "show pdbs;" is being read by bash as it is not being passed to sqlplus.

If you are doing a simple short one liner, you could also use a herestring instead of a heredoc:
Code:
sqlplus user@"$a" <<<"show pdbs;"
 
1 members found this post helpful.
Old 01-13-2023, 08:27 AM   #4
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Original Poster
Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by grail View Post
To answer your original question, the "show pdbs;" is being read by bash as it is not being passed to sqlplus.

If you are doing a simple short one liner, you could also use a herestring instead of a heredoc:
Code:
sqlplus user@"$a" <<<"show pdbs;"
Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is unrolled loops and how to check and know unrolled loops of cpu in ubuntu zerop Linux - Kernel 4 07-31-2014 10:22 PM
SQL: old sql dump not loading into new db BrianK Linux - Software 1 07-25-2006 11:55 PM
Migrating from MS-SQL server to My-SQL emailssent Linux - Networking 2 02-07-2005 02:20 PM
Which SQL is suitable for EMbedded SQL on C? hk_michael Programming 4 01-10-2005 05:07 PM
My SQL and M$SQL ikw38 Linux - Software 2 07-03-2003 01:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration