Oracle 12c, export table with sequence as default value, schema is attached - oracle

I'm use oracle 12c with a user u1. With user u1 I create table T1 like this,
create SEQUENCE T1_SEQ START WITH 1;
CREATE table T1(
id number(11) DEFAULT T1_SEQ.nextval PRIMARY KEY ,
name varchar2(255)
);
Now I want to export the schema to others, and use below command to export
expdp u1/password dumpfile=u1.dmp schemas=u1
, but when others use u1.dmp to import the schema with a new user named u2,
impdp u2/password remap_schema=u1:u2 DUMPFILE=u1.DMP TABLE_EXISTS_ACTION=REPLACE
error happend, beacause default value of table T1 column id add U1 as prefix.
U1.T1_SEQ.nextval
and here is the new create table statement
CREATE table T1(
id number(11) DEFAULT U1.T1_SEQ.nextval PRIMARY KEY ,
name varchar2(255)
);
How can I remove the U1's influence while I want to move one schema to another schema.
Could you give me some suggestions? Thanks in advance!.

this is a known and ongoing issue according to Ask Tom.
So You can,
excluding the affected objects from the import
using the sqlfile option to import the affected objects
amending the sqlfile script output to point to the correct objects before running it
Please See relevant topic

Related

Oracle backup with SEQUENCE-ID Column

Good morning,
I allready know how to do oracle backups with expdp and impdp. It is also no problem for me to remap backups from one schema to an other.
But know I have something where I find no solution to solve it.
I have a table with an ID column. This column has a default value based on a sequence.
CREATE TABLE "TABLE_NAME"
( "ID" NUMBER(*,0) DEFAULT "TABLE_NAME_ID_SEQ"."NEXTVAL",
"KEY" VARCHAR2(200 BYTE),
"VALUE" CLOB
)
After executing thise statement Oracle defines this default with "MY_USER"."TABLE_NAME_ID_SEQ"."NEXTVAL".
This is not an issue until I try to uses the backup with a different schema name. The REMAP_SCHEMA parameter of impdp seems only to change the schema definition in the tabelnames but not in the default values. So the imported backup creates a table with a default values which references to a wrong schema.
How could I solve this?
Best regards"

After adding index global temporary table data will not get fetched

Need some help to identify the reason for the below issue.
I have created a global temporary table as below:
Create global temporary table glo_temp_table
(
row_no NUMBER not null,
resource_id VARCHAR2(40),
company_id VARCHAR2(20),
);
This table’s data gets inserted during the runtime by a function which later used by a another function to fetch data using a cursor. This functionally works fine without any issue. Problem starts when I add an index below (to clear this is not done during the run time.):
CREATE INDEX SS ON glo_temp_table (resource_id);
Now no data will gets fetched by the cursor. Is there any specific reason for this behavior? How can I created a such a index to work properly?
Oracle db veriosn is 12c Release 12.1.0.1.0
This table only has the below constrain only.
alter table glo_temp_table
add constraint glo_temp_table_PK primary key (ROW_NO);

Steps to restore one table from impdp in oracle 10g

I need to import only one table from a full backup (expdp) to a newly create table on the same database.
So can i import the table directly with a new name? or i have to create a new table first with the same parameters then import?
impdp hr DIRECTORY=dpump_dir1 DUMPFILE=expschema.dmp TABLES=hr.employees REMAP_TABLE=hr.employees:emps
Another question will remap_table effect my already exist employees table? or it will only create a new table called emps and import the data of employees from the dump to it?
...................... Update ......................
I found that there is no remap_table in oracle 10g so can i use this method:
create user johny identified by 1234;
grant create session to johny;
impdp system/****** DIRECTORY=dpump_dir1 DUMPFILE=expschema.dmp LOGFILE= tb_imp.log TABLES='HR.employees' REMAP_SCHEMA=HR: johny;
We need the table temporarily only so i can drop johny later. also the above method will not effect the original employees table in the hr schema , right?
Oracle will import the table employees from your dump file and remame it to emps, if an employees table exists it will not be affeted, if the emps table already exists it will not do anything.
You can change the behavior when a table exists by using the table_exists_action parameter either specifiying:
TRUNCATE => truncate the table if exists and import data from the
dump
REPLACE => will first replace the table with the definition
from the dump and then import the data
APPEND => will append the
data to the table leaving the existing data in.

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...

How to create new schema and list all schema name in oracle

I want to create one new schema in oracle and I used sample code, which is available here
CREATE SCHEMA AUTHORIZATION oe
CREATE TABLE new_product
(color VARCHAR2(10) PRIMARY KEY, quantity NUMBER)
CREATE VIEW new_product_view
AS SELECT color, quantity FROM new_product WHERE color = 'RED'
GRANT select ON new_product_view TO scott
/
But, getting error
ERROR at line 1:
ORA-02421: missing or invalid schema authorization identifier
Also, Please help me how to list name of all available schema. I am using
select username from dba_users;
to list schema, but i think, its not a right approach, because, user and schema has many-to-many relation,which means I can't get all schema name here.
Please help me !!
From oracle documentation:
This statement does not actually create a schema. Oracle Database
automatically creates a schema when you create a user
So you first need to create a User with the schema name
As for your query it's fine, since username list is equal to schema names unavailable
UPDATE: I can't really test it now, but should be something like this:
CREATE USER oe IDENTIFIED BY oePSWRD;
CREATE SCHEMA AUTHORIZATION oe
CREATE TABLE new_product
(color VARCHAR2(10) PRIMARY KEY, quantity NUMBER)
CREATE VIEW new_product_view
AS SELECT color, quantity FROM new_product WHERE color = 'RED'
GRANT select ON new_product_view TO scott;
From the docs: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_6014.htm
The schema name must be the same as your Oracle Database username.
Do you want to find all users, or all users for which a table (for example) exists? If the latter then ...
select distinct
owner
from
dba_tables
where
owner not in ('SYS','SYSTEM')
Add in other usernames that you're not interested in listing as required.

Resources