sql - how to use a variable in oracle script for the table name -
I have a pl \ sql script, where I want to set the table name used in the script in a variable Am So, some examples that I found on the web, I wrote the code below, the first section works, so I think my normal syntax is correct, but the second segment, where I try to use a variable for the table name I am the errors (" SQL error: ORA-00903: invalid table name ").
Nobody knows what I'm doing wrong ... I do not have too many PL SQLs, so maybe I'm just missing something clearly.
- Variable numOfrecords numbers work; Exec: numOfrecords: = 10; Choose 2008 from customers * Choose where rownum & lt; : NumOfrecords; - Work table nm CHAR does not work; Exec: tableNm: = 'customers2008'; Print table nm; Choose * from: tableNm; If you are running this script from sqlplus (which appears in the case), then
You want to use the DEFINE command, which allows you to create SQLLS substation variables which are just string string replacements, like:
define tableNm = 'customers2008' Amp; TableNm;
For more information about how this is used, see You can pass values to your script from the command line using predefined positional replacement variables, such as:
define tableNm = & amp; 1 Select & amp; ;; TableNm;
... and then open sqlplus like this:
sqlplus user / pwd @ server @ myscript.sql customers2008
If you do not give a value on the command line, then the script inviteor will be prompted for the price.
See Dave Costa's answer below for the difference between the bind and the replacement variable.
Comments
Post a Comment