I have a problem with insertion scripts in SQL PLUS.In my insert scripts data contains '&' like this 'Rat&CAT'.When am run my script file using SQL PLUS Batch file .It is always promting this message "Enter the Value of CAT:".Could any one tell me how to solve this problem?
Add this command at the start of your script:
SET DEFINE OFF;
It will turn off variable substitution.
Related
I need to deploy database objects by calling a script. But it throws an error like this "PLS-00103: Encountered the symbol "PROMPT" ".
What could be the problem with my script?
My script is as follows:
set echo on
spool logs/dm_ref.log
Prompt Running dw/deploy/dm_ref/file.sql...
#dw/deploy/dm_ref/file.sql
Prompt Running dw/deploy/dm_ref/file_tbl.sql...
#dw/deploy/dm_ref/file_tbl.sql
spool off
set echo off
the 2nd Prompt is for creating a table which successfully runs.
The problem is with the first Prompt for which it creates a stored procedure.
Thank's in advance.
The main issue is you're not giving us enough information to answer your question.
SQL Developer's script engine DOES support the PROMPT command.
Please amend your question to include the spooled output, the error message, and the contents of your .sql files you are executing.
I have a stored procedure in an Oracle database and I want to create a batch file that can call and run the said procedure. After running the stored procedure I want to call a certain sql file then run it also within just a single batch file.
name of stored procedure = health_check
name of SQL file = spool1.sql
I want to run the stored procedure first in the batch file. Upon success I want to call the said sql file then run it still at the same batch file.
I'm already able to execute the sql file. I just want to add the calling and running of the stored procedure in my current batch file
I want to achieve something like this:
#echo off
--run proc here
sqlplus user/password#DB #D:\mysqlfile.sql
Is this possible? Thanks in advance.
You could use a 'heredec' approach:
#echo off
#(
echo execute health_check
echo #D:\mysqlfile.sql
) | sqlplus -s -l user/password#DB
Untested but this pattern should work. Everythign in the parentheses is evaluated, which produces two lines of output:
execute health_check
#D:\mysqlfile.sql
and those are treated as input by SQL*Plus. So it's the equivalent of an interactive session where you start SQL*Plus and then enter those two lines in turn at the SQL> prompt. The #<file> can be used from that prompt too to run the file contents. And execute (or just exec) is a client shortcut for an anonymous PL/SQL block.
This assumes, based on how you did this in your question, that the .sql file ends with an exit. If it doesn't then you can add then to the heredoc with echo exit.
I am going through SQL*Plus script and came across set of lines that has below lines:
#test_data/EMPLOYEE.dat
#test_data/ADDRESS.dat
The .dat has some SQL code inside them. I tried to search in internet what the # symbole indicates but I did not get any results. I am new to SQL*Plus, please let me know what this symbol indicates.
This is about sql*plus scripting, we use this symbol to call scripts from external files.
# is used to call scripts from the external files
From the Oracle docs:
Runs the SQL*Plus statements in the specified script. The script can
be called from the local file system or from a web server. The #
command functions similarly to ## and START.
It is used to run the scripts from another file. eg:
SQL> #PreImport.sql
A shell script with a database connection using sqlplus contains this line:
sqlplus username/password#DBNAME<<EOF>tmp.
(here there is a select sql query)
I know <<EOF indicates the start of the command. I have the below doubts in the >tmp part.
1)Does it indicate storing into a file?
2) If yes will it put the results of the SQL query alone into the tmp file or the query and the results both.
Could you please clear me on this one?
<<EOF is known as "heredocs". It means that from the next line in the script, up to a line that says "EOF", will be read in by the shell, and offered to the command on standard input.
In your case, the sqlplus command is being fed the SQL query as if it came from standard input. Then, the output of sqlplus is being saved to the file called tmp.
The input and output are separate. However, sqlplus as a command has a habit of repeating its input to the output, unless instructed otherwise with SET ECHO OFF.
I have written the sql by name cashload.txt on unix box and kept it on the following location on unix box:
exit |sqlplus -s batch/password#SW_TEST #/soft/checkfree/AccurateBXG/scripts/cashload.txt
In the cashload.txt the below code is written:
spool /Detail/reports/inner/SW/Rep_OIbyAccount_$DATE_FILE.csv
select accountnumber||','||accountname||','||X from HSBC_Cash_OIbyAccount_v;
spool off
But it is not spooling the result set on the above mentioned path.However,when I am giving the path where the script is kept,It is spooling at that location.I don't understand why?It is spooling at the below path where the cashload.txt(sql script) is kept:
**spool /soft/checkfree/AccurateNXG/scripts/Rep_OIbyAccount.csv**
select accountnumber||','||accountname||','||X from HSBC_Cash_OIbyAccount_v;
spool off
Please look into the above query and help me out.
Thanks in advance!!!
If I understand this correctly, DATE_FILE is a shell variable that you want to substitute into the spool file name. This might be part or all of your problem. I don't think you can reference this directly from SQLPlus. You would need to pass that in as a parameter to the script then reference it as a SQLPlus substitution variable.
So the command line would be:
sqlplus -s batch/password#SW_TEST #/soft/checkfree/AccurateBXG/scripts/cashload.txt $DATE_FILE
And the spool command in the script would be:
spool /Detail/reports/inner/SW/Rep_OIbyAccount_&1..csv
(The extra period is necessary because it serves as a terminator to the substition variable name.)
Almost certainly it is a file permissions problem. Remember that when we interact with the OS from inside the database we are using the oracle account, not the account we connected as.
So does the oracle account have write permissions on /Detail/reports/inner ?
Can you echo the value of "/Detail/reports/inner/SW/Rep_OIbyAccount_$DATE_FILE.csv" ?
Only reason I can think of are
a) The above location is not a valid path
b) You do not have permissions to write to that location.
Do you get an error in the first case, or does nothing happen at all ?
Does running without the silent (-s) option give you any more detail?
The path mentioned by you has a $ symbol which is causing the problem. To avoid that just give the path and file name in " ". That should solve the problem:
SPOOL "/Detail/reports/inner/SW/Rep_OIbyAccount_$DATE_FILE.csv "
Maybe you can try the following to see if it generats the desired output. It will put in the directory which you are currently in.
set termout off
set echo off
set linesize 140
set feedback off
set pagesize 0
spool DATE_FILE.csv
select accountnumber
||','
||accountname
||','
|| X
from HSBC_Cash_OIbyAccount_v;
spool off
ed DATE_FILE.csv