Drop Database called "User" from Oracle - oracle

Ok this is what happend...
One of my colleges run a script that created some tables which included one table called "User" on an Oracle XE 10g. Now we are unable to drop that table, we get an ORA-00903 every time we run a:
DROP TABLE USER CASCADE CONSTRAINTS
The same happens when ever we try to run any alter query on it (that means renaming doesn't work)
Do someone know how to deal with this?

have you tried fully qualifying with quotes:
drop table "myschema"."user"

Randy is right suggesting quoted identifiers. Note however that quoted identifiers are case-sensitive.
First, query ALL_TABLES or USER_TABLES to find the case-sensitive name of that table, and use that name in a statement such as
DROP TABLE "User";
or
ALTER TABLE "User" RENAME TO TBL_USERS;

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.

How to remove a strange table named "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0" from oracle database?

I am new to Oracle and for practice I have created some tables (customer, drivers, payment, booking, location, area, job, job_history) in Oracle 11g and upon select * from cat statement I have found a strange table with other created tables named "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0".I don't know why this table is created.
I tried to remove this table through
drop table BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0;
but it gives error:
drop table BIN$c+*eOnMB3RbKSEfg/rsxtAQ==$0
ERROR at line 1: ORA-00933: SQL command not properly ended
what should I do to remove it?
What you see is a deleted table in the RECYCLEBIN
You may get the original name of the table with this query
SELECT original_name FROM RECYCLEBIN where OBJECT_NAME = 'BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0';
Note that (with your parameter setting) if you DROP a table it is not completely removed, but moved in the recyclebin.
You may ommit this using the PURGE option.
DROP TABLE xxx PURGE;
To remove the table from the recyclebin you must qoute the name with double quotes (as this is not a valid name) and use the PURGE statement (not a DROP - which would trigger ORA-38301: can not perform DDL/DML over objects in Recycle Bin).
PURGE TABLE "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0"
Alternatively you may use the original_name obtained with the query above:
PURGE TABLE {your_original_name};
To clean up the recyclebin completely use this statement (with the propper table user)
PURGE RECYCLEBIN;

Oracle does not allow to create "USER" table

Oracle is not allowing to create USER table.
Can anyone guide me to create USER table in Oracle.?
TIA.
Can you use a different name like my_user or something else. If you are insistent about using the table name user then you will have to provide the table name in quotes.
CREATE TABLE "USER"
(
col1 NUMBER(10)
)
You, will have to use quotes and maintain the upper case when doing any operations on this table.
The following will give you an error.
select * from USER;
ORA-00903: invalid table name
However, the following will work.
select * from "USER";
That said I don't recommend this option and it would be good if you can change your table name.
USER is a reserved keyword in oracle. Thus it can't be used directly.
Here is the list of restricted keywords a.k.a reserved words.
e.g. you can't either create a table called TABLE...

Moving dependencies (PK, FK and indexes) from one table to another within the same database in Oracle

Please tell me how can I move dependencies (such as PK, FK and indexes) from one table to another within the same database in Oracle? The second table is a copy of the first, only created later for partition reasons. Thank you in advance! :)
You could look at using the dictionary views in oracle, specifically the USER_CONSTRAINTS view. Then either construct a SQL statement dynamically or use DBMS_METADATA.get_ddl procedure to get the ddl for the constraint. You could do a REPLACE on the SQL to replace the original table name and constraint name with a new constraint name and the name of the new table.

Using sql oracle to add a foreign key

I'm trying to add a key from my customer table to my reservation table in oracle.
However I keep getting an error message when I try to run my SQL commands which states 'Customer_ID is an invalid identifier'.
What I am trying to do is first use an alter statement to alter the reservation table.
Then I am adding a foreign key, which is called 'Customer_ID'
Then I enter a references statement, which tells it that I am getting the CUSTOMER_ID attribute from the customer table. However to sql this doesn't make sense at all.
To me, logically it makes sense, I don't see anything wrong with the syntax or structure of the statements. Any sharp eyes/minds to help me on this matter would be greatly appreciated.
the statements used are:
ALTER TABLE reservation
ADD FOREIGN KEY (Customer_ID)
REFERENCES Customer(Customer_ID);
There's nothing wrong with your syntax; I was able to create simple one-column tables with the appropriate names then execute exactly the statement you posted. So I suspect the column CUSTOMER_ID does not exist in one or the other table. Describe the two tables and double-check the column names. Keep in mind that normally column names in Oracle are case-insensitive, but they can be case-sensitive if enclosed in double quotes; this can be a reason for a non-obvious column name mismatch.

Resources