Schema name vs. table name - how to avoid conflicts?
I've to solve a problem using Oracle database.
In Oracle database there are two schemas: XXX and YYY
The schema XXX contains a table named YYY (the same name as the second schema).
The schema YYY contains some sequences (let's say sequence ZZZ) and log tables, which I need to use by triggers in schema XXX.
But when I try to write trigger over table XXX.some_table using this construction:
SELECT YYY.ZZZ.NEXTVAL INTO AAA FROM DUAL
Oracle considers YYY as table in XXX schema and show error message "component ZZZ must be declared". There are appropriate rights set for XXX user to access YYY.ZZZ sequence, but it is useless.
How to avoid this? Unfortunately the structure of 开发者_如何学运维database is set and can't be changed.
You can write trigger code, so you have some control over the database. That's good.
I suggest you use synonyms to work arround this:
create synonym yyy_zzz_seq for yyy.zzz;
You should then be able to reference the synonym in your trigger:
SELECT yyy_zzz_seq.NEXTVAL INTO AAA FROM DUAL
精彩评论