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

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!

Related

package name is the same as another schema name in ORACLE PL/SQL, how to access another schema object? [duplicate]

Suppose I have schemas A and B.
In schema A I would like to call package X in schema B. However, there exists a package B in schema A.
A:
package B
B:
package X
When I call from schema A:
begin b.x.foo(); end
it looks for procedure X in package B, i.e. A.B.X(), and gets an error.
How can I fully qualify the call to force B to be considered a schema name?
update:
It does seem there's no way to scope the reference to refer to b.x.foo.
CREATE SYNONYM B_X for B.X works. B_X.foo() calls the procedure in schema B.
I don't think you can. From the PL/SQL User's Guide:
"The name resolution rules for PL/SQL and SQL are similar. You can avoid the few differences if you follow the capture avoidance rules. For compatibility, the SQL rules are more permissive than the PL/SQL rules. SQL rules, which are mostly context sensitive, recognize as legal more situations and DML statements than the PL/SQL rules.
PL/SQL uses the same name-resolution rules as SQL when the PL/SQL compiler processes a SQL statement, such as a DML statement. For example, for a name such as HR.JOBS, SQL matches objects in the HR schema first, then packages, types, tables, and views in the current schema.
PL/SQL uses a different order to resolve names in PL/SQL statements such as assignments and procedure calls. In the case of a name HR.JOBS, PL/SQL searches first for packages, types, tables, and views named HR in the current schema, then for objects in the HR schema."
The second bullet above applies. Since the object "B" exists in schema A, that's what the reference resolves to.
I agree with DCookie, this is a normal scoping problem. If you're in this situation though, one way to solve the issue would be to change the CURRENT_SCHEMA:
SQL> exec b.x.foo;
begin b.x.foo; end;
ORA-06550: line 2, column 9:
PLS-00302: component 'X' must be declared
ORA-06550: line 2, column 7:
PL/SQL: Statement ignored
SQL> alter session set current_schema=b;
Session altered
SQL> exec b.x.foo;
PL/SQL procedure successfully completed

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!

Oracle catldr.sql multiple errors

I'm preparing my new Oracle 11g install for "Direct" SQL*Loader operation. As per the documentation here:
http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_modes.htm#i1007669
To prepare the database for direct path loads, you must run the setup script, catldr.sql, to create the necessary views. You need only run this script once for each database you plan to do direct loads to.
So I execute the following sql script:
$ORACLE_HOME/rdbms/admin/catldr.sql
Problem is, when I run this script I get multiple errors. E.g. (and there are a lot more than this, stuff about circular synonyms too):
grant select on gv_$loadistat to public
*
ERROR at line 1:
ORA-04063: view "SUKLTI.GV_$LOADISTAT" has errors
create or replace view v_$loadpstat as select * from v$loadpstat
*
ERROR at line 1:
ORA-01731: circular view definition encountered
Synonym created.
grant select on v_$loadpstat to public
*
ERROR at line 1:
ORA-04063: view "SUKLTI.V_$LOADPSTAT" has errors
create or replace view v_$loadistat as select * from v$loadistat
*
ERROR at line 1:
ORA-01731: circular view definition encountered
Synonym created.
grant select on v_$loadistat to public
*
ERROR at line 1:
ORA-04063: view "SUKLTI.V_$LOADISTAT" has errors
from x$kzsro
*
ERROR at line 15:
ORA-00942: table or view does not exist
And then when I try to run SQL*Loader with "direct=true" I receive the following errors:
ORA-26014: unexpected error on column SYS_NTEOzTt73hE9LgU+XYHax0tQ==.DUMMYCOL NAME
while retrieving virtual column status
ORA-01775: looping chain of synonyms
Note this was a clean Oracle install with some XML schema registered(8) and tables generated off the back of the schema.
Any ideas?
The catldr.sql script says:
Rem NAME
Rem catldr.sql
Rem FUNCTION
Rem Views for the direct path of the loader
Rem NOTES
Rem This script must be run while connected as SYS or INTERNAL.
From the error messages you seem to have run it as your normal user, SUKLTI, rather than as SYS. The documentation you linked to also stated it should be run once per database - not once per end-user.
It should have been run during database creation anyway, via the catalog.sql script, so I'm surprised you need to run it manually at all; and some of the errors suggest the objects it creates did already exist. Through re-running it as SYS doesn't really look like it should hurt.
You can see which objects have been created by querying:
select object_type, object_name
from all_objects
where created > time_just_before_you_ran_the_script
You may need to cross-reference public synonyms with the all_synonyms view to check the table owner, and drop any objects it created from the SUKLTI schema as well as those new public synonyms. (But don't drop anything from the SYS schema...)
You may then need to re-run catldr.sql as SYS to recreate those synonyms pointing to the correct SYS objects.
#AlexPoole
You are completely correct. The script had to be run as SYS.
As this was a "test db" we tore it down and ran the script as SYS at DB re-creation time.
Everything now working!
thanks for reply

"PL/SQL: Statement ignored" error in Java

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

Why can't execute SCHEMA_NAME.PACKAGE_NAME.PROCEDURE, Oracle

I have a schema A, Package B and Procedure C. B is in A schema and C is in B's Package Body.
It works fine when I say:
Begin
Exec B.C;
END;
But it throw an error when I say:
Begin
Exec A.B.C;
END;
Error report:
ORA-06550: line 2, column 12:
PLS-00302: component 'B' must be declared
ORA-06550: line 2, column 4:
PL/SQL: Statement ignored
I log in as A so it's in A's schema.
and
SELECT * FROM user_OBJECTS WHERE OBJECT_NAME = 'B';
shows package and package body both valid.
I had the same problem and found the issue. I will write here the answer to close this problem and help other people.
In my case, my user A have execute privilege on a procedure B(just a procedure, not a package, but it's the same). When the user tries to run:
Begin
Exec A.B;
END;
Get the error:
ERROR at line 2:
ORA-06550: line 2, column 7:
PLS-00302: component 'B' must be declared
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
Problem: That's because a public synonym with name A was created in the database. This is an old database and I am just the DBA, not the developer, but in this case the developer was an uninspired developer. He used 4 types of objects with the same name: user, table, tablespace and public synonym. A public synonym named A in front of a table named A.
Solution: Because you don't know exactly who is using that public synonym I had to found another solution instead of deleting the public synonym. I created a private synonym for that procedure. Now the user can skip the owner of procedure in the execution code and ignore the public synonym. This problem appears in Oracle Database 10.2.0.4.
Begin
Exec B;
END;
PL/SQL procedure successfully completed.
Conclusion: Never use a public/private synonym with the name of the schema.
Hope to help someone. If I didn't made myself clear, please leave a comment.
Fix syntax error in the package, this is a generic PL/SQL compile error message.
Check error points (line 2, column 12) in the PL/SQL where the syntax error occurred, correct it and then try recompiling your code.
Component 'B' must be declared.
After that grant EXECUTE_CATALOG_ROLE to allow user 'A' execute privileges for packages and procedures in the data dictionary.
grant EXECUTE_CATALOG_ROLE to A;

Resources