Storing oracle query results into bash variable The Next CEO of Stack OverflowGet the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?Extract filename and extension in BashLooping through the content of a file in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashEcho newline in Bash prints literal nLoop through an array of strings in Bash?
Raspberry pi 3 B with Ubuntu 18.04 server arm64: what pi version
Can a PhD from a non-TU9 German university become a professor in a TU9 university?
How to coordinate airplane tickets?
What steps are necessary to read a Modern SSD in Medieval Europe?
How to pronounce fünf in 45
How to show a landlord what we have in savings?
pgfplots: How to draw a tangent graph below two others?
Is it reasonable to ask other researchers to send me their previous grant applications?
Is the offspring between a demon and a celestial possible? If so what is it called and is it in a book somewhere?
Early programmable calculators with RS-232
Is it possible to create a QR code using text?
Mathematica command that allows it to read my intentions
Which acid/base does a strong base/acid react when added to a buffer solution?
How to find if SQL server backup is encrypted with TDE without restoring the backup
How can a day be of 24 hours?
What is the difference between 'contrib' and 'non-free' packages repositories?
How do I secure a TV wall mount?
Read/write a pipe-delimited file line by line with some simple text manipulation
Could you use a laser beam as a modulated carrier wave for radio signal?
What did the word "leisure" mean in late 18th Century usage?
Ising model simulation
Does int main() need a declaration on C++?
Is there a rule of thumb for determining the amount one should accept for a settlement offer?
Free fall ellipse or parabola?
Storing oracle query results into bash variable
The Next CEO of Stack OverflowGet the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?Extract filename and extension in BashLooping through the content of a file in BashHow to check if a variable is set in Bash?How to concatenate string variables in BashEcho newline in Bash prints literal nLoop through an array of strings in Bash?
declare -a result=`$ORACLE_HOME/bin/sqlplus -silent $DBUSER/$DBPASSWORD@$DB << EOF $SQLPLUSOPTIONS $roam_query exit; EOF`
I am trying to pull data from an oracle database and populate a bash variable. The select query works however it returns multiple rows and those rows are returned as a long continuous string. I want to capture each row from the database in an array index for example:
index[0] = row 1 information
index[1] = row 2 information
Please help. All suggestions are appreciated. I checked all documentation without no luck. Thank you. I am using solaris unix
linux bash oracle unix solaris
add a comment |
declare -a result=`$ORACLE_HOME/bin/sqlplus -silent $DBUSER/$DBPASSWORD@$DB << EOF $SQLPLUSOPTIONS $roam_query exit; EOF`
I am trying to pull data from an oracle database and populate a bash variable. The select query works however it returns multiple rows and those rows are returned as a long continuous string. I want to capture each row from the database in an array index for example:
index[0] = row 1 information
index[1] = row 2 information
Please help. All suggestions are appreciated. I checked all documentation without no luck. Thank you. I am using solaris unix
linux bash oracle unix solaris
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
You are assigning the entire result to the first element of the array. A first pass at doing what you want would bedeclare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.
– chepner
Mar 8 at 18:33
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35
add a comment |
declare -a result=`$ORACLE_HOME/bin/sqlplus -silent $DBUSER/$DBPASSWORD@$DB << EOF $SQLPLUSOPTIONS $roam_query exit; EOF`
I am trying to pull data from an oracle database and populate a bash variable. The select query works however it returns multiple rows and those rows are returned as a long continuous string. I want to capture each row from the database in an array index for example:
index[0] = row 1 information
index[1] = row 2 information
Please help. All suggestions are appreciated. I checked all documentation without no luck. Thank you. I am using solaris unix
linux bash oracle unix solaris
declare -a result=`$ORACLE_HOME/bin/sqlplus -silent $DBUSER/$DBPASSWORD@$DB << EOF $SQLPLUSOPTIONS $roam_query exit; EOF`
I am trying to pull data from an oracle database and populate a bash variable. The select query works however it returns multiple rows and those rows are returned as a long continuous string. I want to capture each row from the database in an array index for example:
index[0] = row 1 information
index[1] = row 2 information
Please help. All suggestions are appreciated. I checked all documentation without no luck. Thank you. I am using solaris unix
linux bash oracle unix solaris
linux bash oracle unix solaris
edited Mar 8 at 18:33
that other guy
74.9k886124
74.9k886124
asked Mar 8 at 18:25
Kevoy WaltersKevoy Walters
206
206
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
You are assigning the entire result to the first element of the array. A first pass at doing what you want would bedeclare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.
– chepner
Mar 8 at 18:33
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35
add a comment |
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
You are assigning the entire result to the first element of the array. A first pass at doing what you want would bedeclare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.
– chepner
Mar 8 at 18:33
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
You are assigning the entire result to the first element of the array. A first pass at doing what you want would be
declare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.– chepner
Mar 8 at 18:33
You are assigning the entire result to the first element of the array. A first pass at doing what you want would be
declare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.– chepner
Mar 8 at 18:33
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35
add a comment |
1 Answer
1
active
oldest
votes
If you have bash version 4, you can use the readarray -t
command to do this. Any vaguely recent linux should have bash v4, but I don't know about Solaris.
BTW, I'd also recommend putting double-quotes around variable references (e.g. "$DBUSER/$DBPASSWORD@$DB"
instead of just $DBUSER/$DBPASSWORD@$DB
) (except in here-documents), using $( )
instead of backticks, and using lower- or mixed-case variable names (there are a bunch of all-caps names with special meanings, and if you use one of those by accident, weird things can happen).
I'm not sure I have the here-document (the SQL commands) right, but here's roughly how I'd do it:
readarray -t result < <("$oracle_home/bin/sqlplus" -silent "$dbuser/$dbpassword@$db" << EOF
$sqlplusoptions $roam_query
exit;
EOF
)
add a comment |
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068957%2fstoring-oracle-query-results-into-bash-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have bash version 4, you can use the readarray -t
command to do this. Any vaguely recent linux should have bash v4, but I don't know about Solaris.
BTW, I'd also recommend putting double-quotes around variable references (e.g. "$DBUSER/$DBPASSWORD@$DB"
instead of just $DBUSER/$DBPASSWORD@$DB
) (except in here-documents), using $( )
instead of backticks, and using lower- or mixed-case variable names (there are a bunch of all-caps names with special meanings, and if you use one of those by accident, weird things can happen).
I'm not sure I have the here-document (the SQL commands) right, but here's roughly how I'd do it:
readarray -t result < <("$oracle_home/bin/sqlplus" -silent "$dbuser/$dbpassword@$db" << EOF
$sqlplusoptions $roam_query
exit;
EOF
)
add a comment |
If you have bash version 4, you can use the readarray -t
command to do this. Any vaguely recent linux should have bash v4, but I don't know about Solaris.
BTW, I'd also recommend putting double-quotes around variable references (e.g. "$DBUSER/$DBPASSWORD@$DB"
instead of just $DBUSER/$DBPASSWORD@$DB
) (except in here-documents), using $( )
instead of backticks, and using lower- or mixed-case variable names (there are a bunch of all-caps names with special meanings, and if you use one of those by accident, weird things can happen).
I'm not sure I have the here-document (the SQL commands) right, but here's roughly how I'd do it:
readarray -t result < <("$oracle_home/bin/sqlplus" -silent "$dbuser/$dbpassword@$db" << EOF
$sqlplusoptions $roam_query
exit;
EOF
)
add a comment |
If you have bash version 4, you can use the readarray -t
command to do this. Any vaguely recent linux should have bash v4, but I don't know about Solaris.
BTW, I'd also recommend putting double-quotes around variable references (e.g. "$DBUSER/$DBPASSWORD@$DB"
instead of just $DBUSER/$DBPASSWORD@$DB
) (except in here-documents), using $( )
instead of backticks, and using lower- or mixed-case variable names (there are a bunch of all-caps names with special meanings, and if you use one of those by accident, weird things can happen).
I'm not sure I have the here-document (the SQL commands) right, but here's roughly how I'd do it:
readarray -t result < <("$oracle_home/bin/sqlplus" -silent "$dbuser/$dbpassword@$db" << EOF
$sqlplusoptions $roam_query
exit;
EOF
)
If you have bash version 4, you can use the readarray -t
command to do this. Any vaguely recent linux should have bash v4, but I don't know about Solaris.
BTW, I'd also recommend putting double-quotes around variable references (e.g. "$DBUSER/$DBPASSWORD@$DB"
instead of just $DBUSER/$DBPASSWORD@$DB
) (except in here-documents), using $( )
instead of backticks, and using lower- or mixed-case variable names (there are a bunch of all-caps names with special meanings, and if you use one of those by accident, weird things can happen).
I'm not sure I have the here-document (the SQL commands) right, but here's roughly how I'd do it:
readarray -t result < <("$oracle_home/bin/sqlplus" -silent "$dbuser/$dbpassword@$db" << EOF
$sqlplusoptions $roam_query
exit;
EOF
)
answered Mar 8 at 19:46
Gordon DavissonGordon Davisson
71k97894
71k97894
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55068957%2fstoring-oracle-query-results-into-bash-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Stack overflow was not allowing me to enter the `` but I know they are supposed to be there so that is not the issue.
– Kevoy Walters
Mar 8 at 18:26
You are assigning the entire result to the first element of the array. A first pass at doing what you want would be
declare -a results=( $($ORACLE_HOME/bin/sqlplus ...) )
.– chepner
Mar 8 at 18:33
That has its own risks, though, as it subjects the result to word-splitting and pathname expansion. (Most importantly, you'll probably end up with one array entry per field per row, not just one entry per row.)
– chepner
Mar 8 at 18:35