"PL/SQL: Statement ignored" error in Java - jdbc

When I call a PL/SQL of particular schema in Java file it is getting executed and retrieves the result. But when I call another PLSQL in the same Java file of different schema it shows an error saying:
Message: `ORA-06550: line 1, column 7: PLS-00201: identifier 'TEST2' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored`
Example : There are two proc say A and B present in x schema and y schema
I am calling it under test.java file:
CallableStatement csforST= connection.prepareCall("{ call A() }");
csforST.execute();
It works fine.
But when I call:
CallableStatement cs= connection.prepareCall("{ call B() }");
cs.execute();
It displays an error saying B must be declared.

Thank you very much Griffey you made my day. Yes what Griffy said is right. It is simple but spent one day to find it. Since i am new in calling stored proc.
Actually there will be a username and password given for making the connection. The username what i am using do not have permission for the another schema. Hence created a new connection with a userNaming having an access to that schema and then called the another proc. It works fine now :).
I guess it would be useful for the starters like me.
Thanks Griffey

Related

Why Can't PDI find/run my package stored procedure?

community! This is my first question, please go easy on me! :)
I have an ETL process on PDI to orchestrate calls on procedures stored in a package in Oracle.
Some procedures are ready and run normally on PL/SQL Developer.
When I call them using pentaho, either using the job 'SQL' or the transformations 'Execute SQL Script' or 'Call DB procedure' I always get an error related to "can't find the procedure", like: "ORA-00904: "PKG_CARGA_DIARIA_SABARA"."FUN_HELLO_WORLD": invalid identifier" or "ORA-06550: line 1, column 13:
PLS-00201: identifier 'PKG_CARGA_DIARIA_SABARA.FUN_HELLO_WORLD' must be declared".
Please, what am I doing wrong?
enter image description here
enter image description here
enter image description here
EDIT 1: I'm using the user that created the package both to test it in PL/SQL Developer and to connect to the database in PDI.
If I run your code, I get - no surprise - the same message:
SQL> select "PKG_CARGA_DIARIA_SABARA"."FUN_HELLO_WORLD" from dual;
select "PKG_CARGA_DIARIA_SABARA"."FUN_HELLO_WORLD" from dual
*
ERROR at line 1:
ORA-00904: "PKG_CARGA_DIARIA_SABARA"."FUN_HELLO_WORLD": invalid identifier
SQL>
It means that function in that package (which means the package itself) isn't accessible to me. Of course it isn't, I don't have it in my schema. Looks like you don't have it either.
Saying that it works in PL/SQL Developer, I suppose you're connected as package's owner. If user - who tries to call that function - connected to the database in PDI (whatever it is, I don't know/use it) isn't the same as the one you used in PL/SQL Developer and it wasn't granted EXECUTE privilege on the package, then it can't "see" nor execute it.
Therefore:
try to connect as package's owner
if you must connect as someone else, let owner grant EXECUTE privilege, while you should (in PDI) precede package name with the owner name
Found it here! Will post so that anyone can use the answer.
PDI Doesn't automatically consider the schema from the database connection user, you have to specifically add it to your code inside the SQL job.
So: "BEGIN .<procedure name; END;" yelds the error, even though I was running with the procedure and package owner.
And: "BEGIN ..<procedure name; END;" will work it out just fine.
Hope it helps someone, tks!

Does anyone know if the Control-M job designed to run stored procedure accepts parameter with ORACLE pre-defined table type "odcivarchar2list"

The procedure is running fine in the Oracle SQL developer. But when I want to run the same procedure using Control-M database job it is showing me below error:
Job failure message:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'EXE_SUBPARTITION_PARAM_QRY'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Also while passing parameter list in Control-M, it is giving Parameter type as "UNDEFINED" for using ORACLE pre-defined table type "odcivarchar2list" in my procedure.
I know that BOOLEAN type is not supported by Control-M, is this applies to oracle pre-defined types too!
Many thanks for your help.

How to call a package which is belongs to a another user

I have a package'PKG_PARTITION_MAINTENANCE in Schema : 'SAB_OWN'
and i gave EXECUTE PERMISSION TO A USER LIKE BELOW :
GRANT EXECUTE ON PKG_PARTITION_MAINTENANCE TO SAB_READ_USER;
but when the user is trying to call the package it getting error as below :
EXECUTE PKG_PARTITION_MAINTENANCE.ADD_TABLE_PARTITIONS('tbl_name');
ERROR :
[Error] Execution (3: 7): ORA-06550: line 1, column 7:
PLS-00201: identifier 'PKG_PARTITION_MAINTENANCE.ADD_TABLE_PARTITIONS' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
is anything i am missing, why user SAB_READ_USER not able to execute it ? This package is running well in SAB_OWN Schema.
You have to tell Oracle which schema the object belongs to, if it isn't in the schema you're logged into like so:
EXECUTE SAB_OWN.PKG_PARTITION_MAINTENANCE.ADD_TABLE_PARTITIONS('tbl_name');
You could also create a synonym instead:
create synonym PKG_PARTITION_MAINTENANCE for SAB_OWN.PKG_PARTITION_MAINTENANCE;
which acts like a pointer to tell Oracle where to look for the object being called.
Or, you could alter your session so that the schema you're "looking" at is a different one to the one you logged in as:
alter session set current_schema = SAB_OWN;
These last two options should allow you to run the package without explicitly stating the schema name, although personally, I wouldn't recommend them - I would go with explicitly stating the schema name, unless there was a jolly good reason why that wouldn't work!

Spring->Oracle stored procedure call schema issues

As part of a refactor, I am trying to change database calls to use Spring 4.1.0.RELEASE in order to handle connections and exceptions and allow result sets to be passed between functions and classes.
I've gotten my MS SQL Server stored procedure calls working fine, but when I tried to execute an Oracle stored procedure, I got the following error message:
2014-11-13 15:39:35,836 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /EmailServiceLayer/EmailServletClient/springtest/123:
org.jboss.resteasy.spi.UnhandledException: org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback;
bad SQL grammar [{call SPRING_JDBC_TEMPLATE_TEST()}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'SPRING_JDBC_TEMPLATE_TEST' must be declared
I simplified the problem by writing a couple very simple stored procedures that write to a test table: one that takes a parameter and writes and one that takes no parameters and just writes a hardcoded value. These procedures are in the INV schema, which is the same user that my datasource is configured to use.
Eventually I tried running it on my own personal schema, using a datasource configured to use my personal credentials, and it succeeded. I had an admin grant execute all on the procedures in INV, but still no luck. I've confirmed that I can successfully execute simple inline inserts on the INV schema using Spring JdbcTemplate.execute().
My first attempts were using the JdbcTemplate with a CallableStatementCreator of my own definition. I then tried using SimpleJdbcCall, which is what I found out worked on my personal schema. Both ways give the same error message on the INV schema. Here is the code for my latest attempt:
SimpleJdbcCall caller = new SimpleJdbcCall(alex3InvTemplate).withProcedureName("spring_jdbc_template_test");
MapSqlParameterSource paramMap = new MapSqlParameterSource();
paramMap.addValue("p_testval", testval);
Map<String, Object> result = caller.execute(paramMap);
and my test proc:
create or replace
procedure spring_jdbc_template_test
(
p_testval IN number
)
as
begin
insert into jdbc_template_test_table values(p_testval);
commit;
end;
My application is running on a Wildfly 8.0.0.Final server. The datasource configurations for the 2 schemas are exactly the same except for the credentials used to log in. I am able to execute the procedures in INV using the same datasource with a basic JDBC CallableStatement and I've confirmed that I can run them in SQL Developer.
Thanks in advance for any help.
Turns out I made a silly mistake (typo) and was still using an old datasource and thus a different user than INV. Thanks to Dmitry for making me realize this. Still not sure why I'm unable to execute the procedure from a different user using the Spring framework when I was able to do so using a basic JDBC CallableStatement. It works with the INV datasource though and that's a satisfactory solution for me

How to make Oracle error messages more verbose?

The message that drives me crazy is ORA-01008 - Not all variables bound.
Is there a way to know which one of the 42 possible variable names I have misspelled without staring at the monitor till my eyes pop out?
Update: I use ADO.NET to access the database. Perhaps it does lose some information in Oracle exceptions, as #Justin Cave has suggested. But I'm positive that the parameter name never appears even in SQL Plus.
In general, Oracle provides the line and column number of any errors, but it is up to the particular API you are using (unless you happen to be writing an OCI application, which is probably unlikely) as to whether and how those APIs are called. Since the answer is likely to end up being API-specific, what API are are you using and what does your code look like when the error occurs (i.e. JDBC, ODBC, OLE DB, etc)?
As an example, if I write a PL/SQL block with a misspelled variable name, SQL*Plus will report the line and column number of the error in addition to the error message. Many APIs, on the other hand, will just report the PLS-00201 error by default.
SQL> declare
2 i integer;
3 begin
4 j := 1;
5 end;
6 /
j := 1;
*
ERROR at line 4:
ORA-06550: line 4, column 3:
PLS-00201: identifier 'J' must be declared
ORA-06550: line 4, column 3:
PL/SQL: Statement ignored
Similarly, if you execute a SQL statement with an invalid variable name, SQL*Plus will get the column and line position and put a * under the offending character, i.e.
SQL> create table a( col1 number );
Table created.
SQL> insert into a( colN ) values ( 1 );
insert into a( colN ) values ( 1 )
*
ERROR at line 1:
ORA-00904: "COLN": invalid identifier
Most PL/SQL IDE's (TOAD, SQL Developer, etc.) will do something similar by interrogating the appropriate OCI APIs under the covers. Precisely how this is done, however, will depend on the API.
I don't know of any way to get Oracle to make the error more specific. Maybe some future version will improve this error message.
Instead of just staring at it, though, there are other things you can try. For example, convert each variable in the SQL statement to a literal one at a time, until the error goes away. If possible, generate the list of variable names instead of typing them manually.

Resources