2

For Oracle DB and HP-UX : I have a variable name SQL file like: my_sql_file_${TIMESTAMP}.sql

I assign this file to a variable: MYSQLFILE="my_sql_file_${TIMESTAMP}.sql"

So, I am trying to execute the MYSQLFILE inside SQL Plus, like:

@${MYSQLFILE}

but this appears that it cannot be done. Is there any way to achieve the above??

Thank you.

1
  • Can you edit your question to show how you're calling SQL*Plus and using the variable in context? Changing sensitive data of course (username/password/etc.) but otherwise leaving it exactly as you run it? Commented Jan 22, 2019 at 16:20

2 Answers 2

2

This should work:

MYSQLFILE="my_sql_file_${TIMESTAMP}.sql"

sqlplus -S user/password@db << EOF
@$MYSQLFILE
exit;
EOF

You can also pass user, password and db as parameters to your script

Sign up to request clarification or add additional context in comments.

9 Comments

Unfortunately, I have already tried that and does not work... :( I get response: SP2-3010: unable to open file "$MYSQLFILE".
@Kostas75 - are you doing it exactly like this, or are you perhaps quoting the heredoc marker - i.e. << "EOF" ?
I am doing exactly like this (with the EOF) and does not work, tried several times. Only the 1 line command works (with no EOF).
@Kostas75 Which shell are you using?
@vc 74: #!/bin/sh (inside shell script) at HP-UX.
|
2

you can use

sqlplus user/pass@service_name @$MYSQLFILE

inside SQLPLUS, you can also use

sql> host echo $MYSQLFILE

And this is also valid,

sqlplus user/password@db <<EOF
  @$MYSQLFILE
  exit;
EOF

6 Comments

The 1-line command works fine: sqlplus user/pass@service_name @$MYSQLFILE. The EOF is exactly what I have tried to do when I opened this questions here and does NOT work, at least not at my environment.
Glad that you solved your problem. If you believe that this answer is useful for you please consider to upvote and/or mark it as answer so that community can also benefit from it :) thank you
Problem solved with different approach, question was not answered exactly, but OK.
If there is another approach can you please share your practice with us? besides I am not meaning check my post as an answer, but if you think any of them relevant to your problem you should mark it as answer. This is how community works and This is how we share out know how
OK, basically I used the 1-line sqlplus call, but also had to include the sets, commit and quit at the SQL file, because everything should be done from within the SQL file, since I could not use the EOF (it does not work at my system).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.