SQLException 00604 & 01003 while calling stored procedure from hibernate named query - sql

We are calling a stored procedure ( which calls another inside it) from hibernate.
Query query = session.getNamedQuery("query_name");
query.setParameter('param', 'value');
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List returnList = query.list();
The stored procedure is independently running good when we run in SQL developer. But we run this through application it is giving following error.
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-01003: no statement parsed
Things we tried :
calling a simple stored procedure from hibernate - working well.
creating the test case to test the method in which the stored
procedure (which throws error) is being called - working well.
Our question is , why the same query is running good in test case, and not while running thorugh application ?
Any ideas?
Update
It was my fault, i was passing the arguments in-correctly. Just swapped the first tow arguments. To anybody facing this issue, please check your argument ordering in the named query.
Thanks.

It was my fault, i was passing the arguments in-correctly. Just swapped the first tow arguments. To anybody facing this issue, please check your argument ordering in the named query.

Related

Syntax Error While Calling DB2 Stored Procedure Through JMeter

I am trying to call a DB2 Stored Procedure which has two Input parameters (Timestamp, both) and one Output parameter (Integer). I am trying to do so from JMeter JDBC Sampler and getting sql syntax exception.
Response code: 42884 -440
Response message: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-440, SQLSTATE=42884, SQLERRMC=PROCEDURE;DEVSCHEMA.GET_ROW_COUNT, DRIVER=4.19.26
Response headers:
1272084586, URL=jdbc:db2://<db2IP>:<port>/DB2T, UserName=<someUserName>, IBM Data Server Driver for JDBC and SQLJ
From IBM Documentation I got to know that this error happens when either Stored procedure is not present - which is not the case, Schema name incorrect - which is also not the case, mismatching number of parameters - I verified this but I am doubtful at this point because JMeter provides separate fields to be filled up and in one of the fields I might be passing incorrect value.
I have not much knowledge of JMeter but with the help from apache JMeter documentation I have set below values to the Sample Fields.
Query Type: Callable Statement
Query: CALL DEVSCHEMA.GET_ROW_COUNT(?,?,?)
Parameter Values: ${__time(yyyy-MM-dd HH:mm:ss,)},${__time(yyyy-MM-dd HH:mm:ss,)},0
Parameter Types: IN TIMESTAMP,IN TIMESTAMP,OUT INTEGER
Variable Names:VARCOUNT
Handle ResultSet: Store as a String
Can anyone please figure out where am I making a mistake? Many thanks.
The issue has been resolved. It was literally something else about which I never gave a thought. When I got the same error when I tried to access the same SP using Java code, I contacted DB2 team who wrote the Stored procedure. And issue was with the SP. According to them execute access was given so after drilling here and there they preferred to create a new SP which worked without any issues. Else everything was perfect from JMeter side.

How to invoke stored procs with parameter using T-SQL scripting?

We are using edge-sql to execute T-SQL scripts and also stored procedures via C#. I noticed recently that stored proc support has been added and I'm trying to execute would would be:
exec dbo.sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx';
in SQL Server Management Studio, using edge-sql 0.1.2.
I've played around with several variations, but I get one of 2 error messages. Either cannot find stored procedure '' or "cannot find stored procedure 'sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx'" The stored proc executes just fine in edge.sql when invoked via C# method.
I did some additional experimentation and found I can execute a stored proc with no parameters: exec dbo.sgVersionGet, but any stored procs with parameters return errors.
So what am I doing wrong? And how could I invoke with parameter values that aren't hard-coded, as above? Both SQL Server and edge use the # character for parsing params.
Any help appreciated ...
-BillyB
In SQL Server when you are referring to a database object without the object full path ([database.schema].object), SQL Server will try to locate the object using the Default/Initial Catalog value which points to the default database if that was not specified within the connection string then chances are that when you try running your statement SQL Server won't be able to find the object throwing the "Cannot find XX" error, You should either specify an initial catalog on your connection string or execute your procedures using the full path, database.schema.procedure E.g. mydatabase.dbo.sp_customerCleanUp. On the other hand there is an internal procedure sp_executesql that you can use to run your procedures without having to hard code the parameters, all you need to do is build a string concatenating the hard coded part of the string (the procedure name) and whatever number of variables you are passing as parameters, see example ( https://technet.microsoft.com/en-us/library/ms175170%28v=sql.105%29.aspx )
The variables are assumed when calling a stored procedure with edge-sql. Any parameter you would preface with an '#' symbol will need to have the same name within the stored procedure.

A call for sp_OA causes an error during execution inside a scalar function

We have a scalar function in the database that calls an assembly using sp_OA methods. The scalar function is called from a view. The SQL Server is Microsoft 2008 R2, a 32-bit installation. We have the same database installed on three different servers. On one of them the call to function fails with this message
Msg 557, Level 16, State 2, Line 2 Only functions and some extended
stored procedures can be executed from within a function.
On the other two it works fine. Is there a setting we are missing on that one specific SQL Server? Or can it be something else? The internet is ambiguous about this error.
Thank you.
Thank you for the tips. The problem resolved itself rather unglamorously. It seems that an unhandled error in legacy code, through faulty data, was throwing the scalar function into a fit, causing the that particular error to show up.
Thank you.

Calling a stored function (that returns an array of a user-defined type) in oracle across a database link

Normally, I call my function like so:
SELECT *
FROM TABLE(
package_name.function(parameters)
)
I'm trying to call this function across a database link. My intuition is that the following is the correct syntax, but I haven't gotten it to work:
SELECT *
FROM TABLE(
package_name.function#DBLINK(parameters)
)
> ORA-00904: "PACKAGE_NAME"."FUNCTION": invalid identifier
I've tried moving around the database link to no effect. I've tried putting it after the parameter list, after the last parenthesis, after the package name...I've also tried all of the above permutations including the schema name before the package name. I'm running out of ideas.
This is oracle 10g. I'm suspicious that the issue may be that the return type of the function is not defined in the schema in which I'm calling it, but I feel like I should be getting a different error if that were the case.
Thanks for your help!
What you're trying is the correct syntax as far as I know, but in any case it would not work due to the return type being user-defined, as you suspect.
Here's an example with a built-in pipelined function. Calling it locally works, of course:
SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'));
Returns:
SQL_ID: a, child number: 1 cannot be found
Calling it over a database link:
SELECT * FROM TABLE(dbms_xplan.display_cursor#core('a',1,'ALL'));
fails with this error:
ORA-30626: function/procedure parameters of remote object types are not supported
Possibly you are getting the ORA-904 because the link goes to a specific schema that does not have access to the package. But in any case, this won't work, even if you define an identical type with the same name in your local schema, because they're still not the same type from Oracle's point of view.
You can of course query a view remotely, so if there is a well-defined set of possible parameters, you could create one view for each parameter combination and then query that, e.g.:
CREATE VIEW display_cursor_a_1_all AS
SELECT * FROM TABLE(dbms_xplan.display_cursor('a',1,'ALL'))
;
If the range of possible parameter values is too large, you could create a procedure that creates the needed view dynamically given any set of parameters. Then you have a two-step process every time you want to execute the query:
EXECUTE package.create_view#remote(parameters)
SELECT * FROM created_view#remote;
You have to then think about whether multiple sessions might call this in parallel and if so how to prevent them from stepping on each other.

Update linked SQL server with parameters

I have two linked SQL servers and i am trying to issue an update on the other server but am getting an error "Statement(s) could not be prepared.", followed by "Must declare the scalar variable "#Shipper_Nbr""
The syntax i am using is:
update DBSERVER.DBNAME.DBO.TABLE set Field = #Value WHERE ID = #id
What is the correct way to do this?
UPDATE:
I tried using a stored procedure and get the same result. Also, i noticed additional information. The syntax checks out, i only get the error when i attempt to save the stored procedure. Also, i noticed the error also states "OLE DB provider "SQLNCLI" for linked server "WARSQLVS01" returned message "Deferred prepare could not be completed."."
ACK - i figured it out. It was a separate line where i was trying to pass the parameter from within OPENQUERY select statement. Sorry about that! :-\
Not entirely sure what this problem is, but we have had to work round similar kinds of issues by setting up a stored proc on the remote server and calling that, rather than trying to manipulate the items on the remote server locally.
Are you sure the problem is with the server link, and not something about the rest of your SQL statement? Where is the #Shipper_Nbr value assigned?
Se if this works
UPDATE T
SET Arrive_DT = #Actual_DateTime
WHERE Shipper_Nbr = #Shipper_Nbr and Container_Name = #Container_Name
FROM WARSQLVS01.ISS3_AND_DHAM_PROD.dbo.ISS_AND_data_Shipments as T