Create table as select statement.
Hello Oracle Gurus,
I am trying to create a table using select * from other table.
The procedure that I am following is this:-
I have a temp table whose signature is on commit delete rows.
I insert records in this table.
when I do select * from temp_table,perm_table I get some rows.
then I try to create a result_table using this
CREATE TABLE result_table
AS SELECT * FROM temp_table,perm_table;
I see the table in created but number of records in 0. Can anyone please explain where commit takes place while sequence in this query occurs.
Thanks
Edited by: user10696492 on Nov 10, 2009 8:47 AM
Create table statement is a ddl - so an implicit commit is performed before the create statement begins. The implicit commit will delete all the rows from the temp table. If it is feasible change the definition of the temp table to on commit preserve rows.
Similar Messages
-
Create table as select (CTAS)statement is taking very long time.
Hi All,
One of my procedure run a create table as select statement every month.
Usually it finishes in 20 mins. for 6172063 records and 1 hour in 13699067.
But this time it is taking forever even for 38076 records.
When I checked all it is doing is CPU usage. No I/O.
I did a count(*) using the query it brought results fine.
BUT CTAS keeps going on.
I'm using Oracle 10.2.0.4 .
main table temp_ip has 38076
table nhs_opcs_hier has 26769 records.
and table nhs_icd10_hier has 49551 records.
Query is as follows:
create table analytic_hes.temp_ip_hier as
select b.*, (select nvl(max(hierarchy), 0)
from ref_hd.nhs_opcs_hier a
where fiscal_year = b.hd_spell_fiscal_year
and a.code in
(primary_PROCEDURE, secondary_procedure_1, secondary_procedure_2,
secondary_procedure_3, secondary_procedure_4, secondary_procedure_5,
secondary_procedure_6, secondary_procedure_7, secondary_procedure_8,
secondary_procedure_9, secondary_procedure_10,
secondary_procedure_11, secondary_procedure_12)) as hd_procedure_hierarchy,
(select nvl(max(hierarchy), 0) from ref_hd.nhs_icd10_hier a
where fiscal_year = b.hd_spell_fiscal_year
and a.code in
(primary_diagnosis, secondary_diagnosis_1,
secondary_diagnosis_2, secondary_diagnosis_3,
secondary_diagnosis_4, secondary_diagnosis_5,
secondary_diagnosis_6, secondary_diagnosis_7,
secondary_diagnosis_8, secondary_diagnosis_9,
secondary_diagnosis_10, secondary_diagnosis_11,
secondary_diagnosis_12, secondary_diagnosis_13,
secondary_diagnosis_14)) as hd_diagnosis_hierarchy
from analytic_hes.temp_ip b
Any help would be greatly appreciatedHello
This is a bit of a wild card I think because it's going to require 14 fill scans of the temp_ip table to unpivot the diagnosis and procedure codes, so it's lilkely this will run slower than the original. However, as this is a temporary table, I'm guessing you might have some control over its structure, or at least have the ability to sack it and try something else. If you are able to alter this table structure, you could make the query much simpler and most likely much quicker. I think you need to have a list of procedure codes for the fiscal year and a list of diagnosis codes for the fiscal year. I'm doing that through the big list of UNION ALL statements, but you may have a more efficient way to do it based on the core tables you're populating temp_ip from. Anyway, here it is (as far as I can tell this will do the same job)
WITH codes AS
( SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
primary_PROCEDURE procedure_code,
primary_diagnosis diagnosis_code,
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_1 procedure_code,
secondary_diagnosis_1 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_2 procedure_code ,
secondary_diagnosis_2 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_3 procedure_code,
secondary_diagnosis_3 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_4 procedure_code,
secondary_diagnosis_4 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_5 procedure_code,
secondary_diagnosis_5 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_6 procedure_code,
secondary_diagnosis_6 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_7 procedure_code,
secondary_diagnosis_7 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_8 procedure_code,
secondary_diagnosis_8 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_9 procedure_code,
secondary_diagnosis_9 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_10 procedure_code,
secondary_diagnosis_10 diagnosis_code
FROM
temp_ip
UNION ALL
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_11 procedure_code,
secondary_diagnosis_11 diagnosis_code
FROM
temp_ip
SELECT
bd.primary_key_column_s,
hd_spell_fiscal_year,
secondary_procedure_12 procedure_code,
secondary_diagnosis_12 diagnosis_code
FROM
temp_ip
), hd_procedure_hierarchy AS
( SELECT
NVL (MAX (a.hierarchy), 0) hd_procedure_hierarchy,
a.fiscal_year
FROM
ref_hd.nhs_opcs_hier a,
codes pc
WHERE
a.fiscal_year = pc.hd_spell_fiscal_year
AND
a.code = pc.procedure_code
GROUP BY
a.fiscal_year
),hd_diagnosis_hierarchy AS
( SELECT
NVL (MAX (a.hierarchy), 0) hd_diagnosis_hierarchy,
a.fiscal_year
FROM
ref_hd.nhs_icd10_hier a,
codes pc
WHERE
a.fiscal_year = pc.hd_spell_fiscal_year
AND
a.code = pc.diagnosis_code
GROUP BY
a.fiscal_year
SELECT b.*, a.hd_procedure_hierarchy, c.hd_diagnosis_hierarchy
FROM analytic_hes.temp_ip b,
LEFT OUTER JOIN hd_procedure_hierarchy a
ON (a.fiscal_year = b.hd_spell_fiscal_year)
LEFT OUTER JOIN hd_diagnosis_hierarchy c
ON (c.fiscal_year = b.hd_spell_fiscal_year)HTH
David -
Using plsql tables in select statement of report query
Hi
Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
thanks in advance
sureshhi,
u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
declare
ur_file utl_file.file_type;
my_result varchar2(250);
begin
ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
utl_file.get_line(ur_file, my_result);
dbms_output.put_line(my_result);
utl_file.fclose(ur_file);
end;
make sure u have an entry in ur init.ora saying that your
utl_file_dir = '\your directory where ur files reside'
cheers!
[email protected] -
FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.
Hi,
I have one multi record block in which i want to fetch values
(more then one record) from another table using select statement
IN KEY NEXT ITEM.I am getting following error.
ORA-01422: exact fetch returns more than requested number of rows
Thanks in advance.In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
However, you can replace the explicit cursor with implicit one like
go_block('non_db_block_name');
first_record();
FOR v_tab IN (SELECT *
FROM tab
WHERE col_name = :variable)
LOOP
:non_db_block_name.field1 := v_tab.col1;
:non_db_block_name.field2 := v_tab.col2;
next_record();
END LOOP; -
Question on Creating Table From Insert statement
Hi,
I want to create a table using a DBlink from another database using the create/insert statement. Will it also transfer the constraints or do I have to do it manually afterwards? Thanks.
Create table T1
SELECT a,b,c from T2 from DB@dblink;As discussed above, the constraints, indexes, triggers are not copied. Only NOT NULL constraints are copied.
Look at this thread Re: Copying table structure.
for copying triggers/indexes from source table to destination table.
Thanks,
Navaneeth -
DB Link Create table as select
I ve a query which starts with create table as select ..
When I run the select part of the query, it runs in 2 sec.
But the whole query runs in 10min. It is fetching data from dblink.
I think if select can finish in 2 sec. All is left to do is create table and insert.
Why is takin so long?
Oracle DB version 9.2.0.8When I run the select part of the query, it runs in 2 sec.Does the select finish in 2 seconds or does it start returning rows in 2 seconds?
Big difference. -
Identify tablspace in create table as select
I am trying to run a create table as select query that specifies which tablspace to create the table in. When I run the query below I get an error, any ideas?
create table roi_call_record_backup as (select * from prod.roi_call_record)
tablespace roi_data01;
nullTry this ...
create table roi_call_record_backup
tablespace roi_data01
as
(select * from prod.roi_call_record)
null -
Create object type from multiple tables for select statement
Hi there,
I have 3 tables as given below and I wish to create an object type to group selected columns as 'attribute' from multiple tables.
I need to create 2 input parameters to pass in - 'attribute' and 'attribute value' in PL/SQL and these 2 parameters will be
passing in with 'column name' and 'column value'. e.g. 'configuration' - the column name, 'eval' - the column value.
Then, the PL/SQL will execute the select statement with the column and column value provided to output the record.
Pls advise and thank you.
table ccitemnumber
name null type
ccitemnumber not null varchar2(20)
configuration varchar2(20)
item_type varchar2(30)
table productmodel
productmodelnumber not null varchar2(6)
description varchar2(60)
accesstimems number
numberofheads varchar2(2)
generation varchar2(10)
numberofdiscs varchar2(2)
factoryapplication varchar2(150)
table topmodel
stmodelnumber not null varchar2(30)
productfamily varchar2(60
formfactor varchar2(10)
modelheight varchar2(10)
formattedcapacity number
formattedcapacity_uom varchar2(20)
object type in database
configuration varchar2(20)
item_type varchar2(30)
numberofheads varchar2(2)
generation varchar2(10)
numberofdiscs varchar2(2)
factoryapplication varchar2(150)
modelheight varchar2(10)
formattedcapacity number
formattedcapacuser12043838 wrote:
Reason to do this as these fields are required to be grouped together as they are created in different tables. They are treated as 'attribute' (consists of many columns) of the part number. So, the PL/SQL is requested to design in a way able for user to pass in the column name and column value or part number, then the select statement should be able to query for the records. Another reason is a new column can be added easily without keep modifying those effected programs. Reuseable too.This basically equates to ... hard to code, hard to maintain, and poor performance.
Are you really sure you want to do this? This isn't going to be easy-street as you seem to think it is, but it's a one way street to a poorly performing system with security vulnerabilities (google SQL Injection).
I would highly recommend you reconsider your design decision here. -
Dynamic internal table from SELECT - statement ?
Hi, is it possible to define an internal table just after a select statement is executed so that this internal table holds all the data that come back from the statement ?
thanks in advance,Check the link -
Re: Create Dynamic internal table
Regards,
Amit -
CREATE TABLE AS SELECT PROBLEM
Dear members,
I created a table whose definition is a select query.
for ex: I created a table xx_customer as :
create table xx_customer as
select customer_name,customer_number
from xx_ar_customer
where org_id = '87'when i run the query
select count(*)
from xx_customer;The count was 120 records.
This was done as part of performance tunning.
Now few days after the table xx_customer was created few records were inserted into table xx_ar_customer for org_id = '87' .
So ideally the count should be more than 120 but its not.
when i run the same query again
select count(*)
from xx_customer;I get count as 120 Records which is wrong.
It looks like it not refreshing data. If i run the table definition query i am getting count as more than 120 but if i do a select on the table count is still 120.
Any ideas?
Thanks
SandeepHi,
795291 wrote:
I cant create view. I tried that before. If i use view then my query runs for a very long time and if i create a table then the run time is reduced by half :)
So if we create Table as a select statement, then will it give data at the point of time it was created? Exactly!
Will it not give latest data?Not unless the latest data happens to be the same as the data at the time it was created.
CREATE TABLE AS is kind of like putting a photograph of yourself on your web site. If you smile, that doesn't mean the picture smiles.
CREATE VIEW is kind of like hanging a video camea from your hat, and streaming the output to your web page. As soon as you smile, the picture smiles. It's more expensive than a still picture.
A compromise apprioach is a Materialized View , which is really a type of table. Like any other table, it occupies space, and is relatively fast to use. You can define a materialized view to be refreshed at regular intervals (once a day, once an hour, once a week, ...) or whenever there is a change in the base table(s). -
"Create Table from select Query" Vs "Insert into"
Hi
Schenaio:
My Select Query returns more than 10 million records, these records needs to be inserted into another table.
Approach 1:
I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
Approach 2:
I create table like,
CREATE TABLE TABLE1 AS <SELECT QUERY>
Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
Thanks
NidhiMost "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
Therefore, a FullTableScan is executed for each batch of 5000 rows.
However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
Hemant K Chitale -
Problem in creaing the logical tables by SELECT statement
Hi,
I have created logical tables in the physical layer of the OBIEE tool by "select statement". Connection Pool is set up properly for the repository. Rows of the tables are updating properly by clicking to the "Update Row Count" but when I am clicking to the "View Data" it shows the following error
[nQSError:17001] Oracle Error code:936, message: ORA-00936:missing expression at OCI call OCIStmtExecute.
[nQSError:17010]SQL statement preparation failed.
Also for some tables data is coming properly by clicking to the "View Data" .
I'm stack in this point and cannot move forward. Please, help me guys.
Thanks
SandeepHi
I also face same type of error. Just do one thing Change the call interface OCI 10g to ODBC 3.5 and on Feature tab click revert to default.
I think that will work properly.
Best of Luck
Thanks
SIddhartha P -
[Solved]SIMPLE Question ON "CREATE TABLE as SELECT".
Hi there,
I was wondering how to work it out smartly and briefly.
For example, I already have a "tableA" as following.
tableA
id name
1 name1
2 name2
create table tmp as
select id, name from tableA;
It will create the tmp table successfully.
If I want to add a new column 'tel' in tmp table,
I can run as following.
create table tmp as
select id, name, 999 tel, 'aaaaaaaaa' ps from tableA;
It will add 'tel NUMBER' column and 'ps char(9)' in tableA.
If I want to add 'col varchar(50)' in tableA,
I do not want to make a string which contains 50 characters in Select command.
How can I make it work in a smart way?
Thanks.
Phil
Message was edited by:
user615355Is there a reason that you need this to be in a single statement? You would normally be better served here with a separate CREATE TABLE and INSERT (possibly as a direct path operation).
That said, you could use the CAST operator, i.e.
SCOTT @ jcave102 Local> create table a as select cast('a' as varchar2(50)) col1 from dual;
Table created.
Elapsed: 00:00:00.48
SCOTT @ jcave102 Local> desc a;
Name Null? Type
COL1 VARCHAR2(50)
SCOTT @ jcave102 Local> Justin -
Performance issue Create table as select BLOB
Hi!
I have a performance issue when moving BLOB´s between tables. (The size of images files are from 2MB to 10MB).
I'm using follwing statement for example,
"Create table tmp_blob as select * from table_blob
where blob_id = 333;"
Is there any hints that I can give when moving data like this or is Oracle10g better with BLOB's?Did you find a resolution to this issue?
We are also having the same issue and wondering if there is a faster mechanism to copy LOBs between two table. -
To make the query more efficient (create table wiht select command)
Hi,
I have written this query to create another table, but it takes approx two hours while both tables are indexed with 891353, 769023, i have used the following query.
create table source1 as select a.idx, a.source from tt a where a.idx not in (select b.idx from ttt b)
thanksTry this one if you're on oracle 8i or older
create table source1 as
select a.idx, a.source
from tt a
where not exists (select null from ttt b where a.idx = b.idx)
Maybe you are looking for
-
Have Yosemite AND IOS 8.1 but SMS forward doesn't work!
I have the latest versions of Yosemite and IOS 8.1 both devices are logged into icloud and message forwarding says that it is enabled - everything is set up as it should be and yet when I try to send an SMS message from my mac it tells me the number
-
How to configure FTP Adapter for multiple endpoints?
Scenario: I have multiple ftp endpoints (5-15) and depending on some business logic, I have to send data to the right destination. With default ftp adapter configuration, I have to add a n adapter connection factory reachable via JNDI for each destin
-
Flash transparency in Linux Firefox
I have develped a site where the html is split with<div> separators. One of the divisions contains a flash animation with a transparent backgroud and a z index lower than the text that should be visible over the animation. This works on all platforms
-
Hi! I guess this is not actually web services (WS) problem, but anyway... I created WS that works flawlessly on my local machine. The structure is like this: Client --> WS stateless bean in separate EAR (can return emulated results by itself or call
-
Iphone 4s not working after ios 7 upgrade
Ever since i have updated my iphone 4s to ios 7my phone has stuck in recovery mode and when i connectect to itunes it keeps coming up with unknown error occurred. Please help my mobile has been out of action since Friday.