how to call store procedure from bteq in Teradata? - teradata

I need to call a store procedure from BTEQ but I am unable to handle the Transaction error.
The script looks like below:
.logon xxx/xx,xx
CALL DD_LAB.MY_SP('a', 'b', outParam);
.logoff

Related

Shared database and "An owner referenced by user does not have EXECUTE PROCEDURE access to" procedure

Is there a way around it in Teradata, if you have rights to create a procedure in the shared database, but fail to execute the first procedure inside the second procedure you created in the same database.
Attempted with SQL INVOKER and SQL CREATOR.
Tried an option to grant the execution explicitly, ended with the:
The user doesn't have CREATE PROCEDURE WITH GRANT OPTION access to database
What else can be done here?
.login server1/$user1,$pwd1
database shared_db;
replace proc proc1
SQL SECURITY CREATOR
begin
end;
replace proc proc2
begin
call proc1;
end;
-- errors
EDIT for Fred:
Database holding the procedures is shared (aka shared_db). User1 (who has the rights to create procedures in the shared_db) is creating proc1 in it, and proc2; the latter executes proc1 from its body.
EDIT 2 - concluded, setup needed was indeed (which is not that obvious)
GRANT EXECUTE ON shared_db.proc1 to shared_db;
The creator of PROC1 can
GRANT EXECUTE PROCEDURE ON shared_db.proc1 TO shared_db;

How to execute multiple Oracle statements from .sql script in Airflow OracleOperator

I am using OracleOperator to execute sql at remote database source.
Below is the simple operator code written in Airflow DAG,
t2 = OracleOperator(
task_id='task_2',
oracle_conn_id='ORA_DATABASE_SYSTEM',
sql='/query.sql',
dag=dag)
query.sql is the file created , which i want to have multiple sql statements which can be DDL or DML, but while running DAG it throws
cx_Oracle.DatabaseError: ORA-00922: missing or invalid option
.sql file have following sql statement,
create table SP(name varchar(50), age int);
insert into SP (name,age) values('Suraj',24);
insert into SP values('Ashish',27);
AM i doing something wrong ?
It would be help if anyone can share trying different or pointing right way of doing it.
After some try outs, i am able to use Oracle Operator to execute multiple sql statements on remote Oracle database using .sql script.
# template_searchpath is the path where .sql files are stored
dag = DAG('Test_Oracle_Connection', default_args=default_args,template_searchpath=['/home/Ashish'])
t2 = OracleOperator(
task_id='task_2',
oracle_conn_id='Oracle_connection',
sql='/oracle_query.sql', #SQL file name
dag=dag)
oracle_query.sql file contains multiple sql statements, for example
DECLARE
sql_smt VARCHAR2 (5000);
sql_smt := q'[<SQL_STATEMENT>]'
EXECUTE IMMEDIATE sql_smt;
EXECUTE IMMEDIATE 'commit';
This might not be the best way but at least working for me at the moment.
Please share any other best way if there, to connect to remote Oracle database and execute your queries which can be DDL or DML.

Teradata ODBC connection

I am trying to run a stored procedure stored in Teradata database using python script. Teradata ODBC is connected in 'Teradata' mode. Still I am getting the following error:
3932 :Only an ET or null statement is legal after a DDL Statement
The Stored procedure does not have 'ET' between DML and DDL in my stored procedure.
I do not have access to modify the stored procedure.
When I call th eprocedure in SQL Editor, it runs absolutely fine.
Any help will be greatly appreciatd.
Thank you!

Oracle SQL French script file

I need to do a mass insert into my database. I have French characters(e.g é) into my table
When i connect to SQLPlus and run the query manually
INSERT INTO TEST VALUES ('é');
Data is inserted properly.
When i save the same query in an Sql file and execute same through SQLplus
I get below error:
SQLPLUS>#test.sql;
ERROR:
ORA-01756: quoted string not properly terminated
Can anyone guide me.
thanks

Error during Invoking a Stored procedure from UNIX

I had a stored procedure with no arguments which was invoked form the UNIX
script by db2 call and the SP was working fine and script running fine as well.
The new requirement is to pass a file name to the stored procedure and do some
business logic -- I am not able to pass the file name from UNIX to the SP. I am using IN parameter of Varchar(50).
The SP compiled fine and is available in the correct schema -- I invoked
using multiple ways and none of them are working fine.
Please help me debug this.
DB2 Stored Procedure:
CREATE PROCEDURE ABC.sp_Update(IN FILE_NAME VARCHAR(50))
Different methods I tried Calling the DB2 stored proc from the UNIX script
db2 call "ABC.sp_Update("filename.txt")"
db2 call "ABC.sp_Update(("filename.txt"))"
FILE_NAME="filename.txt"
db2 call "ABC.sp_Update($FILE_NAME)"
FILE_NAME="filename.txt"
db2 call "ABC.sp_Update($(FILE_NAME))"
The error I get:
db2 call ABC.sp_Update(filename.txt)
SQL0206N "FILENAME.TXT" is not valid in the context where it
is used. SQLSTATE=42703
When I checked for the execution status of the command I get a return code 4
+ RC=4
Before the code change, this worked fine:
db2 call "ABC.sp_Update()"
When I Googled the description of the error 42703, it is An undefined column, attribute, or parameter name was detected.
Sorry Guys - Should have used a single Quote - It worked - Thanks and sorry

Resources