I use dbms_metadata.get_ddl(...) to get object ddl but it is not generate ddl for column.
is there way to get column ddl oracle 12 version?
thanks
I think following query may usefull for you.
SELECT *
FROM ADMIN.DDL_HISTORY_LOG L
WHERE L.OBJECT_TYPE = 'TABLE'
AND L.DDL = 'ALTER'
AND L.OBJECT_NAME = 'TABLE_NAME' --just change table name here
AND UPPER(L.DDL_SQL) LIKE '%ALTER%TABLE%ADD%'
AND UPPER(L.DDL_SQL) NOT LIKE '%ADD%CONSTRAINT%'
this oracle dictionary is holding all historic DDL statements. so, If you specify your table name, you can get all DDL statements for this table in the past.
Related
I have few databases and all the databases have the same tables (i.e. table names). Now i want to get the DDL of the table with different schema.
Use the dbms_metadata package to get the DDL of any object of the DB.
SELECT
DBMS_METADATA.GET_DDL('<Object type>', '<Object name>', '<object schema>')
FROM
DUAL; -- How to
SELECT
DBMS_METADATA.GET_DDL('TABLE', 'MY_TABLE', 'MY_SCHEMA')
FROM
DUAL; -- In your case use something like this
Also, You can format the output using dbms_metadata.set_transform_param.
See Oracle documentation for more information on it.
Cheers!!
I put this code into SQL Developer's Worksheet:
CREATE TRIGGER T_testDSNa
before INSERT
on testDSNa
referencing new as new
for each ROW
BEGIN
SELECT S_testDSN.nextval INTO :NEW.SYSID FROM dual;
END;
I get this:
Error report -
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Would anyone know why? This has worked for 3 previous tables until I tried to run the DDL to create a 4th. Alternatively, is there a better way to set up an autoincrementing PK?
The problem was lack of schema. Oracle Definition of a schema :
Collection of database objects, including logical structures such as
tables, views, sequences, stored procedures, synonyms, indexes,
clusters, and database links. A schema has the name of the user who
controls it.
If you want to know the objects accessible without alias. You have to look on [USER_OBJECTS]. Which describes the relational objects owned by the current user :
SELECT
OBJECT_NAME
, OBJECT_TYPE
, LAST_DDL_TIME
FROM USER_OBJECTS;
If you want to know the objects accessible to the current user :
SELECT
OWNER
, OBJECT_NAME
, OBJECT_TYPE
, LAST_DDL_TIME
FROM ALL_OBJECTS;
In your case to see your objects in the list of available tables you need:
SELECT * FROM ALL_OBJECTS WHERE OWNER = 'USER';
You can also alter the session to avoid alias :
ALTER SESSION SET current_schema = User;
For priviliges/ roles views you can look at :
SELECT * FROM USER_SYS_PRIVS;
SELECT * FROM USER_ROLE_PRIVS;
The last method but not the most secure to avoid alias. Is to log on with a user that has the same name as the schema.
Hoping that it can help
I was getting the same issue.
Solution: What I observed that my table which I created was surrounded by double quotes, which made it case sensitive.
So for each time I refer to my table, I need to surround it by double quotes.
CREATE TRIGGER T_testDSNa
before INSERT
on "testDSNa"
referencing new as new
for each ROW
BEGIN
SELECT S_testDSN.nextval INTO :NEW.SYSID FROM dual;
END;
refer this link: What exactly do quotation marks around the table name do?
I want to create a table (lets say table_copy) which has same columns as other table (lets call it table_original) in Oracle database, so the query will be like this :
create table table_copy as (select * from table_original where 1=0);
This will create a table, but the constraints of table_original are not copied to table_copy, so what should be done in this case?
Only NOT NULL constraints are copied using Create Table As Syntax (CTAS). Others should be created manually.
You might however query data dictionary view to see the definitions of constraints and implement them on your new table using PL/SQL.
The other tool that might be helpful is Oracle Data Pump. You could import the table using REMAP_TABLE option specifying the name for the new table.
Use a database tool to extract the DDL needed for the constraints (SQL Developer does the job). Edit the resulting script to match the name of the new class.
Execute the script.
If you need to do this programmatically you can use a statement like this:
DBMS_METADATA.GET_DDL('TABLE','PERSON') from DUAL;
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
Sounds pretty easy query the column names from a table, right? Indeed there is a answer to this question How can I get column names from a table in Oracle?
The main issue is that the table belongs to another user. My user is just for integration and I don't have any database privileges.
So I'm able to do some query like: SELECT * FROM anotherUser.THE_TABLE;
But something like SELECT * FROM USER_TAB_COLUMNS return no rows.
Perhaps I can create queries over all_tab_columns, Are there another faster options without procedures?
*It´s a oracle database!
SELECT *
FROM ALL_TAB_COLUMNS
WHERE OWNER='ANOTHERUSER'
AND TABLE_NAME='THE_TABLE';
Should get you there if you have privileges on the table.