Newly Added Column is not Appearing in Synonym - sql

I have a table named YY_ZZ_VAT_TRX_DETAILS under the XX schema.
It has an existing SYNONYM to AA schema.
I am currently logged in as AA and I wanted to add a column to YY_ZZ_VAT_TRX_DETAILS and executed the below command just fine
alter table XX.YY_ZZ_VAT_TRX_DETAILS
add (USER_DEFINED_FISC_CLASS VARCHAR2(30));
Table XX.YY_ZZ_VAT_TRX_DETAILS altered.
I tried to select the Column from the Table using the simple query below
select USER_DEFINED_FISC_CLASS
from YY_ZZ_VAT_TRX_DETAILS;
But I surprisingly got this error:
ORA-00904: "USER_DEFINED_FISC_CLASS": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action: Error at Line: 1 Column: 9
I thought I just missed altering the table, so I re-ran the ALTER script again, but got this error instead:
Error starting at line : 4 in command - alter table
XX.YY_ZZ_VAT_TRX_DETAILS add (USER_DEFINED_FISC_CLASS VARCHAR2(30))
Error report - ORA-01430: column being added already exists in table
01430. 00000 - "column being added already exists in table"
*Cause:
*Action:
I checked the Object Definition and sure enough, I found the new column there:
But when I query all the columns from the Table, I still can't see it:
select *
from YY_ZZ_VAT_TRX_DETAILS;
However, when I query using the XX schema prefix, I'm able to see the column:
select *
from XX.YY_ZZ_VAT_TRX_DETAILS;
Why isn't the synonym picking up the newly-added column?

It seems this was caused by this "Edition-Based Redefinition" thing that Oracle recently introduced for 12c.
Upon further investigation, what happened was:
The Table XX.XX_ZZ_VAT_TRX_DETAILS has a Editionable view named XX_ZZ_VAT_TRX_DETAILS# that only selects a certain number of columns.
Now, the View XX_ZZ_VAT_TRX_DETAILS# has a SYNONYM named XX_ZZ_VAT_TRX_DETAILS under the schema AA, hence the confusion on the Table having a SYNONYM of the same name.
To resolve this, i modified the view XX_ZZ_VAT_TRX_DETAILS# and added the new column and successfully recompiled it.
Once this was done, the synonym now shows the newly-added column and I was able to compile the stored procedure successfully.

I believe you could be having a table or a view called YY_ZZ_VAT_TRX_DETAILS or a private synonym that points to another table?.
In oracle the preference while querying is
1)objects_in same schema
2)private synonym
3)public synonym

Related

Moving a table from one schema to another in Exasol

I am trying to move a table which resides in a certain schema to a different schema with the same table name. I have tried the following but they do not work:
rename <OLD_SCHEMA_NAME>.<TABLE_NAME> TO <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: invalid identifier chain for new name [line 1, column 100] (Session: 1722923178259251200)
and
ALTER TABLE <OLD_SCHEMA_NAME>.<TABLE_NAME> RENAME <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: syntax error, unexpected IDENTIFIER_PART_, expecting COLUMN_ or CONSTRAINT_ [line 1, column 62] (Session: 1722923178259251200)
Many Thanks!
According to Exasol documentation there is no way to move table between schemas using RENAME statement:
Schema objects cannot be shifted to another schema with the RENAME
statement. For example, 'RENAME TABLE s1.t1 TO s2.t2' is not allowed.
I would move the table this way:
create table <NEW_SCHEMA_NAME>.<TABLE_NAME>
like <OLD_SCHEMA_NAME>.<TABLE_NAME>
including defaults
including identity
including comments;
insert into <NEW_SCHEMA_NAME>.<TABLE_NAME>
select *
from <OLD_SCHEMA_NAME>.<TABLE_NAME>;
drop table <OLD_SCHEMA_NAME>.<TABLE_NAME>;

Insert table from one database into another database

I want to copy a table to another database server in SQL developer.
I use this method to solve this problem.
INSERT INTO mahdi-jiradb..empier SELECT * FROM tamindb..users;
but i get an error:
Error starting at line : 8 in command -
INSERT INTO mahdi-jiradb..empier
SELECT * FROM tamindb..users
Error at Command Line : 8 Column : 18
Error report -
SQL Error: ORA-00926: missing VALUES keyword
00926. 00000 - "missing VALUES keyword"
*Cause:
*Action:
What should i do?
As you commented, it looks as if you use Oracle.
In that case, schema name can't contain a "minus" sign (mahdi-jiradb) so that's probably underline (mahdi_jiradb) instead.
SQL> create user mahdi-jiradb identified by test;
create user mahdi-jiradb identified by test
*
ERROR at line 1:
ORA-00922: missing or invalid option
Unless, of course, you enclosed username into double quotes (but now you have to use it always, everywhere):
SQL> create user "mahdi-jiradb" identified by test;
User created.
Presuming that that's not the case, schema name is wrong. Check it.
Also, use one dot to separate schema name from table name.
Something like this might work:
INSERT INTO mahdi_jiradb.empier SELECT * FROM tamindb.users;
presuming that both tables share the same description. That's why it is better to explicitly name all columns involved, e.g.
INSERT INTO mahdi_jiradb.empier (user_id, user_name)
SELECT uid, uname FROM tamindb.users;

I'm trying this query to change attribute name

alter table car
rename column office-id to office_id
Why is it giving out "missing to keyword" error?
This seems to be a potential solution:
Error trying to rename columns with space in oracle table. Error - SQL Error : ORA- 00946 : missing TO keyword
alter table car rename column "office-id" to office_id
You'll likely need to enclose the column name in quotes
alter table car rename column "office-id" to office_id
Also you don't specify the dialect (the db is it Oracle, MS SQL, Postgres?)

Can only find table in Oracle SQL when surrounding the table name with double quotes. Why?

I'm having the following weird issue with Oracle SQL. I have a table called schema_version, but I can't run simple selects over it:
> SELECT * FROM schema_version;
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 1 Column: 15
Now if I attempt to run the very same query but this time surrounding the table name with double quotes everything seems to run fine:
> SELECT * FROM "schema_version";
< results are shown >
From what I've read # https://stackoverflow.com/a/7425931/130758 I should be okay not using double quotes. What may I be missing? Thanks
If the table was created as
CREATE TABLE "schema_version" (...)
its name is stored in the catalog in the exact (lower) case. When you reference the name unquoted:
SELECT * FROM schema_version;
the name is converted to the upper case by default, so the table cannot be found. When you reference the name quoted:
SELECT * FROM "schema_version";
the table name is used as is (in lower case) and matches that in the catalog.

Rename column with reserved word as column name; Works on one, fails on another

I'm renaming two columns in two tables, both of which are named LEVEL, which is a reserved word.
What is confusing me greatly is that I am running an identical command on both these tables, but only one of them is failing. Here are the commands:
--this works
ALTER TABLE notificationsubscriptions RENAME COLUMN "LEVEL" TO nlevel;
--this doesn't
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel;
The second statement results in the following error:
Error starting at line : 9 in command -
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel
Error report -
SQL Error: ORA-00900: invalid SQL statement
00900. 00000 - "invalid SQL statement"
*Cause:
*Action:
Both these columns are of the same datatype (number). I am baffled - Why would this command work for one of these tables but not the other?
The database is running Oracle 10.2.
Try to remove any links that exist on this column from indexes and/or foreign key constraints
Drop indexes
Rename column
Create indexes with the new name of column