Insert into some sort of temp table?
Hi there,
Not sure how to do this, I have three Two CTEs
with a as (select field1, field2, field3 from table1),
b as (select field1, field2, field3 from table2)
Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
Let me know what would be the best approach to accomplish this task here.
Thanks very much for your help.
Hi,
Sorry, I don't understand what you want.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using.
Midway wrote:
Hi there,
Not sure how to do this, I have three Two CTEs
with a as (select field1, field2, field3 from table1),
b as (select field1, field2, field3 from table2)Why do you need CTEs? Why can't you just use table1 and table2?
Now I would like to insert each result from the above CTE into some kind of table or something. I would not want to use a temp table cause I read that's not a good approach. I'm kind of new to the Oracle world. I'm coming from a SQL server background and the way I would do it in SQL server would something like creating a Table variable and inserting all the result sets into that table variable, hence avoiding the creation of a temp table with in Oracle its more like a permanent table I read.
Let me know what would be the best approach to accomplish this task here.What is the task that you want to accomplish?
Is INSERTing really the goal, or is that a means you might use to accomplish your real task?
If all you want to do is generate a specific output, then I'm sure you don't need any other tables, temporary or otherwise. Exactly how to do it depends on what data is in your actual tables, and what results you want from that data. As long as I don't know where you're starting from, or where you want to go, I can't give you very good directions.
Similar Messages
-
my computer crashed,then it started up having totally going back to as if it were just bought ,it deleted everything i had . Does itunes save my library because its all gone off my computer
It has always been very basic to always maintain a backup copy of your computer for this very occasion.
Use your backup copy of your computer to put everything back.
If for some reason you have failed to maintain a backup copy, not good, then you can redownload some itunes purchases in some countries:
Download past purchases - Support - Apple -
Query is taking too much time for inserting into a temp table and for spooling
Hi,
I am working on a query optimization project where I have found a query which takes hell lot of time to execute.
Temp table is defined as follows:
DECLARE @CastSummary TABLE (CastID INT, SalesOrderID INT, ProductionOrderID INT, Actual FLOAT,
ProductionOrderNo NVARCHAR(50), SalesOrderNo NVARCHAR(50), Customer NVARCHAR(MAX), Targets FLOAT)
SELECT
C.CastID,
SO.SalesOrderID,
PO.ProductionOrderID,
F.CalculatedWeight,
PO.ProductionOrderNo,
SO.SalesOrderNo,
SC.Name,
SO.OrderQty
FROM
CastCast C
JOIN Sales.Production PO ON PO.ProductionOrderID = C.ProductionOrderID
join Sales.ProductionDetail d on d.ProductionOrderID = PO.ProductionOrderID
LEFT JOIN Sales.SalesOrder SO ON d.SalesOrderID = SO.SalesOrderID
LEFT JOIN FinishedGoods.Equipment F ON F.CastID = C.CastID
JOIN Sales.Customer SC ON SC.CustomerID = SO.CustomerID
WHERE
(C.CreatedDate >= @StartDate AND C.CreatedDate < @EndDate)
It takes almost 33% for Table Insert when I insert the data in a temp table and then 67% for Spooling. I had removed 2 LEFT joins and made it as JOIN from the above query and then tried. Query execution became bit fast. But still needs improvement.
How I can improve further. Will it be good enough if I create Indexes on the columns for the temp table and try.or what If I use derived tables?? Please suggest.
-PepHow I can improve further. Will it be good enough if I create Indexes on the columns for the temp table and try.or what If I use derived tables??
I suggest you start with index tuning. Specifically, make sure columns specified in the WHERE and JOIN columns are properly indexed (ideally clustered or covering, and unique when possible). Changing outer joins to inner joins is appropriate
if you don't need outer joins in the first place.
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
Issue with INSERT INTO, throws primary key violation error even if the target table is empty
Hi,
I am running a simple
INSERT INTO Table 1 (column 1, column 2, ....., column n)
SELECT column 1, column 2, ....., column n FROM Table 2
Table 1 and Table 2 have same definition(schema).
Table 1 is empty and Table 2 has all the data. Column 1 is primary key and there is NO identity column.
This statement still throws Primary key violation error. Am clueless about this?
How can this happen when the target table is totally empty?
ChintuNope thats not true
Either you're not inserting to the right table or in the background some other trigger code is getting fired which is inserting into some table which causes a PK violation.
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Insert into multiple tables; grab id from first
I apologize if this has been answered elsewhere, but I tried
searching and got no results.
I'm trying to insert the contents of one form into two
tables. After inserting some fields into one table, I want to grab
the key/id from the first table into the second table with the
other fields.
I've tried a few different things, including trying to use
SCOPE_IDENTITY(), but just kept getting lots of errors.
The current version of my code works perfectly, *except for
the fact that it doesn't insert the ID*!
Can anyone tell me what I'm doing wrong? or offer another way
of doing this?
Thanks for your help, as usual.MarianneStone wrote:
> The current version of my code works perfectly, *except
for the fact that it doesn't insert > the ID*!
> Can anyone tell me what I'm doing wrong?
The EmployeeID is not inserted because the getMyID query
cannot find the newly inserted record. When using a UUID to
identify the new records ..
<cfquery name="qAddDeptHead" datasource="#db#"
result="result">
INSERT INTO Employee(... , EmpUUID)
VALUES ( ... , '#CreateUUID()#')
</cfquery>
You have to use that _same_ UUID to find the record, _not_
create a new one.
<cfquery name="getMyID" datasource="#db#">
SELECT EmployeeID, EmpUUID
FROM Employee
WHERE Employee.EmpUUID='#UseTheSameUUIDFromTheFirstQuery#'
</cfquery>
As an aside, you could probably do this in two queries not
three. Just drop the second SELECT query and use an INSERT
INTO/SELECT .. FROM Table statement instead. Plus you should also
consider using cfqueryparam for your query parameters. It has many
benefits.
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_18.html#1102474
> Can anyone ... offer another way of doing this?
There are a few options. For ColdFusion 8, you could use the
result attribute. After running the INSERT you can grab the new
EmployeeID by using #yourResult.IDENTITYCOL#
<cfquery name="qAddDeptHead" datasource="#db#"
result="yourResult">
INSERT INTO Employee ( Columns here )
VALUES (... values here ...)
</cfquery>
For earlier versions, you can either use SCOPE_IDENTITY() or
a UUID value - as you are currently doing now.
> I've tried a few different things, including trying to
use SCOPE_IDENTITY(),
> but just kept getting lots of errors.
If you use SCOPE_IDENTITY() turn off the rowcount, or the
query variable "qAddDeptHead" may be undefined when you try and use
it.
<cfquery name="qAddDeptHead" datasource="#db#"
result="yourResult">
SET NOCOUNT ON;
INSERT INTO Employee ( Columns here )
VALUES (... values here ...)
SELECT EmployeeID AS NewEmployeeID
SET NOCOUNT OFF;
</cfquery>
<cfquery name="qNewEmpPosition" datasource="#db#">
INSERT INTO EmployeePositions(EmployeeID, .... )
VALUES ( #qAddDeptHead.NewEmployeeID#, ....)
</cfquery> -
Retriving unique records and insert into cust and cust_det table
Hi,
uniq Table : EMP
column name
name
addr
city
addr1
city1
EMP table contains only unique records.
we neet to get the records from emp and insert into cust and cust_det accordingly
table : cust
empno : auto generated
name
addr
tabel : cust_det
empno : refer from cust
addr1
city1
plese help me to do this.user10069916 wrote:
can some one help me to resolve this plz. bit urgent..My boss says my work is more urgent than yours.
As I said, please read: {message:id=9360002} (especially point 2)
If you post sufficient information, then people can help you. the better the information you provide the faster people will be able to help... but still, if it's "urgent" then we can only assume you have a live production system that is failing, in which case you need to raise an SR with Oracle Support, as the forums are not the place for logging "urgent" production system issues. -
Inserting into table takes several hours
Hi All,
A table has a composite index with unique as Y, logging as YES, degree as 1. There are three columns for this index. Inserting into these columns in the table takes hours. Even for 3 or 4 hours, only 10 records or so get inserted.
The number of extents for this index is 84. Would that be a problem for this performance issue? Please advise bcos it is quite urgent. Many thanks.Welcome to the forum!
First read this:
Smart Questions: Urgent
Then check out these:
{message:id=1812597}
{thread:id=863295}
Post back with the information identified above and we can try and help you further. -
INSERT INTO TABLE (SELECT -----)
I laready posted But i think people got confused this is the same query in easiest way
Hi Please please here Insdie the curusr FOR Loop i am using INSERT INTO by SELECT (see the below code EACH INSERT WILL FETCH 800-1000 records Minimum !!!)
In that satement here i am using the MINUS also ,,thi is taking minute to insert each record approx
This way I need to insert 5 insert Into sattement for different tables see EXA
Inside the FOR loop------
INSERT INTO PICKSLIP
( SELECT FIELDS
FROM table p, table d
WHERE ---- AND ---
AND ---
AND -----
IN ( SELECT Fields
FROM p, d
WHERE ---- AND ---
AND ----
MINUS
SELECT PICKSLIP_PREFIX, PICKSLIP_NUMBER FROM C
GROUP BY Fields);
This WAY
5 insert it dam slow taking 1 minutes to insert to all 5 tables ...this way i have lot of recordss....But i think people got confused this is the same query in easiest way I don't think this is more clear with your current thread. Your query is bad, and shouldn't work at all.
It shouldn't work for too many reasons (at least because AND without nothing behind) and use a group by clause where is not required.
Nicolas. -
Inserting a record in an internal table - Urgent
Hi Friends,
I have a requirement where in I have 2 internal tables say itab1 and itab2.Itab1 has 10 records and itab2 has one record initially.
Now I have to move the records of itab1 into itab2.
My question is if some conditions satisfy,then I need to append the records of itab1 after the single record in itab2.In some other cases I need to insert the records of itab1 before
the single record in itab2.
What is the syntax to attach the records before the record as append statement always attaches the record after the existing record.
Your help is highly appreciated.
Regards,
Vishnu.You can use insert itab index idx .
Alternative 2
... itab INDEX idx
Effect
This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.
If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.
An exception that cannot be handled is raised when:
idx contains a value less than or equal to 0
A line to be inserted would cause a duplicate entry in tables with a unique table key
A line to be inserted would disrupt the sort order of sorted tables
Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.
read help on this .
reward if helpful -
My input is from a file. Since I do not have an ETL tool, I am using a stored proc to do the ETL (which also gives me an advantage, I do not have to unload the target table to do the join). So, I dump the file contents into a temp table and use it in proc.
The query is like
Insert into <target table1> (Select fields and some transformation from <temp table> where <key> not in target table and <some joins with other tables in database>
Like this I have four queries for four target tables.
The inserts from the temp table into the target table is very slow because the target has a lot of index and RI. I cannot drop & create the index since the application requirements does not give me that liberty.
My only option is to insert in a temp table similar to the target but without any index/RI/PK and then dump it into a file and then use SQL loader to load the file contents into target table. This is relatively faster but is a very cumbersome route to me.
Is there any other way to do bulk insert from one table to another table like SQL loader without using a file? Is there anyway to bypass the index update operation without dropping the index?
My source will be almost 500,000 rows and target is having 9 million rows.Posts like this one are better avoided.
Because
- You don't post a version
- You don't post the SQL
- You don't post the EXPLAIN PLAN
It is your assertion the INSERT is to blame, yet it can equally be the SELECT statement involved.
Basically your post boils down to
'It doesn't work. Please help', without any relevant information.
I'm saying this because INSERT SELECT is the fastest method available. OK, you could try the APPEND hint, but in that case you would have to rebuild all indices. Something you state you can not do.
BULK INSERTs will be slower, SQL*Loader will be slower too, as it involves SQLnet. INSERT SELECT is a server side operation.
And the 'solution' to do this by means of a file... Ahem, let's not talk about it. It just doesn't work.
Sybrand Bakker
Senior Oracle DBA -
Temp table gets deleted when calling another function
Hello Everyone
I am using temporary tables which gets deleted on commit to workaround a multiset union (which doesnt work on Oracle 9). Now, this table somehow gets deleted (the content) during execution of my stored procedure but there is no delete or commit statement.
Here is what I am doing
start
delete temp table (just to be sure)
prepare array
loop array {
output count of temp table
a = some other function(...)
output count of temp table
insert stuff I need to temp table
output count of temp table
end
The output is giving me (example). The correct result would be 140 at the end
0
0
100
0
40
I checked all further function calls, there is no delete or commit, just some objects are created (and collections) which are then processed and returned.
Could it be that there is a automatic commit or something like that?
Thanks
Edited by: maschlegel on Jan 26, 2009 6:36 AM
Edited by: maschlegel on Jan 26, 2009 6:37 AM
Edited by: maschlegel on Jan 26, 2009 6:38 AMjust some objects are created (and collections) which are then processed and returneAll DDL statements issue COMMITs implicitly - once before the statement is processed and once after. (so any data changes are committed even if the DDL statement fails).
This is just one reason why it is such a bad idea to stick DDL statements in the middle of transactions.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
ORA-01461: can bind a LONG value only for insert into a LONG column-Update
Hi,
I'm using Oracle 9.2 with Weblogic 8 server. There are two columns OBJ_EVIDENCE_COMP - varchar2(4000 bytes), Descriptiion - varchar2(4000 bytes) in a table.I'm getting the Data from that table and again I'm updating into the same table with same data after updating the Data object in java.
I am getting the following error
"Java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column"
Can some one let me know why this error occurs ? Please do let me know if you want any other information. Below is my SQL Query:
* @jc:sql statement::
* UPDATE CORRECTIVE_ACTION SET
* CA_ID = {dt.caId},
* CA_NBR = {dt.caNbr},
* CAPA_PLAN_ID = {dt.capaPlanId},
* OBJ_EVIDENCE_COMP = {dt.objEvidenceComp},
* APPLICABLE_ELSE_WHERE = {dt.applicableElseWhere},
* JUSTIFICATION = {dt.justification},
* MOE = {dt.moe},
* COMPLETION_DATE = {dt.completionDate},
* EXTENSION_DUE_DATE = {dt.extensionDueDate},
* STATUS_CD = {dt.statusCd},
* SYSTEM_STATUS_CD = {dt.systemStatusCd},
* ROOT_CAUSE_CD = {dt.rootCauseCd},
* DESCRIPTION = {dt.description},
* CA_TYPE = {dt.caType},
* CREATED_BY = {dt.createdBy},
* CREATED_DATE = {dt.createdDate},
* MODIFIED_BY = {dt.modifiedBy},
* MODIFIED_DATE = {dt.modifiedDate},
* COMPLETION_DUE_DATE = {dt.completionDueDate}
* WHERE CA_ID = {dt.caId}
In the above update statement if i remove one among the 2 columns mentioned then it is getting updated properly......
Regards,
Bharat
Edited by: 908508 on Jan 17, 2012 2:18 AMI am occasionally getting this error in an Oracle 11g database
I use Rogue Wave to insert:
connection.beginTransaction ("bulkInsertEvents");
RWDBTBuffer <RWCString> symbols (symbol, rowCount);
RWDBTBuffer <RWDateTime> timeStamps (timeStamp, rowCount);
RWDBTBuffer <int> eventCounts (eventCount, rowCount);
RWDBTBuffer <RWCString> events (event, rowCount);
RWDBBulkInserter ins = table.bulkInserter (connection);
ins << symbols << timeStamps << eventCounts << events;
ins.execute ();
connection.commitTransaction ("bulkInsertEvents");
catch (RWxmsg & exception)
cout << Logging::getProgramName () << " " << exception.why () << endl;
throw "Failed to do bulk insert events to DBTools.";
Some of the inserts give me
"[SERVERERROR] ORA-01461: can bind a LONG value only for insert into a LONG column"
the table structure is
SYMBOL VARCHAR2(33 BYTE)
DATEANDTIME TIMESTAMP(6)
NUMOFEVENTS NUMBER
EVENTS VARCHAR2(4000 BYTE) -
Hi all,
Whats the best way for insert multivalues
INSERT INTO EMP(ENAME) values (htmldb_aplication.g_f32(i)); where EMPNO populated from trigger
and (htmldb_aplication.g_f34(i)), (htmldb_aplication.g_f36(i)),(htmldb_aplication.g_f38(i)) ....
regards,
Gordanuou have a form with 8 columns on it, correct?
-thats like row with 20 fields (Formular A8) but every field need insert into ONE row from emp table into EMPNO column-thats form
So you need to allow the user ti insert a number of rows of emp type data, correct?
-user fill 20 fields from user friendly UI and when finish click CREATE a and all 20 fields (:P1_CODE1....:P1_CODE20) need insert into EMP(ENAME) and all type are VARCHAR2(255) inserting 20 x.
SO you COULD have a multiple row update (MRU) form with you table design built by apex, correct... No - just INSERT
Will the user be entering all the columns of data? or only some and some are blank? Yes, Could be some blank
thenks for link I will trying to solve with collection
Gordan -
Can I convert my VBA project to some sort of batch submitted executable
Thanks to the help from you all, I have written VBA macros that open huge word documents and pluck out specific information and put it into Excel. The files I've received have grown in size from 1500 to 3500 pages. I'm currently running the VBA
macros by opening the document in word and then clicking "View....Macros...mymacro....Run. The macro then runs for any where from 10 minutes to 2 hours.
Is there a way I can convert my VBA project into some sort of executable so that I can "submit" the word file to the executable? Sometimes I run this on a term server. I'd like to start the job, log off the term server, and then later
check for the resulting excel file.
Is there a way to queue up a list of input files for this?Hi Denis Backer,
>>Can I convert my VBA project to some sort of batch submitted executable<<
Yes, it is possible. We can write an application to automate open the Word documents and run the macro using
Application.Run. Also we can convert all the VBA project with mange code, however the Office automation is not supported on the server enviroment.
Microsoft does not currently recommend, and does not support, Automation of
Microsoft Office applications from any unattended, non-interactive client
application or component (including ASP, ASP.NET, DCOM, and NT Services),
because Office may exhibit unstable behavior and/or deadlock when Office is run
in this environment.
You can get more detail about it from link below:
Considerations for server-side Automation of Office Print Print Email Email
And here are two helpful links about Office automtaion using C# for your reference:
C# app automates Word (CSAutomateWord)
How to automate Microsoft Excel from Microsoft Visual C#.NET
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
That is a really curious disclaimer considering the number of options for automation Microsoft itself integrates into its products. -
How to insert into collection type of objects?
Hello,
Can any one help with the follwoing code below,where i cant insert into an instance of the table type within the pl/sql block.
create type courselist is table of varchar2(25);
create type student as object
(name varchar2(20),
courses courselist);
create type student_typ is table of student;
create or replace procedure test_nested as
my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
n_numb number;
begin
dbms_output.put_line('hello initial'||'-'||my_courses1.count);
my_courses1.extend;
n_numb:=my_courses1.next(my_courses1.first);
dbms_output.put_line('Next Subscript :'||n_numb);
dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));
dbms_output.put_line(my_courses1(n_numb).name);
exception
when others then
dbms_output.put_line(sqlerrm);
end;Look at:
my_courses1(n_numb):=student_typ(student('Potter',courselist('eng 2010','bio 2010')));my_courses1(n_numb) is of student type while student_typ(student('Potter',courselist('eng 2010','bio 2010'))) is table of student type. Change it to:
my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));and you will be fine:
SQL> create or replace
2 procedure test_nested
3 as
4 my_courses1 student_typ:=student_typ(student('harry',courselist('eco 2010','math 2010','acct 2010')));
5 n_numb number;
6 begin
7 dbms_output.put_line('hello initial'||'-'||my_courses1.count);
8 my_courses1.extend;
9 n_numb:=my_courses1.next(my_courses1.first);
10 dbms_output.put_line('Next Subscript :'||n_numb);
11 dbms_output.put_line('hello after extend'||'-'||my_courses1.count);
12 my_courses1(n_numb):=student('Potter',courselist('eng 2010','bio 2010'));
13 dbms_output.put_line(my_courses1(n_numb).name);
14 exception
15 when others then
16 dbms_output.put_line(sqlerrm);
17 end;
18 /
Procedure created.
SQL> exec test_nested
hello initial-1
Next Subscript :2
hello after extend-2
Potter
PL/SQL procedure successfully completed.
SQL> SY.
Maybe you are looking for
-
Excise invoice financial entry is vary
Hi All, when i create a excise invoice for the same vendor(10026) first one is november'09 and then create second one on December'09 but the financial entry was varied for those excise invoice. Please find the attached data entry view. 1. While Updat
-
MISSING Video after Time Machine Restore
Hi All. I had a drive go bad and had to buy a new one and restore from Time Capsule. I am noticing that I am missing a slideshow video that I spend a good deal of time creating. I went from a 500 GB to a 1 TB drive which I assume does not matter. The
-
Hi, everyone I have a need for what I think is an older version of info-zip that used to have the -E (capital E) option that would encrypt the file but it could be scripted unlike the current zip -e which will prompt you to enter a password twice and
-
IPod Only Charges on Computer. HELP!
I've got a 30gig Video iPod, and a Monster iPod adapter, and it will not charge my iPod at all. NI've tried several different car-chargers/transmitter and none charge my iPod. The only way I can charge it is through the computer. When it is connected
-
Error Inovking render operation
Hello, I am getting the below errors after switching my livecycle over to a new server. Can anyone point me in the right direction on taking care of this? Sorry I am still in the newbie stage. Caused by: com.adobe.idp.taskmanager.dsc.client.task.Task