How can I use synonyms for reference of object type in table?
I am using an object type in my table. I want to access the table from different user using a synonym.
I have one table EMP (empid number, audit_trail audit_trail_obj) where audit_trail_obj is an Oracle object type embedded in EMP table.
Now if I want to access the same table from different user thru a synonym, what should be the process to do so?
Thanx in advance,
What was the problem?
You can just create a synonym as
create synonym xyz for EMP;
I'm a JOLE(JavaOracleLinuxEnthusiast)
--- Everything was meant to be
I don't know all the names of your objects and schemas so it's difficult to explain so here's an example:
The object and table owner is DEV and the other schema that will access the table and object is SCOTT:
Connect as DEV:
create type test1_type as object (id number(10), description varchar2(50));
create table test1_tab (
grant select, insert, update, delete on test1_tab to scott;
grant execute on test1_type to scott;
Connect as SCOTT:
create synonym test1_tab for dev.test1_tab;
create synonym test1_type for dev.test1_type;
insert into test1_tab(id, test1_col) values (1, test1_type(1, 'ONE'));
This should explain how you need to approach it. If lots of schemas are going to need access to this table you may want to substitue the synonym for a public synonym. This saves you defining it for each referencing schema.
It does not work.
When insert the record in the table from scott, Oracle gives the error - Invalid column name.
I've just tried again. If I cut and paste my example as I said it works perfectly. I think you must be typing something wrong. Make sure you grant execute on the type or you will not be able to use the type constructor in the insert.
I've just tried again. But same problem again occur.
SQL> connect bank/bank@hclinf011
SQL> create type test1_type as object (id number(10), description varchar2(50));
SQL> create table test1_tab (
2 id NUMBER(10),
3 test1_col test1_type);
SQL> grant select, insert, update, delete on test1_tab to bank_app;
SQL> grant execute on test1_type to bank_app;
SQL> connect bank_app/bank_app@hclinf011
SQL> create synonym test1_tab for bank.test1_tab;
SQL> create synonym test1_type for bank.test1_type;
SQL> insert into test1_tab(id, test1_col) values (1, test1_type(1, 'ONE'));
insert into test1_tab(id, test1_col) values (1, test1_type(1, 'ONE'))
ERROR at line 1:
ORA-00904: invalid column name
I'm assuming the * was originally under the test1_type(1, 'ONE') reference in the insert statement. I'd try a couple of things next:
1) Try the insert in the owners schema to check it works OK.
2) Try the insert in the app schema without using the synonym. Instead use the schema to prefix it :bank.test1_type(1, 'ONE').
What version of Oracle are you using?
As per your two suggetion, it will work perfectly.
But I want to access the table(Oracle object type embedded) from different user without using schema name.
It is possible....
Oracle Version - 126.96.36.199.0
Well it definitely works in 9i, and I'm sure I've seen it work OK in 8i also, although I'm not able to prove this at the moment. I wonder if there is some problem with synonyms on objects in your version.
You should raise a TAR on metalink and check if there is a problem with your version. You may need to apply a patch to fix it. You should consider going to 188.8.131.52 anyway.
When you raise the TAR use this example as it will allow support to assess the issue alot quicker.
Click Here to Expand Forum to Full Width