I am trying to run a shell script with values and pass those values into a .sql file which will call my plsql procedures with these values. I've tried a lot with no luck.
What I have now:
shl script: RunSql $SQL_PATH/update_load_status.sql 'N'
sql script: execute dbms_output.put_line('&1'); (based on other code in system - (&1) gives a bind var not declared)
Will multiple values work in a similar manner?
Thanks!
Use the DEFINE keyword to capture the arguments passed to a shell script
define first_arg=&1
define second_arg=&2
BEGIN
dbms_output.put_line('&first_arg');
dbms_output.put_line('&second_arg');
END;
/
Related
I have a ssis package that has a foreach loop container. I am trying to use .bat file within the foreach loop container using execute Process task. How do I configure my Execute Process task to pass the value into my .bat file?
Here is my sequence:
Execute sql task (passing my variable into the foreach)--> Foreach loop container----> Execute Process Task (I need help with executables, arguments....)
Create 2 variables in your SSIS package.
The first one would have the FileName along with the entire path.
The other variable will have its property 'Evaluate As Expression' set to TRUE and set its Expression to the following -
"local:" + #[System::FilePathVariable] + " -d HDMS:/To_HDMS/"
As soon as the second variable is referenced in your SSIS package, its expression (the one written above) would execute.
Say the FilePathVariable had the value "D:\Folder1\Folder2\FileName"; so, the value of the second variable after its expression is evaluated would be "local:D:\Folder1\Folder2\FileName -d HDMS:/To_HDMS/"
You need to pass this as an argument to your batch file. This would be done as explained in my previous post above.
In your batch file, have the command as -
C:
cd \Program Files\WS_FTP Pro\
wsftppro -s %1
Please try and let us know in case it doesn't work for you.
How we can pass shell variable to pig param file. As an example I have a shell variable defined as DB_NAME. i would like to define my pig parameter file as
p_db_nm=$DB_NAME
I tried like above which does not work and i did try like echo $DB_NAME does not work either.
I'm aware that i can pass this by using -param in command line but i have many variables which i would like to put it in param file but the values will be defined in shell script. I searched many topics in google and didn't have any luck!!!
My question is similar what was posted in http://grokbase.com/t/pig/user/09bdjeeftk/is-it-possible-to-use-an-env-variable-in-parameters-file but i see no workable solution is posted.
Can anyone help?
you can pass parameter file using –param_file option.
if Parameter File named "pig.cfg" defined like below,
p_db_nm=$DB_NAME
in the shell, pig command will be like this,
pig -param_file pig.cfg
and finally in your pig, you can use does variables named by KEY in the cfg file. (in this case, $p_db_nm)
#libjack:
Hi,
I wanted to pass parameters into the hql from ksh script.
I went through Apache hive using variables document. The below worked fine where I set the values inside hql:
SET hivevar:parm1=valu1;
CREATE SCHEMA IF NOT EXISTS ${parm1};
But I wanted to pass the parameters while invoking hive inside ksh. I have the variables and its value in a file as below:
--hiveconf:
SET hivevar:parm1=valu1;
--Inside .ksh:
hive --hivevar "'cat ${hiveconf}`" -f hiveScript.hql
--hiveScript.hql:
CREATE SCHEMA IF NOT EXISTS ${parm1};
This fails. I tried with hiveconf as well.
How to pass the variable to hql?
Is it possible to pass as a file?
Thanks.
I am running the following SQL query through a powershell script and need to run the script multiple times against different files. So what I am trying to figure out is how to specify a file path as a variable when I run the script?
update [$Db_name].[dbo].[$BatchTable]
set [$Db_name].[dbo].[$BatchTable].Wave = 'Wave1.1'
from [$Db_name].[dbo].[$BatchTable]
inner join OPENROWSET(BULK 'FilePath\file.csv',
FORMATFILE= 'E:\import.xml') AS a
on ([$Db_name].[dbo].[$BatchTable].Name= a.Name) and
([$Db_name].[dbo].[$BatchTable].Domain = a.Domain)
The 'FilePath\file.csv' is the file path I need to define as a variable so that my code would instead look like this:
inner join OPENROWSET(BULK '$INPUTFILEPATH',
FORMATFILE= 'E:\import.xml') AS a
Any help or potentially better methods to accomplish this would help very much.
From the command like I want to be able to run the script like this:
CMD: updatescript.ps1 $INPUTFILEPATH = C:\Documents\myfile.csv
Again, I'm not sure this is the best way to go about this?
You're nearly there.
You will need to add a parameter block at the very start of your script e.g.
Param(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_ -PathType 'leaf'})]
[string] $InputFilePath
)
This creates a mandatory (not optional) string parameter, called InputFilePath, and the ValidateScript is code used to validate the parameter, in this case checking the file exists using the Test-Path cmdlet and pathtype of leaf (if checking existence of a directory use 'container').
When running your script use the syntax below:
updatescript.ps1 -INPUTFILEPATH "C:\Documents\myfile.csv"
and in the script use the variable as the path exactly as in your question:
inner join OPENROWSET(BULK '$INPUTFILEPATH',
FORMATFILE= 'E:\import.xml') AS a
NOTE: in powershell when using parameters when running a script you only need to use the least amount of characters that uniquely identify that parameter from all the others in your param block - in this case -I works just as well as -InputFilePath.
You can pass command line parameters to the powershell script using param.
Example:
param(
[string]$INPUTFILEPATH
)
And then call the script as follows:
updatescript.ps1 -INPUTFILEPATH C:\Documents\myfile.csv
More details about cmd line parameters can be found here
I am using Command Prompt to run SQL Scripts. One of the script requires a file name which is read from a settings file (file_name=ABC) by CMD and feed to the script like so
sqlplus #"Script_Run" %file_name%
Inside the script the input is read in the line:
UTL_FILE.FOPEN('DIR','&1.ext','R');
Now when I run the bat file,
the substitution happening is:
old: "&1.ext"
new: "ABCext"
the script returns "Invalid File Operation" error.
But when I change the script line to:
UTL_FILE.FOPEN('DIR','&1..ext','R');
it works. Why does the sql script here require two dots ?
improved formatting
As documented in the SQL*Plus® User's Guide and Reference, the period is used to concatenate the value of a substitution variable with other characters:
If you wish to append characters immediately after a substitution variable, use a period to separate the variable from the character. For example:
SELECT SALARY FROM EMP_DETAILS_VIEW WHERE EMPLOYEE_ID='&X.5';
Enter value for X: 20
is interpreted as
SELECT SALARY FROM EMP_DETAILS_VIEW WHERE EMPLOYEE_ID='205';