0

For example, in the beggining of script I get the input from user:

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

ok, at the end I want to leave some message like it:

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATHtmp_script.sql to execute the generated script.
prompt

But the sqlplus don't undestand I am trying to concatenate &PATH with tmp_script.sql. I've tried the scape \, but don't work on prompt command.

3 Answers 3

1

Isn't that two ampersands?

SQL> prompt "Type path"
"Type path"
SQL> spool '&&PATH\test.sql'
Enter value for path: c:\temp
SQL> select * from dept;

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

SQL> prompt End of commands
End of commands
SQL> prompt Execute :: &&PATH\test.sql to execute ...
Execute :: c:\temp\test.sql to execute ...                        --> here's te result
SQL>
Sign up to request clarification or add additional context in comments.

3 Comments

If I use \ it works, but the result is for example (linux): /home/oracle/\tmp_script.sql. the \ still there. As Windows use \ instead of /, it seems ok, but in linux it get wrong. I've tested the && and same problem.
Sorry, I don't have (nor know Linux) so I can't comment it.
A double ampersand prefix means remember the value and don't reprompt. Try select &n + &n from dual; vs select &&n + &&n from dual;
1

Substitution variables can be terminated with a dot.

SQL> define PATH = u:\whatever
SQL> prompt File is saved to &PATH.\somefile.log

gives

File is saved to u:\whatever\somefile.log

Comments

0

I've found the solution. Actually, I was almost there, need to use \, but before we need to use set escape on command to make \ as escape, You can check here

SET ESCAPE on

Prompt "Type the path where the script will be saved: "
spool '&&PATH\tmp_script.sql'

Prompt
prompt End of commands.
prompt
prompt Execute: @&PATH\tmp_script.sql to execute the generated script.
prompt

Comments

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.