I need to call another sql file within an sql file using sql plus - sql

I need to call another sql file within an sql file using sql plus. This si the script i have so far and its not working. I have to code it in a unix vi file. I am new to this so would someone mind helping. thank you in advance.
call=`$LIVE_SQL/sqlfile2.sql`
if &call = 0 then
echo "ERROR: $LIVE_SQL/sqlfile2.sql file not found"
exit 1
fi

The command to call other SQL files from within SQLPLUS is : start (or #)
Getting feedback from the SQL script : SQLPLUS is not Bash. It is possible, but not really beginner stuff.

Related

TWS job is getting abended

While executing the job, I am getting below error
Job.sh is the script - while executing it in tws I am getting below error
path of the script - job.sh: sqlplus: not found
Can any please help on this
Thanks
I don't know how Tivoli works, but you are writing to run a "job.sh" script, so I assume it is a shell script.
Normally when working with oracle it is a good idea to enter absolute paths, so your script could be
#!/bin/sh
$ORACLE_HOME=<your path of oracle installation>
$ORACLE_SID=<your instance name>
$PWD=<Position of your sql script>
..........
$ORACLE_HOME/bin/sqlplus login/password #$PWD/script.sql
I hope that's what you were looking for.

How to run an SQL file with sqlplus in Powershell ISE

I want to execute an SQL file with sqlplus, but when I try to in Powershell ISE the result says how to use sqlplus. The result I get
The code I used in the example in ISE is:
sqlplus "username/password#database #C:Path\To\file.sql"
But when I run this code in CMD or regular Powershell it works without problems. The result is just some dummy Select 1 from dual.
I have tried to put the path in a single qoute( ' ) with and without the # (inside and outside of the quote) but nothing is working. I also didn't find much when googling the issue.
I also tried just to connect and it works without problems, although I can't type anything after it connects. Result with just the connect
because you are doing wrong
the real syntex is
sqlplus username/password#TnsAlias 'c:\path\to\DBscript.sql' | out-file 'c:\temp\sql- output.txt'
I think you (') use early.
or try this without outfile
$output = sqlplus username/password#TnsAlias 'c:\path\to\DBscript.sql'
store in variable

Passing variable into SQL script using BAT file

Here is my dilemma. I cannot get my code to work. I have a batch file which executeS an SQL script. The batch file needs to be able to execute the sql script using the proper variable. Here is my batch file
#echo off
set list= TRA-1000 TRA-1002 TRA-1003 TRA-1004
for %%a in (%list%) do (
#sqlplus gpms/gpms#prod112 #get_tra1098_data.sql outputfilename = %%a
)
#pause
So essentially I am trying to pass the selected item from 'list' into my sql script. Here are the relevant lines of code from my sql file:
spool $(outputfilename).csv
...
where inst.instruction_doc_no in ($(outputfilename))
...
It is not working. How do I get my batch file to properly call my sql file in a loop, each time calling the sql file using the proper item in 'list'?
ps. this is what the sql file would look like if I wasn't trying to automate it:
spool TRA-1000.csv
...
where inst.instruction_doc_no in ('TRA-1000')
...

Using sql within shell script

I am currently trying to integrate an sql statement into a shell script, But facing major syntax issue:
My statement in the script:
su - <sid>adm -c 'hdbsql -U SYSTEM export "'SCHEMA'"."'*'" as binary into "'Export Location'" with reconfigure'
I get the following error:
* 257: sql syntax error: incorrect syntax near "*": line 1 col 16 (at pos 16) SQLSTATE: HY000
Would really appreciate if anyone could help me with this.
Thanks and Regards,
AK
Your command line doesn't make much sense to me. It starts with
su - <sid>adm
which means that you are redirecting the contents of the file "sid" into "su" and then redirecting the result of that operation into the file "adm".
Second problem is that in the command you are giving to adm, the single quotes end right before the "" which means, that the "" will get interpreted by the shell as a file glob:
-c 'hdbsql -U SYSTEM export "'SCHEMA'"."'*'" as binary into "'Export Location'" with reconfigure'
You'll need to escape those single quotes like this: "\'".
But I think your problem solving approach is not good. Try to reduce to problem and only then start adding additional things to it. So first try to execute the SQL statement from the "hdbsql" shell. Does it work?
$ hdbsql
> YOUR SQL STATEMENT HERE
Once that works, try to execute the SQL statement from the unix shell as a user:
$ hdbsql -U SYSTEM export ...
Once that works, try to execute it via su
$ su - ...

How to generate executable TPC-DS queries?

I have downloaded the DSGEN tool from the TPC-DS web site and already generated the tables and loaded the data into Oracle XE.
I am using the following command to generate the SQL statements :
dsqgen -input ..\query_templates\templates.lst -directory ..\query_templates -dialect oracle -scale 1
However, No matter how I adjust the command I always get this error message :
ERROR: A query template list must be supplied using the INPUT option
Can anybody help?
Apparently you need to use / rather than - for the flags for the Windows executable:
dsqgen /input ..\query_templates\templates.lst /directory ..\query_templates
/dialect oracle /scale 1