Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, mrunmayi.

Asked: October 15, 2015 - 6:50 am UTC

Last updated: October 13, 2018 - 4:20 am UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

Hello,

i want session specific data for my current requirement. i am doing some calculations so i need that data only. at a time multiple users can use screen and do operations so i am using GTT. i have created GTT and created index on that GTT. my screen is search screen so i have to create index on GTT otherwise its taking too much time to display data and its consuming more resources also. i have checked it mannualy. i concern is, after creation of index on table after few transcations data is not inserting in GTT. also i tried to drop table then its not allowing mw to drop table. i am not getting why this is happening. it would be great if you can help me for same.

thanks,
mrunmayi

and Connor said...

There is no problem with having an index on a GTT. You need to show us some examples of how it is failing. Here's an example which I'm taking a guess at the error you might be getting and why:

SQL> create global temporary table GTT ( x int , y int)
  2  on commit preserve rows;

Table created.

SQL>
SQL> create index GTT_IX on GTT ( x );

Index created.

SQL>
SQL> insert into GTT values (1,1);

1 row created.

SQL>
SQL> drop table GTT;
drop table GTT
           *
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already in use


SQL> truncate table GTT;

Table truncated.

SQL> drop table GTT;

Table dropped.



Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, October 15, 2015 - 8:19 am UTC

Yes..thats right guess.. same scenario I am facing..i have truncated table and then its allow me to drop..but my concern is its not allowing me to insert data.if you can please tell me why this is happening?
Connor McDonald
October 15, 2015 - 12:03 pm UTC

You might need to *show* us an example, and the error message etc....

Help us to help you

I don't know why index is not created can anyone please help thank you!!

Sarfraz alam, October 12, 2018 - 9:48 am UTC

create table demo (id int primary key , name varchar2(500) not null)
insert into demo select level , initcap(dbms_random.string('A',5)) from dual connect by level < =50

create or replace procedure Insert_gtt(table_name varchar2)
is
sql_stmt varchar2(100);
create_table varchar2(200);
begin
create_table :='Create global temporary table ' ||table_name||' (ids Number, names varchar2(100)) ON COMMIT PRESERVE ROWS ';
execute immediate create_table;
sql_stmt := 'Insert into ' ||table_name|| ' select * from demo d where MOD(id,2) = 0';
execute immediate sql_stmt;
commit;
end;

declare
table_name varchar2(100);
begin
table_name := 'Table_'||to_char(systimestamp,'ddmmyyyyhh24missFF2');
dbms_output.put_line(table_name);
Insert_gtt(table_name);
end;

create unique index MyIndex on "Dynamically Generated Name" (IDS,NAMES);
Connor McDonald
October 13, 2018 - 4:20 am UTC

Show us the output of running this code, top to bottom, in a SQL Plus session