This question already has an answer here:
Creating a table from a query using a different tablespace (Oracle SQL)
(1 answer)
Closed 5 years ago.
I tried to simply create a table with the structure of another table to sync them contents later.
When is use "CREATE as SELECT", it just returns the error
ORA-00933 "SQL command not properly ended"
As mentioned in the link, the syntax should be OK.
https://www.techonthenet.com/oracle/tables/create_table2.php
Both tables should be stored in the same user scheme.
The only difference is the added user scheme and tablespace.
CREATE TABLE "MYUSER.TABLE_B"
as (SELECT * FROM "MYUSER.TABLE_A")
TABLESPACE "SANDBOX" ;
I don't have Oracle database with me now, but I am sure, you can use like this-
CREATE TABLE "MYUSER.TABLE_B"
TABLESPACE "SANDBOX"
AS
SELECT *
FROM "MYUSER.TABLE_A";
Related
This question already has answers here:
Automated Oracle Schema Migration Tool [closed]
(5 answers)
Closed 7 years ago.
Is it possible in Oracle to generate a bunch of ALTER TABLE statements based on existing table in schema plus CREATE TABLE statement with newer definition of that table?
Let's say I have a schema with some previous version of an application. I have an installation script for newest version of the application. The script creates all tables and sequences from scratch performing CREATE TABLE (and probably CREATE SEQUENCE) statements.
I'd like to update the schema to the newest version of the application without loosing any data (e.g. without performing DROP TABLE).
Is it possible with using of standard Oracle 11gR2 or third party components?
You can try CORT : www.cort.tech
https://github.com/cort-master/cort
It's free
You can create a procedure in PLSQL to:
create new table when it not exists in new DB
alter table when it exists, feeding it with ALL_TAB_COLUMNS
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.
I am trying to export data in oracle 11g
exp user/password file=dump.dmp tables = (table1)
via sqlplus.
And i get the following error:
About to export specified tables via Conventional Path ...
EXP-00011: USER.TABLE1 does not exist Export terminated
successfully with warnings.
But when i check who is the owner of this table:
SELECT owner, table_name from dba_tables where table_name = 'TABLE1';
I get that the owner of TABLE1 is USER
What should i do to export this table?
UPDATE
Actually, i found a solution. I hope it will help someone else.
Since version 11g Oracle has introduced new feature that is called deferred segment creation. Thus oracle doesn't create table segment if there are now rows in it. So i recreated my table with option 'segment creation immediate'
Actually, i found a solution. I hope it will help someone else. Since version 11g Oracle has introduced new feature that is called deferred segment creation. Thus oracle doesn't create table segment if there are no rows in it. And my table didn't contain any data. So i recreated my table with option 'segment creation immediate'
The solution was found here. There are more options how to fix the problem and an explanation why this thing happens to be in oracle 11g. :)
In addition to the posted answer from Olivia i would like to add some code:
SELECT 'alter table ' || table_name || ' allocate extent;'
from dba_tables where SEGMENT_CREATED = 'NO';
Execute the output and exp again. Your schema will be exported including empty tables.
EDIT:
similar question here, maybe you'll find your solution there.
Change this:
exp user/password file=dump.dmp tables = (table1);
to this:
exp user/password tables = (table1) file=dump.dmp;
You Can Use below query to take table level export from specific user.
exp user/password file=dump.dmp tables = user.table1
This question is related to the one I posted yesterday but with further implications.
The situation is: I'm unable to drop ANY table. Here's an example:
SQL> CREATE TABLE FOO (BAR NUMBER) TABLESPACE SYSTEM
/
Table created.
SQL> SELECT COUNT(1) FROM FOO;
COUNT(1)
----------
0
SQL> DROP TABLE FOO;
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist
ORA-06512: at line 19
So, the table seems to exist but I'm not capable of dropping it.
Notice the error ORA-00604: error occurred at recursive SQL level 1. If I try to drop a non existing table, this error does not appear:
SQL> DROP TABLE NON_EXISTING_TABLE
ERROR at line 1:
ORA-00942: table or view does not exist
Somehow, the system is unable to find the table at dropping time.
The oracle installation and the DB itself is new (one day old).
EDIT - I retried this test using another tablespace and user (I just created ones) and I got a slightly different behaviour: using SYS, after I got the DROP error I can still SELECT from the table. However, using this new user, after I got the DROP error, I no longer can SELECT from the table.
Solution
We found the problem: the MDSYS.SDO_GEOR_SYSDATA_TABLE was missing, preventing the drop operation.The solution is to restore that table. Here is the complete solution, by Gaurav Soni (by the way, many thanks).
Run the script catmd.sql (located in $ORACLE_HOME/md/admin dir).
The catmd.sql script is the script that loads all objects needed by Oracle spatial in the database. Then drop the user.
you can also refer to oracle metalinks
Steps for Manual Installation of Oracle Spatial Data Option
Dropping user results in ORA-942 against SDO_GEOM_METADATA_TABLE
I'd suggest that you activate SQL tracing (ALTER SESSION SET SQL_TRACE=TRUE;) and try the drop again. This will generate a trace file on the server (in the udump directory) that will show all the SQL the session executed, including recursive statements. This should show you the recursive SQL statement that is failing.
I think the problem is that you created the table on system tablespace. You should create it on the user tablespace or create one to store your data.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
SELECT INTO using Oracle
I have one table in my oracle database. I want to create one table with another name, but containing same data. How to achieve this ?
Use this query to create the new table with the values from existing table
CREATE TABLE New_Table_name AS SELECT * FROM Existing_table_Name;
Now you can get all the values from existing table into newly created table.