SQL script cshell - sql

I am doing this in my cshell script sqlplus $ORA_UID/$ORA_PSWD #${SQL}test.sql ${DATA}${ext1}thats trying to get output from test.sql script.. in my sql script i am dumping output to spool &1 .. but when i run my script my files are blank i am not getting anything from database.. can someone tell what wrong with this

normally it is not a good idea to have your userid and password displayed in the processlist, as is happening now. Most of the times when sql scripts don't produce the expected output it is because the end of SQL marker is missing. Default the end of SQL is the ';' Reading the end of SQL marker actually starts the SQL statement.
First try the script with feedback on and check the error message in the spoolfile.
Is the spoolfile location OK ?
sqlplus /nolog <<eof
connect $ORA_UID/$ORA_PSWD
#${SQL}test.sql ${DATA}${ext1}
eof
This construction prevents the display of the credentials on the processlist.
In the sqlscript could be
select * from dual;
or
select * from dual
/
but each and every SQL statement has to have an end of SQL marker.

Related

Non-english letters in sql script problem - Oracle Sql Developer

I'm executing some random script to my local database and I have problem with non-english letters. When I'm executing the same insert statement directly from sql develeoper everything is ok. Could somebody explain my how can I avoid this problem using sql script?
Example. Everything works okay.
Statement: insert into my_table values ('aaaaała');
Result: 'aaaaała';
Now I'm pasting the same insert statement into my sql file(script.sql) and I'm wirting:
#'D:\script.sql';
'D:\' - it is location of that file
Statement: insert into my_table values ('aaaaała');
Result: 'aaaaała';
The result is wrong:
My settings:
You must set your NLS_LANG value according to the character set of the script.sql file. Typically you set this in the options in at the "Save" dialog.
For example if the .sql file was saved as UTF-8 then you must run:
set NLS_LANG=.AL32UTF8
sqlplus .... #'D:\script.sql';
See also OdbcConnection returning Chinese Characters as "?" for more details.

sql query in shell script #xyz.sql

Can anyone please tell me the exact meaning/significance of #forecast2.sql in below query , the given query is a part of one shell script. Also how can I find the exact sql query executed by #forecast2.sql
Below is the code:
sqlplus -s / #forecast2.sql $SCHED_ID > /tmp/BR_forecast
I need to find the sql query that's been executed here.
This means that sqlplus will execute script called forecast2.sql.
You could locate it:
> env | grep SQLPATH
-- path where scripts are located

How to display the result of SQL query in unix server (putty)?

Suppose I want to display the result of a simple SQL query, say SELECT * FROM dual; that is executed in SQL developer and get the result in unix server using a simple command. I do not want to use scripts to get the result. Hoping to use a single line command. I already tried using the isql command, but that is not working.
echo "select * from dual" | isql -v dbname userid hostname
Please help me.

Create text file in oracle using sql

I need to grab data from some oracle database tables and format it into a fixed width text file.
I want to know if its possible to create a text file using sql.
I looked at some stuff and found the bc and xp_cmdshell but they are a bit confusing.
I am pretty new to sql and oracle databases.
Is this possible and how can I begin?
I don't need to open a file or check for existing file, overwriting is fine, what ever makes it easiest.
I don't need anything big or complex, a simple script to grab values and create a text file.
Just an update:
I don't think bcp works in the toad for oracle editor.
I found this tutorial here: http://www.sqlteam.com/article/exporting-data-programatically-with-bcp-and-xp_cmdshell
but the first bcp command does not compile, it says invalid sql query
If you are using the SQL*Plus client, you can spool to an output file. Here is a sample SQL*Plus file:
set serveroutput on size 1000000
set linesize 150
spool C:\path_to_file\filename.extension
-- Your SQL statement
select columns
from table
where somecondtion;
-- Your next SQL Statement
select ...
from ...;
spool off
I think you can use sqlplus command line tool todo this. See oracle manual for formatting hints.

# command does not work in SQL PLUS (OS HP-unix)

I have a sql file (abc.sql) which contains some code. I am able to run this using "run" command as
SQL> run abc.sql
1* select 1 from dual
1
SQL>
But not able to execute using "#" command. If i execute using # it just return to the SQL prompt without executing this file.
SQL> #abc.sql
SQL>
SQL>
Could you please help me in resolving this issue?
FYI, I m using Oracle 8.1.7.4.0 on HP-unix (Tru64 UNIX V5.1B (Rev. 2650)
run does not execute a file's content. Rather, it runs the content of the buffer.
The docu (
http://download.oracle.com/docs/cd/E11882_01/server.112/e16604/ch_twelve037.htm#sthref1803 ) says
R[UN]
Lists and executes the SQL command or PL/SQL block currently stored in the SQL buffer.
The buffer has no command history list and does not record SQL*Plus commands.
Usage
RUN causes the last line of the SQL buffer to become the current line.
The slash command (/) functions similarly to RUN, but does not list the command in the SQL buffer on your screen. The SQL buffer always contains the last SQL statement or PL/SQL block entered.
You are probably misstaking run for the start command.
within your file do have
select 1 from dual
/
you need to tell the sql engine to execute the line (/)
Edit
after the # type in "EDIT" and see what the buffer says:
SQL> #a.sql
1
----------
1
SQL> ed
Wrote file afiedt.buf
...
select 1 from dual
/