LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 02:15 PM   #1
dc.901
Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 997

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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 02:26 PM.
 
Old 01-10-2023, 03:22 PM   #2
dc.901
Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 997

Original Poster
Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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 04:35 PM.
 
Old 01-11-2023, 05:37 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,968

Rep: Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177Reputation: 3177
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, 09:27 AM   #4
dc.901
Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 997

Original Poster
Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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 11:22 PM
SQL: old sql dump not loading into new db BrianK Linux - Software 1 07-26-2006 12:55 AM
Migrating from MS-SQL server to My-SQL emailssent Linux - Networking 2 02-07-2005 03:20 PM
Which SQL is suitable for EMbedded SQL on C? hk_michael Programming 4 01-10-2005 06:07 PM
My SQL and M$SQL ikw38 Linux - Software 2 07-03-2003 02:45 PM

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

All times are GMT -5. The time now is 09:59 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