Reputation: 1064
I was wondering if it was possible to provide values for variables in an SQL script that accepts user input. This is a small part of a larger assignment (one question involves writing a script which has to invoke another script, which in turn requires user input). I cannot alter the script that requires user input.
For simplicity's sake, assume I have the following in foo.sql
:
ACCEPT TABLENAME CHAR PROMPT 'Enter Table: '
SELECT * FROM &TABLENAME;
Once I am already logged into SQL*Plus, is there a way for me to execute foo.sql
and redirect input in a way similar to Bash? In an ideal world, I would be able to do this as follows:
@foo < "SOMETABLE"
Unfortunately, that doesn't work. Is there any way to accomplish this?
Upvotes: 1
Views: 2309
Reputation: 7928
you can redirect input from a file to the sqlplus
command itself, before you login:
> sqlplus user/pwd@db @foo < input_file
Upvotes: 2