Error on calling Snowflake stored procedure from tDBrow in Talend - stored-procedures

I am getting below error message while executing a Snowflake stored procedure from tDBrow in Talend.
​
The same stored procedure executes fine when executed from Snowflake Web UI. Could you advise why I am getting scoped transaction error when executing from Talend but not from Web UI.
ERROR:
Stored procedure execution error: Scoped transaction started in stored procedure is incomplete and it was rolled back.

The problem is solved. When the procedure is called from Talend, the transaction starts before execution of the procedure and it finishes after the execution.
I should have explicitly defined the scope of transaction inside the procedure. Therefore, I added these two lines at the beginning and end of the procedure (before return) respectively:
snowflake.createStatement({sqlText: "BEGIN TRANSACTION"}).execute();
snowflake.createStatement({sqlText: "COMMIT"}).execute();

Related

Snowflake procedure is running as caller but not as owner even though both are same

The definition of the procedure is as follows
CREATE OR REPLACE PROCEDURE "EMPLOYEE_TREND_TMP"()
RETURNS VARCHAR(16777216)
LANGUAGE JAVASCRIPT
EXECUTE AS OWNER
AS '
var rs = snowflake.execute( { sqlText:
SELECT count(*) FROM "DATA_MART"."EMPLOYEE"."CCH_EMPLOYEE_COMP" ;
} );
';
The owner of the procedure is HR_ROLE. When I specify "execute as caller" and call the procedure using HR_ROLE, it works fine. But "execute as owner" throws an error:
"Execution error in store procedure EMPLOYEE_TREND_TMP: Stored procedure execution error: Requested information on the current user is not accessible in stored procedure. At Snowflake.execute, line 4 position 21"
This is strange because both the owner and caller of the procedure is HR_ROLE itself.
The query inside the procedure "SELECT count(*) FROM "DATA_MART"."EMPLOYEE"."CCH_EMPLOYEE_COMP" ;" is also running fine using the HR_ROLE.
I want to execute the procedure as owner but I am confused as to why it's throwing an error, when both the caller and the owner are the same exact role (HR_ROLE). I have checked all the privileges and access to objects, everything seems to be in place.
As I see, this error occurs usually happens when accessing information_schema or session parameters. Are you sure that the SP contains only 1 line, and it's just calling this statement? Could there be other statements to access session variables or information schema?
Have you checked the limitations of the Owner’s Rights Stored Procedures?
https://docs.snowflake.com/en/sql-reference/stored-procedures-rights.html#owner-s-rights-stored-procedures

While executing simple stored procedure getting warning compiled but compilation error how to see

While executing a simple stored procedure getting a warning compiled but compilation error how to see.
Below is the query:
create procedure spgetdat
as
begin
select empis empname, empadd from tb1employees;
end;
While executing above query getting an error. Pls suggest what needs to be corrected.
Regards
Jitendra
Your Select statement inside the procedure is not correct. There should be into clause in the select statement inside the PL/SQL block.
It can be like below. You have to put a where condition for selection of one record or for best practice you can use cursor to fetch more then one record also.
create procedure spgetdat
as
v_empis tab1employees.empis%type;
v_empadd tab1employees.empadd%type;
begin
select empis empname ,empadd into v_empis,v_empadd from tb1employees where empis = 'given name' ;
end;
show errors;

SPL routine is no longer valid

I have a stored procedure named
"component_allocate"
When I execute this procedure using PreparedStatement, I get the following error
[Error Code: -721, SQL State: IX000] SPL routine(AAABxg) is no longer valid.
I get the same error even when I execute the procedure directly on DbVisualizer.
I tried updating the statistics on the procedure using
update statistics for procedure component_allocate
That didn't help. Still getting the same error.
Has anyone else faced this problem in informix ? How do I resolve this?
Did you check this?
"If an index was added after the statement was prepared, you must prepare the statement again and declare the cursor again. You cannot simply reopen the cursor if it was based on a prepared statement that is no longer valid."
source:
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.docnotes.doc/uc3/ids_perf_docnotes_10.0.html

HSQLDB: COMMIT within stored procedure

Within HSQLDB, I'm trying to create a stored procedure that executes a commit after having updated the database.
Something like:
CREATE PROCEDURE MY_PROC(IN p_id INTEGER)
MODIFIES SQL DATA
BEGIN ATOMIC
...
UPDATE ...
...
COMMIT;
END
Creating this procedure, by means of a call to the JDBC Statement.execute() method, I get an error:
SQLSyntaxErrorException: unexpected token: COMMIT required: END
Without the COMMIT statement, the procedure is compiled correctly.
Any idea what I'm doing wrong?
You cannot commit the transaction inside a procedure.
You can commit after calling the procedure.

DB2 - How do I create a Stored Procedure that ignores errors?

I am trying to create a simple stored procedure in DB2 that performs the following actions:
Drop table "DELETE_ME"
Create table "DELETE_ME"
Insert into table "DELETE_ME"
Basically, if the table DELETE_ME already exists, the stored procedure executes fine. If it does not exist, then the Stored Procedure fails with the following error:
Lookup Error - DB2 Database Error: ERROR [42704] [IBM][DB2/LINUXX8664] SQL0204N "SARTS02T.DELETE_ME" is an undefined name.
I completely understand this. However, I was hoping to set the procedure up to ignore this error (and all errors) that way the procedure can work as a deployment script as well. On the first deployment, it will ignore the drop table line and jump right to building the table.
I found a CREATE PROCEDURE option called CONTINUE AFTER FAILURE however I am receiving an error. Please see my code and error below. Thanks for your help!!!
CODE:
CREATE OR REPLACE PROCEDURE TEST_PROC LANGUAGE SQL CONTINUE AFTER FAILURE
BEGIN
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME (
COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A) VALUES (69);
COMMIT;
END;
ERROR:
Lookup Error - DB2 Database Error: ERROR [42601] [IBM][DB2/LINUXX8664] SQL0104N An unexpected token "CONTINUE AFTER FAILURE" was found following "ST_PROC LANGUAGE SQL". Expected tokens may include: "<space>".
The BEGIN ... END section is called a compound statement which allows various declarations and other statements, including other compound statements, to be included inside it.
You'll want to declare a condition handler. You could do it something like this.
CREATE OR REPLACE PROCEDURE TEST_PROC
LANGUAGE SQL
COMMIT ON RETURN YES
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '42704' -- or SQLEXCEPTION
BEGIN
-- insert any code here when DROP fails
END;
DROP TABLE DELETE_ME;
CREATE TABLE DELETE_ME
( COLUMN_A DECIMAL(5)
);
INSERT INTO DELETE_ME (COLUMN_A)
VALUES (69);
END;

Resources