How to identify all global temporary tables - oracle

I need to identify which tables in my schema are Global Temporary Tables.
Following script returns names of all my tables, but I am not able to identify which of these are GTTs and which are not.
SELECT OBJECT_NAME
FROM ALL_OBJECTS
WHERE OBJECT_TYPE IN ('TABLE')
AND OWNER='owner_name';
Thank you!

You can use ALL_TABLES
select table_name
from all_tables
where TEMPORARY = 'Y'
AND OWNER='owner_name';
Temporary column indicates whether the table is temporary (Y) or not (N)

Related

In Oracle, how to list all the tables in *my* schema that *I* created (without having DBA privileges)

I'm an Oracle11XE user with privileges to create and drop tables and procedures. I create a few tables, then while visiting the restroom, MIB zap me with a memory wipe (I foolishly looked into the light). Returning to sit at my workstation, I realize I need to query the database with my regular user privs, and figure out what that table or tables I created and the DBA has mysteriously gone missing.
You can use USER_TABLES view to get all the tables currently in your schema:
select table_name
from user_tables
If, additionally, you are interested in knowing when the tables were created, then you can use the USER_OBJECTS view where OBJECT_TYPE = 'TABLE'. That view includes the CREATED column.
select object_name, created
from user_objects
where object_type = 'TABLE'

Oracle : How to get Last DDL Updated Time

I have tried the following SQL:
SELECT * FROM all_objects
But it also update LAST_DDL_TIME column of above table whenever any table grant is given any other schema.
I want Last DDL update time for table Alter only.
Ketan, I think DDL Triggers will solve your problems.
Find out more on this : http://www.dba-oracle.com/t_ddl_triggers.htm
If you use trigger to monitor DDL, you are essentially replicating functionality already provided through Oracle Auditing.
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_4007.htm
There is 10g-related guidance here: https://oracle-base.com/articles/10g/auditing-10gr2
You can try this:
SELECT object_name, object_type, last_ddl_time
FROM dba_objects
WHERE owner = <<table owners name>>
AND object_name = 'yourTableName'

How to specify tablespace_name in SQLPlus Oracle select

My setup looks like this
SQL> SELECT tablespace_name, table_name
FROM all_tables
WHERE tablespace_name = 'MYSPACE';
TABLESPACE_NAME TABLE_NAME
-------------------------- ------------------------------
MYSPACE MYTABLENAME
MYSPACE MYOTHERTABLENAME
Now I'd like to SELECT * FROM MYSPACE.MYTABLENAME; but that's apparently not how you do it.
ERROR at line 1:
ORA-00942: table or view does not exist
My expected result would be to get all records from that table. Like I would if it was MySQL.
Thanks
You are selecting from tablespace, which is not the same as your Owner/Schema name. Thats why. For example the tablespace SYSTEM has owner SYS. You do select from Sys.xxx;
Ok.
SELECT owner, tablespace_name, table_name
FROM all_tables
WHERE tablespace_name = 'MYSPACE';
And then
select * from [ owner ].[ table_name ];
(worth to mention: select .. from dba_tables / user_tables)
Tables are not owned by a tablespace. A tablespace is a logical storage storage structure. When you create a table (or index) you specify which tablespace its contents should be stored in. Unless you're doing DBA tasks, you don't really need to know which tablespace(s) your data is stored in.
You may just be confusing terms. Tables are owned by schemas. If you query the owner column instead of tablespace_name you might see something like:
SQL> SELECT owner, table_name
FROM all_tables
WHERE tablespace_name = 'MYSPACE';
OWNER TABLE_NAME
-------------------------- ------------------------------
MYUSER MYTABLENAME
MYUSER MYOTHERTABLENAME
And you can then query from that with
SELECT * FROM MYOWNER.MYTABLENAME;
Of course, if the owner is actually you anyway, then you don't need to prefix the table name with the schema; you can just select FROM MYTABLENAME. (You may also have synonyms or session settings that make the schema prefix unnecessary, but that's getting a a bit off-topic). And if you own the table you'll see it in USER_TABLES as well.

Extract Table(s) having name in numbers

I am using Oracle developer , my DB have 150+ tables having different namings
i Want to extract all tables having names like
tbl_1234
tbl_22
tbl_45
tbl_719
All tables whose naming convention is like " table name , underscore , number "
Pleaseee help me on this
try following query:
select table_name from user_tables where regexp_like (table_name, '_[0-9]+$');
and you can use, of course, the all_tables or dba_tables view, if you have approriate rights

How do I get all records associated with a record in an aggregate root table

For testing purposes, I would like to generate an insert script for all records in all tables associated with a particular record in one of the root tables. For example, I might have a "Participant" table, which has any number of associated entries in the "Documents" table, which in turn has any number of associated entries in the "PrintRequests" table and so on and so forth. I have hundreds of these tables in the database.
Is there any way to select/script out all the records in all tables that are associated with for example ParticipantId = 1? This way, for a representative participant, I can extract all the associated records in all the tables.
One of my ideas was to restore a back up of the full database, modify all foreign key constraints to have cascade delete and then delete everything that is not participantid = 1 and let the database take care of deleting everything that is not related to the participant of interest and then script out the entire database of what remains.
For this, I might have to drop and recreate all the constraints, which I am unsure about how to do across the entire database.
Alternately, are there any other tools that would be able to do this? A migration tool for example that can take a query and only migrate the records and associated child records of that query?
While it is entirely possible to build scripts to walk through all the primary key and foreign key constraints and, via liberal use of dynamic SQL, generate these scripts, doing so would be a non-trivial undertaking. I would strongly suspect that you would be better served using a product like DataBee to generate your data subset.
You can script it creating dynamic SQL statements, but I think it is really lots of work. I think you will be faster to just find all the tables with a column "ParticipantId" with something like this
select * from all_tab_columns where column_name = 'PARTICIPANTID'
And then do some fast edit / replace / other sort of script action to generate yourself the delete statements.
Regarding the constraints. This is similar. Getting all the constraints with
SELECT owner, table_name, constraint_name
FROM dba_constraints
where table_name in (select table_name from all_tab_columns where column_name = 'PARTICIPANTID')
You switch on and off constraints using
ALTER TABLE <table name> ENABLE/DISABLE constraint <constraint name>;
Maybe this you could do with a loop. Borrowing from this page
begin
for i in
(select constraint_name, table_name from user_constraints where table_name in (select table_name from all_tab_columns where column_name = 'PARTICIPANTID')
) LOOP
execute immediate 'alter table '||i.table_name||' disable constraint '||i.constraint_name||'';
end loop;
end;
I am not sure about your cascading delete thing but the above gives a bit an idea how the delete would look like:
begin
for i in
(select constraint_name, table_name from user_constraints where table_name in (select table_name from all_tab_columns where column_name = 'PARTICIPANTID')
) LOOP
execute immediate 'delete from '||i.table_name||' where participantid = ''1'' ';
end loop;
end;
Hope it helps.

Resources