Can we alter the All_objects table with the Sys user? - oracle

can we alter the all_objects table with the sys user.
can i alter it using the alter command.
or is this table read only?
I was looking into the tables and tried to alter it,but for some reason
im not able to do it.Is it coz it can only be read.

ALL_OBJECTS is a view it is based primarily on internal table SYS.OBJ$.
NEVER alter in any way the internal tables or views of the database dictionnary.
What are you trying to achieve by altering this view?

Related

Using oracle seq generator in Informatica Mapping [duplicate]

I use SQL developer and i made a connection to my database with the system user, after I created a user and made a another connection with that user with all needed privileges.
But when I try to proceed following I get the SQL Error
ORA-00942 table or view does not exist.:
INSERT INTO customer (c_id,name,surname) VALUES ('1','Micheal','Jackson')
Because this post is the top one found on stackoverflow when searching for "ORA-00942: table or view does not exist insert", I want to mention another possible cause of this error (at least in Oracle 12c): a table uses a sequence to set a default value and the user executing the insert query does not have select privilege on the sequence. This was my problem and it took me an unnecessarily long time to figure it out.
To reproduce the problem, execute the following SQL as user1:
create sequence seq_customer_id;
create table customer (
c_id number(10) default seq_customer_id.nextval primary key,
name varchar(100) not null,
surname varchar(100) not null
);
grant select, insert, update, delete on customer to user2;
Then, execute this insert statement as user2:
insert into user1.customer (name,surname) values ('michael','jackson');
The result will be "ORA-00942: table or view does not exist" even though user2 does have insert and select privileges on user1.customer table and is correctly prefixing the table with the schema owner name. To avoid the problem, you must grant select privilege on the sequence:
grant select on seq_customer_id to user2;
Either the user doesn't have privileges needed to see the table, the table doesn't exist or you are running the query in the wrong schema
Does the table exist?
select owner,
object_name
from dba_objects
where object_name = any ('CUSTOMER','customer');
What privileges did you grant?
grant select, insert on customer to user;
Are you running the query against the owner from the first query?
Case sensitive Tables (table names created with double-quotes) can throw this same error as well. See this answer for more information.
Simply wrap the table in double quotes:
INSERT INTO "customer" (c_id,name,surname) VALUES ('1','Micheal','Jackson')
You cannot directly access the table with the name 'customer'. Either it should be 'user1.customer' or create a synonym 'customer' for user2 pointing to 'user1.customer'. hope this helps..
Here is an answer: http://www.dba-oracle.com/concepts/synonyms.htm
An Oracle synonym basically allows you to create a pointer to an object that exists somewhere else. You need Oracle synonyms because when you are logged into Oracle, it looks for all objects you are querying in your schema (account). If they are not there, it will give you an error telling you that they do not exist.
I am using Oracle Database and i had same problem. Eventually i found ORACLE DB is converting all the metadata (table/sp/view/trigger) in upper case.
And i was trying how i wrote table name (myTempTable) in sql whereas it expect how it store table name in databsae (MYTEMPTABLE). Also same applicable on column name.
It is quite common problem with developer whoever used sql and now jumped into ORACLE DB.
in my case when i used asp.net core app i had a mistake in my sql query. If your database contains many schemas, you have to write schema_name before table_name, like:
Select * from SCHEMA_NAME.TABLE_NAME...
i hope it will helpful.

ORACLE Database - Why SYS User can drop tables but not columns?

I am learning PLsql with Oracle 19c. I was wondering - why sys user can drop tables but not specific columns within a table? I found this workaround, where you create a copy of the table for a specific SCHEMA, drop the column in this newly created table, drop the original table, and finally create another copy of the (copied)-table without SCHEMA/USER ROLE.
Is there another, let's say a smoother way, to accomplish this? Or is there any specific reason Oracle implemented it this way?
Thanks.
SQL> SHOW USER;
USER is "SYS"
________________________________________
SQL> ALTER TABLE employees DROP (gender);
ALTER TABLE employees DROP (gender)
*
ERROR at line 1:
ORA-12988: cannot drop column from table owned by SYS
_______________________________________
SQL> DROP TABLE employees;
Table dropped.
"To maintain the integrity of the data dictionary, tables in the SYS schema are manipulated only by the database. They should never be modified by any user or database administrator. You must not create any tables in the SYS schema."
https://docs.oracle.com/database/121/ADMQS/GUID-CF1CD853-AF15-41EC-BC80-61918C73FDB5.htm#ADMQS12003
Try to put in this order:
ALTER TABLE table_name DROP COLUMN column_name;
If the table has data it doesn't work.

ORA-00942: Table or View not exist connecting with another user

in Oracle SQL developer I got error ORA-00942: Table or View not exist connecting with another user when I do the following:
CREATE USER marta IDENTIFIED BY 'marta';
GRANT SELECT, INSERT ON myTable TO marta;
so then, executing:
CONNECT marta/marta;
INSERT INTO myTable VALUES ('1', 'foo', bar');
got the ORA-00942...
Obviusly, If I use system user I can insert row with no issues.
I searched other answers but I couldnt solve this... what is wrong
Obviusly, If I use system user I can insert row with no issues.
Uh-oh. There's nothing obvious about that. The SYSTEM user should not own a table called MY_TABLE (or whatever application table that is actually named). The SYSTEM user is part of the Oracle database, its schema is governed by Oracle and using it for our own application objects is really bad practice.
But it seems you have created a table in that schema and user MARTA can't see it. That's standard. By default users can only see their own objects. They can only see objects in other schemas if the object's owner (or a power user) grants privileges on that object to the other user.
So, as SYSTEM
grant select on my_table to marta;
Then, as MARTA
select * from system.my_table;
To avoid prefixing the owning schema MARTA can create a synonym:
create or replace synonym my_table for system.my_table;
select * from my_table;
But really, you need to stop using SYSTEM for your own tables.

Why is oracle dictionary lying to me?

In the documentation for all_constraints table it says that the "owner" column gives us information about "Owner of the constraint definition". But when examining the living example I found that to be false.
select user from dual; --gives EXAMPLE_USER
create table example_user.example_table(id number);
Now I will change user to SYS.
select user from dual --gives SYS
alter table example_user.example_table add constraint ex_constrain check(id > 10);
Now the best part:
select owner from all_constraints where constraint_name = 'EX_CONSTRAINT';
--gives EXAMPLE_USER and not SYS.
My question is simple: why?
Tested on: Oracle Database 11g EE 11.2.0.4.0
Well, SYS is special, it owns the database and can do anything.
If you wanted to do the same with another user (for example, SCOTT, and let it try to create constraint for EXAMPLE_USER's table), you'd fail unless privileged user grants SCOTT ALTER ANY TABLE system privilege. Doing so, that user will be able to alter any table (which belongs to any user), and that includes creating constraints.
If you'd want to create a primary key constraint, that privilege won't be enough - you'll need CREATE ANY INDEX privilege as well (as primary key creates index as well).
Just like CREATE ANY TABLE system privilege, which allows you to create a table in any other user's schema, but that table will then belong to the schema owner, the same goes for a constraint - yes, you created it in behalf of another user, but the constraint is still owned by the table owner, not the creator.
Therefore, dictionary isn't lying, it is you who misunderstood how it goes.

Reference a table in other schema omiting schema name

If I have a table sch1.tab1 is it possible to call it from schema/user sch2 just with
select * from tab1 (assume that we have all the privilegies)?
I am aware that in postgresql you can set the search path where db would look for tables which enables you to omit the schema when you are referencing a table but I do not know if this exists in oracle.
Thank you.
You can create a synonym, but you'd have to make one for each table you wanted to access; from sch2:
create synonym tab1 for sch1.tab1;
A more general method is to switch your current schema:
alter session set current_schema = 'SCH1';
You're still connected with your original user account and only have those privileges still, but you don't have to qualify objects in that schema any more. But now you would have to qualify any of your own tables (back in sch2), if you have objects in both schemas.

Resources