how to run multiple queries via DOS batch file, which will create plsql packages - sql

how to run multiple queries via DOS batch file, which will create plsql packages?
I'm that far:
This is my 'driver'
#Echo Off
sqlplus [login details] #C:\runPackages.sql
EXIT
and in file runPackages.sql I have:
#C:\SqlPackage1.sql
#C:\SqlPackage2.sql
#C:\SqlPackage3.sql
Its seems, that this is working for simple Sql Queries, but its not creating packages...
Thanks for any advice.

"Well it gives me number... Just that. Like 69, or 6800. Don't know,
what does that mean."
What that means is you haven't terminated your CREATE PACKAGE scripts properly. That is SQL*Plus's way off telling you it expects you to enter another line of code. And that's why they don't run from the driver script either.
After the end; you need a new line and a slash to execute the statement. Like this
create or replace package package1 as
....
end package1;
/
Finish off each CREATE statement with the slash and your scripts will run without further input.
The teaching from this is, we need to test our individual program units first before we integrate them at a higher level.

Related

Azure Data Factory Script Activity does not like the keyword GO

If I create a script, e.g.
print 'hello'
GO
print 'cats'
GO
Then the script errors when I try to run my ADF pipeline:
Operation on target GreetCatsActivity failed: Incorrect syntax near 'GO'.
Is GO not allowed in scripts? The issue is I need it to run a gigantic script that is autogenerated and has tons of GO statements in it. Part of the script might reference things created earlier in the script so I suspect the GO statements are important to ensure items are created to be used later on.
Could I be doing something wrong or is there another way to handle this?
Just throught of sharing this as a think this may be helpful .
You can use the a Mapping data flow pipeline to replace the "GO" .
What I tried is on the source side I added the scripts ( a files with the extension .sql , I am assuming you must be gaving something similar ) which is shared with "GO" above & I used the FIlter to ger rid of the all the GO's and on the sink I did write back the scripts ( without GO to a blob .
Now I wanted to automate the execution of the command using the Script activity in ADF .
For executing the queries we will use the a Lookup which will read the file which we created in the last step and a for each loop and a Script activity inside that .
My lookup output looks something like
and so wjem you are setting the scripts activity , please pass dynamic value as i did
HTH

How to execute SQL queries from text files

I am using Aqua Data Studio 7.0.39 for my Database Stuff.
I have a 20 SQL files(all contains sql statements, obviously).
I want to execute all rather than copy-paste contains for each.
Is there any way in Aqua to do such things.
Note: I am using Sybase
Thank you !!
I'm also not sure of how to do this in Aqua, but it's very simple to create a batch/powershell script to execute .sql files
You can use the SAP/Sybase isql utility to execute files, and just create a loop to cover all the files you wish to execute.
Check my answer here for more information:
Running bulk of SQL Scripts in Sybase through batch
In the latest versions of ADS there is an integrated shell named FluidShell where you can achieve what you are looking for. See an overview here: https://www.aquaclusters.com/app/home/project/public/aquadatastudio/wikibook/Documentation15/page/246/FluidShell
The command you are looking for is source
source
NAME
source - execute commands or SQL statements from a file
SYNOPSIS
source [OPTION...] FILE [ARGUMENT...]
source [OPTION...]
DESCRIPTION
Read and execute commands or SQL statements from FILE in the current shell environment.
I have not used Aquafold before so I can't tell you exactly. However I have tackled a similar problem once before.
I once created a Powershell script. It opened a ODBC connection to my database and then executed stored procedures in a loop until end of file.
I suggest having a text document with each line being the name of an Stored Proc to run. Then in your powershell script read in a line from the file concatenate it into the call to execute a stored procedure. After each execution is completed you can delete the line from the text file and then read the next line until the EOF (end of file) is reached.
Hope this helps. If I have some time this morning I will try and do a working example for you and post it.

Passing parameters to oracle script

This is my scenario.
I have Test1.sql, Test2.sql and Test3.sql files with create, drop, insert, etc statements. The number of files could increase in the future.
I wanted to run all of them in a single script so I created a master script Master.sql, which has the below
##Test1.sql
##Test2.sql
##Test3.sql
I run it as #"Path to the script\master.sql" using SQL plus command prompt on my windows and if I wanted to run it through SQL developer, I just open the master.sql file and run it. So far so good…
Now, I have to run the master.sql in various environments with different user and schema names but the user and schema names are hard coded in the scripts. I want to be able to replace all the occurrences of the hard coded names with parameters and pass them just once on Master script execution. Both from the command prompt and using SQL developer. How do I do it? Please advice.
Have a look at the documentation of the SQL*PLUS User Guide and Reference.
From the manual:
You can bypass the prompts for values associated with substitution
variables by passing values to parameters in a script through the
START command. You do this by placing an ampersand (&) followed by a
numeral in the script in place of a substitution variable. Each time
you run this script, START replaces each &1 in the file with the first
value (called an argument) after START filename, then replaces each &2
with the second value, and so forth. For example, you could include
the following commands in a script called MYFILE:
SELECT * FROM EMP_DETAILS_VIEW
WHERE JOB_ID='&1'
AND SALARY='&2';
In the following START command, SQL*Plus would substitute PU_CLERK for
&1 and 3100 for &2 in the script MYFILE:
START MYFILE PU_CLERK 3100
When you use arguments with the START command, SQL*Plus DEFINEs each
parameter in the script with the value of the appropriate argument.

Is it possible to execute Teradata FastLoad or MultiLoad scripts through VBA?

I am able to run Normal DML scripts (INSERT, UPDATE & DELETE) scripts through VBA ODBC connection.
But Is it possible to run FLOAD or MLOAD scripts through VBA ODBC ?
I have large set of data and i want to write a VBA code for FLOAD / MLOAD to insert the data very quickly rather than normal DML scripts.
I heard that FLOAD / MLOAD can be executed from Unix or Mainframe systems. Is it possible to run from VBA ? If yes can you please help with some sample ?
Below is sample Teradata FLOAD script.
.LOGTABLE DB.Table_Log;
.LOGON oneview/uid,pwd;
.BEGIN IMPORT MLOAD TABLES DB.FRC_RPT_PERD SESSIONS 5;
.LAYOUT InputFile_layout;
....
....
From some brief research it appears MLOAD and FLOAD are command line utilities (.EXE)
If that is correct you would run it like this in VBA:
Shell(sCmdLine, vbHide)
Where sCmdLine is a string variable holding your command line
This site suggests your command line might be
mload < example.txt
http://datawarehouse.ittoolbox.com/groups/technical-functional/teradata-l/multiload-script-2193378
Anyway the first thing to do is work out your command line. Then you just run that from VBA. You will of course need all the Teradata client tools installed on the machine with VBA. Maybe that's your issue?

Mysql: How to call sql script file from other sql script file?

Suppose I have wrote script Table_ABC.sql which creates table ABC. I have created many such scripts for each of required tables. Now i want to write a script that call all of these script files in a sequence so basically I want another script file createTables.sql. Mysql provides option to execute a script file from "mysql" shell application but could find some command like exec c:/myscripts/mytable.sql. Please tell me if there is any command that can be written in sql script itself to call other one in latest mysql versions or alternative for same.
Thanks
You can use source command. So your script will be something like:
use your_db;
source script/s1.sql;
source script/s2.sql;
-- so on, so forth