Steps to restore one table from impdp in oracle 10g - oracle

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.

Related

How to create Oracle event trigger that will log table creations

I am trying to write a trigger that fires after user creates a new table, and logs the creation of table into an audit table.
I have the below starter code:
CREATE OR REPLACE TRIGGER create_table_trigger
AFTER CREATE
ON SCHEMA
BEGIN
INSERT INTO TABS_MODS (ID,ACTION) VALUES (1, 'CREATE TAB');
END;
TABS_MODS is a global temporary table like below:
CREATE GLOBAL TEMPORARY TABLE TABS_MODS (
id NUMBER,
action VARCHAR2(20)
) ON COMMIT PRESERVE ROWS;
But on creating table I am not seeing anything in the TABS_MODS table.
Use Oracle's built-in auditing features to do this. Audit the "CREATE TABLE" and "CREATE ANY TABLE" privileges. You didn't specify which version of Oracle you're using, but you can start here and search for more version-specific examples if you need them: https://docs.oracle.com/database/121/DBSEG/auditing.htm

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.

How to create a temporary table in ORACLE with READ ONLY access

I am using CREATE GLOBAL TEMPORARY TABLE script to create a temporary table in the oracle DB but its showing SQL Error: ORA-01031: insufficient privileges. I Want to create a temp table with Read only access. Plz help me out in this.
What we are trying to achieve is:
We have to create a table in the destination database which is always GreenPlum.
In source database(Oracle) we are getting a select query from the USER for example: "select * from ABC A join DEF D on A.Col1=D.col1" then we are creating TEMP TABLE(In case of Oracle) on top of it for example "CREATE GLOBAL TEMPORARY TABLE table101 AS (select * from ABC A join DEF D on A.Col1=D.col1)".
Then using this TEMP table we get the required information from INFORMATION_SCHEMA for example "select * from ALL_TAB_COLUMNS where table_name='table101' ".By this we will get the column_name,data_type,character_maximum_length etc information. Using this information we can get "create table Statement" using Javascript .
Then we store this Create table statement in a variable & run it in Execute Row script(Step in pentaho data integration tool) which will create the Table in the destination DB.
Problem is that we have read only access in oracle. now what to do.
NOTE: In short, we are creating a table in the destination DB using the select statement from the source DB. Means structure of the table in Dest DB depends on the select query in Source DB.
If the target database is also an oracle database then you should be able to set up a database link there to the source database and use a "CREATE TABLE AS SELECT * FROM +source table+#+database link+;"
Whoops, I just noticed that this is from 2014. Oh well, maybe it well help future inquirers.

How to convert a temporary table to permanent table in Oracle and vice versa

I would like to know which is the command to convert a temporary table to permanent table in Oracle.
Other issue is about the index. An index used in a temporary table will be the same used in a permanent table, if I convert it?
You can't convert a table from a temporary table to a permanent table.
You can create a new permanent table that matches the structure of the temporary table
CREATE TABLE new_permanent_table
AS
SELECT *
FROM old_temporary_table
WHERE 1=0;
Or you could get the DDL for the temporary table using the DBMS_METADATA package and manually edit the DDL to create the new permanent table.
Then you can create whatever indexes you would like on the new permanent table and drop the old temporary table. Once the old temporary table is dropped, you can rename the permanent table to use the name of the old temporary table if you would like.

oracle - how to copy partitioned table to a new schema on new tablespace

I created a datapump export (Oracle 11g) from SCHEMA A on a partitioned table (tablespace TEST``) usingTABLE=MYPARTTBL:MYPART`.
I created a new schema SCHEMA B and imported the dump of SCHEMA A's partitioned table with success, but it created the table using the same tablespace TEST.
What I need to do is import the partitioned table to a different tablespace TEST_NEW.
What's a good way to do this? Considering now, that I have a copy of SCHEMA A's partitioned table in SCHEMA B.
Here's my export parfile parameters:
DIRECTORY=DW_PUMP
TABLES=MRA.FACT_USE:P_20111009
DUMPFILE=MRA.TBLPART-20111209.dmp
LOGFILE=MRA.TBLPART-20111209.log
Use the REMAP_TABLESPACE parameter when importing:
REMAP_TABLESPACE=TEST:TEST_NEW

Resources