INSERTING INTO A TABLE FROM ANOTHER TABLE
Hi,
I am having a table called emp in which 5 columns are there, I want to insert some rows from another table called employees, only into three columns of emp table through a sub query.
Is this scenario is possible, I tried so many queries but it is not working out.
Can any body help me out.
The columns in emp table is
empno, ename, doj, designation, salary, deptno, mgrid
The columns in employees table is
empno, name, hiredate, post, salary, commission, deptno, mgr
I want to insert into empno, ename, doj, designation columns of emp table from the employees table empno, name, hiredate, post columns.
Ramesh.
It looks like your EMP table has 7 columns, not 5, and you want to insert into 4 columns, not 3.
insert into emp
(empno, ename, doj, designation)
select empno, name, hiredate, post
from employees;
Similar Messages
-
Fetch data from one table and insert into two tables in desired format
I have similar to the following data in a table and it is not normalized. The groupID is being used to group two records of similar nature.
DECLARE @OldDoc TABLE (oldDocID INT, groupID INT, deptID INT)
INSERT INTO @OldDoc (oldDocID, groupID) VALUES (1, NULL, 111),(2,NULL,111),(3,1,111),(4,NULL,333),(5,1,222),(6,NULL,333),(7,2,222),(8,2,333),(9,NULL,111),(10,3,222),(11,NULL,333),(12,3,444)
I need to process the data from the above table (@OldDoc) and write into two new tables (@NewDoc and @NewDocGroup) as follows.
oldDocID should be stored as newDocID when inserting to @NewDoc table. Only records with groupID NULL and one record (first one) per group should be considered (For example, oldDocID 5 is not considered as 3 and 5 belong to the same groupID 1) for insertion.
DECLARE @NewDoc TABLE (newDocID INT)
INSERT INTO @NewDoc (newDocID) VALUES (1),(2),(3),(4),(6),(7),(9),(10),(11)
All records from @OldDoc should be considered for insertion into @NewDocGroup table. OldDocID is inserted as NewDocID and deptID is as-is. Instead of groupID, the ID of the first record in the
group should be considered as parentNewDocID (For example, 3 is considered as parentNewDocID for newDocID 5 as 3 and 5 belong to the same groupID in @OldDoc table) for the newDocID.
DECLARE @NewDocGroup (newDocID INT, parentNewDocID INT, deptID INT)
INSERT INTO @NewDocGroup (newDocID, parentNewDocID, deptID) VALUES (1,1,111),(2,2,111),(3,3,111),(4,4,333),(5,3,222),(6,6,333),(7,7,222),(8,7,333),(9,9,111),(10,10,222),(11,11,333),(12,10,444)
How do I accomplish the above using SQL ? Thanks for the help.>> I have similar to the following data in a table and it is not normalized. The group_id is being used to group two records [sic] of similar nature. <<
Rows are not records. Tables have to have a key by definition. You do not do math with identifiers, so they should not be numeric. Let's ignore that error for now. In short, you are posting garbage. If you had followed Forum Netiquette, would you have posted
this?
CREATE TABLE Old_Documents
(old_doc_id INTEGER NOT NULL PRIMARY KEY,
group_id INTEGER,
dept_nbr INTEGER NOT NULL
REFERENCES Departments (dept_nbr));
INSERT INTO Old_Documents(old_doc_id, group_id, dept_nbr)
VALUES (1, NULL, 111),
(2, NULL, 111),
(3, 1, 111),
(4, NULL, 333),
(5, 1, 222),
(6, NULL, 333),
(7, 2, 222),
(8, 2, 333),
(9, NULL, 111),
(10, 3, 222),
(11, NULL, 333),
(12, 3, 444);
>> I need to process the data from the above table (Old_Documents) and write into two new tables (New_Documents and New_Documents_Groups) as follows. <<
Just like punch cards and mag tape data processing! Being old and being new are a status, not another kind of entity. But that is how mag tapes work. And you even use the verb "fetch" from tape files. This design flaw is called attribute splitting.
Do you have a Male_Personnel and Female_Personnel table? NO! It is just Personnel!
>> old_doc_id should be stored as new_doc_id when inserting to New_Documents table. Only records [sic] with group_id NULL and one record [sic] (first [sic; no ordering in a table] one) per group should be considered (For example, old_doc_id 5 is not considered
as 3 and 5 belong to the same group_id =1) for insertion. <<
Think about your punch card mindset. Why did you physically materialize that redundant New_Documents table? Let me answer that: this is how you work with punch cards! In SQL we use a VIEW:
CREATE VIEW New_Documents (new_doc_id)
AS
SELECT old_doc_id
FROM Old_Documents;
>> All records [sic] from Old_Documents should be considered for insertion into New_Documents_Groups table. The old_doc_id is inserted as new_doc_id and dept_nbr is as-is. Instead of group_id, the ID [sic: which identifier??] of the first [sic: tables
have no ordering like a deck of punch cards] record [sic] in the group should be considered as parent_new_doc_id (For example, 3 is considered as parent_new_doc_id for new_doc_id 5 as 3 and 5 belong to the same group_id in Old_Documents table) for the new_doc_id.
<<
Why not use 5 as the parent? My guess is that you are trying to form equivalence classes. See:
https://www.simple-talk.com/content/print.aspx?article=2020
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Insertion into local table from remote table with contains clause
Hi all,
We are tasked to insert some rows into our database from another database. We tried to use DBLinks to link the 2 databases and were able to use Select statements to filter out the data that we need to insert into our database.
These statements take the form of: Select * from RemoteTable where contains@RemoteLink(IndexColumn, 'car')>0;
where RemoteLink is the DBLink that we have created.
However Oracle gave us an error (ORA-00949: illegal reference to remote table) when we tried to insert the dataset from the above statement into our local table. We used the following statement in doing so: Insert Into LocalTable (Select * from RemoteTable where contains@RemoteLink(IndexColumn, 'car')>0);
Even if we use Create Table, Oracle gave us the same error when we tried to push the data from the Select Statement into the new table.
Could anyone advise us whether it is possible to insert such data into a local table? And if som what is the proper way of doing it?
Many thanks to any advises.Hi,
there is document 261741.1 on Metalink. This states explicitly that it is not possible to invoke remote user-defined operators, and contains is such. The solution given in the article is to create a wrapper function on the remote site and this one calling in stead of contains.
Herald ten Dam
htendam.wordpress.com -
Inserting into a table which is created "on the fly" from a trigger
Hello all,
I am trying to insert into a table from a trigger in Oracle form. The table name however, is inputted by the user in am item form.
here is what the insert looks like:
insert into :table_name
values (:value1, :value2);
the problem is that forms does not recognize ::table_name. If I replace :table_name with an actual database table, it works fine. However, I need to insert to a table_name based from oracle form item.
By the way, the table|_name is built on the fly using a procedure before I try to insert into it.
Any suggestion on how can I do that? My code in the trigger is:
declare
dm_drop_tbl(:table_name,'table) // a call to an external procedure to drop the table
dm_create_tbl(:table_name,'att1','att2');
insert into :table_name
values (:value1, :value2);
this give me an error:
encounter "" when the symbol expecting one.....Hi ,
You should use the FORMS_DDL built_in procedure. Read the on-line documentation of forms ...
Simon -
How to extract data from xml and insert into Oracle table
Hi,
I have a large xml file. which will have hundreds of the following transaction tags having column names and there values.
There is a table one of the schema with coulums "actualCostRate","billRate"....etc.
I need to extract the values of these columns and insert into the table
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuUK" chargeCode="LCOCD1" externalID="L-RESCODE_UK1-PROJ_UK_CNT_GBP-37289-8" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-12" transactionType="L" units="11" taskID="5017601" inputTypeCode="SALES" groupId="123" voucherNumber="ABCVDD" transactionClass="ABCD"/>
<Transaction actualCostRate="0" billRate="0" chargeable="1" clientID="NikuEU" chargeCode="LCOCD1" externalID="L-RESCODE_US1-PROJ_EU_STD2-37291-4" importStatus="N" projectID="TESTPROJ" resourceID="admin" transactionDate="2002-02-04" transactionType="L" units="4" taskID="5017601" inputTypeCode="SALES" groupId="124" voucherNumber="EEE222" transactionClass="DEFG"/>Re: Insert from XML to relational table
http://www.google.ae/search?hl=ar&q=extract+data+from+xml+and+insert+into+Oracle+table+&btnG=%D8%A8%D8%AD%D8%AB+Google&meta= -
How to insert into a table with a nested table which refer to another table
Hello everybody,
As the title of this thread might not be very understandable, I'm going to explain it :
In a context of a library, I have an object table about Book, and an object table about Subscriber.
In the table Subscriber, I have a nested table modeling the Loan made by the subscriber.
And finally, this nested table refers to the Book table.
Here the code concerning the creation of theses tables :
Book :
create or replace type TBook as object
number int,
title varchar2(50)
Loan :
create or replace type TLoan as object
book ref TBook,
loaning_date date
create or replace type NTLoan as table of TLoan;
Subscriber :
create or replace type TSubscriber as object
sub_id int,
name varchar2(25)
loans NTLoan
Now, my problem is how to insert into a table of TSubscriber... I tried this query, without any success...
insert into OSubscriber values
*(1, 'LEVEQUE', NTLoan(*
select TLoan(ref(b), '10/03/85') from OBook b where b.number = 1)
Of course, there is an occurrence of book in the table OBook with the number attribute 1.
Oracle returned me this error :
SQL error : ORA-00936: missing expression
00936. 00000 - "missing expression"
Thank you for your help1) NUMBER is a reserved word - you can't use it as identifier:
SQL> create or replace type TBook as object
2 (
3 number int,
4 title varchar2(50)
5 );
6 /
Warning: Type created with compilation errors.
SQL> show err
Errors for TYPE TBOOK:
LINE/COL ERROR
0/0 PL/SQL: Compilation unit analysis terminated
3/1 PLS-00330: invalid use of type name or subtype name2) Subquery must be enclosed in parenthesis:
SQL> create table OSubscriber of TSubscriber
2 nested table loans store as loans
3 /
Table created.
SQL> create table OBook of TBook
2 /
Table created.
SQL> insert
2 into OBook
3 values(
4 1,
5 'No Title'
6 )
7 /
1 row created.
SQL> commit
2 /
Commit complete.
SQL> insert into OSubscriber
2 values(
3 1,
4 'LEVEQUE',
5 NTLoan(
6 (select TLoan(ref(b),DATE '1985-10-03') from OBook b where b.num = 1)
7 )
8 )
9 /
1 row created.
SQL> select *
2 from OSubscriber
3 /
SUB_ID NAME
LOANS(BOOK, LOANING_DATE)
1 LEVEQUE
NTLOAN(TLOAN(000022020863025C8D48614D708DB5CD98524013DC88599E34C3D34E9B9DBA1418E49F1EB2, '03-OCT-85'))
SQL> SY. -
How to insert into 2 tables from the same page (with one button link)
Hi,
I have the following 2 tables....
Employees
emp_id number not null
name varchar2(30) not null
email varchar2(50)
hire_date date
dept_id number
PK = emp_id
FK = dept_id
Notes
note_id number not null
added_on date not null
added_by varchar2(30) not null
note varchar2(4000)
emp_id number not null
PK = note_id
FK = emp_id
I want to do an insert into both tables via the application and also via the same page (with one button link). I have made a form to add an employee with an add button - adding an employee is no problem.
Now, on the same page, I have added a html text area in another region, where the user can write a note. But how do I get the note to insert into the Notes table when the user clicks the add button?
In other words, when the user clicks 'add', the employee information should be inserted into the Employees table and the note should be inserted into the Notes table.
How do I go about doing this?
Thanks.Hi,
These are my After Submit Processes...
After Submit
30 Process Row of NOTES Automatic Row Processing (DML) Unconditional
30 Process Row of EMPLOYEES Automatic Row Processing (DML) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
40 reset page Clear Cache for all Items on Pages (PageID,PageID,PageID) Unconditional
50 Insert into Tables PL/SQL anonymous block Conditional
My pl/sql code is the same as posted earlier.
Upon inserting data into the forms and clicking the add button, I get this error...
ORA-06550: line 1, column 102: PL/SQL: ORA-00904: "NOTES": invalid identifier ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored
Error Unable to process row of table EMPLOYEES.
Is there something wrong with the pl/sql code or is it something else? -
Fetch data from two tables and insert into one table
I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director.
Data exists only for subset of plants and a Plant may have one or both roles.
DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
The above data needs to be inserted into one table (@PlantNew) as follows:
PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
How do I achieve the above using SQL ? Thanks.like this
INSERT @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
@PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
You're missing a FROM
insert into @PlantNew
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
from @PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID -
Insert into other table from form
Hi All,
I have created a data block with view as a data source. I need to save the data from a form to some other table.
I have tried using INSTEAD OF Trigger. howeverwhen I try to save, getting an error : ORA-01445 cannot select ROWID from a join view without a key-preserved table.
I appreciate any suggestions on it.
Thanks and Regards
SaiSorry, it looked at first as if you wanted help on the problem you encountered. After reading again your response to Zaibiman I see that you were just tricking us with the detailed explanation of the error.
To insert into a table other than the one you queried, use the on-insert trigger.
However, an Instead Of trigger on the view is usually the best method. If you have set the key mode, defined a primary key item and removed any references to rowid, as per Zaibiman, then it should work. You'll need your own locking method if the view uses Group By or Distinct. -
Insert into local table as select from remote tables
Hi all,
In Oracle DB version 11g i have the following issue:
I want to insert into a table in the current schema as selecting data from two remote tables. I execute the insert in portions of data. Firstly, when the target table where i want to insert is empty the Select as Insert is being executed very fast. But after every insert i made , the performance became worse than the previous one. I have no FKs or indexes in the local table/target table where i'm inserting/... I tried using /*+ append*/ hint but no success...what should be the reason of that?
Thanks in advance,
Alexander.a.stoyanov wrote:
Hi all,
In Oracle DB version 11g i have the following issue:
I want to insert into a table in the current schema as selecting data from two remote tables. I execute the insert in portions of data. Firstly, when the target table where i want to insert is empty the Select as Insert is being executed very fast. But after every insert i made , the performance became worse than the previous one. I have no FKs or indexes in the local table/target table where i'm inserting/... I tried using /*+ append*/ hint but no success...what should be the reason of that?
Thanks in advance,
Alexander.How should we know? You don't give enough information to be able to tell. Not even the SQL involved.
Please read {message:id=9360002} and {message:id=9360003}
and follow the advice given. -
How to insert into a table in database1 from a table in database2?
hi!
how to insert into a table in database1 from a table in
database2?
can anyone help?
Tariq.using the EXEC_SQL package.
see form help for detail.
Regards. -
How to insert into a table from 3 tables?
Hello,
How to insert into a table getting values from 3 different tables?
For example table_A has col_1 to col_10.
I want to insert into table_A,
values: col_1 to col_4 are from table_B,
col_5 is from table_C,
col_6 to col_10 are from table_D.
Thanks!Normally, you'd do this by joining B, C, and D together. In the simplest case, something like
INSERT INTO A( col1, ... col10 )
SELECT B.col1, ..., B.col4,
C.col5,
D.col6, ..., D.col10
FROM B,
C,
D,
WHERE B.someKeyColumn = C.someKeyColumn
AND C.anotherKeyColumn = D.anotherKeyColumnYou'd have to know how the data in B, C, and D relate to fill in the WHERE clause. This basically tells Oracle how to match the data in a particular row in B with the data in a particular row in C with the data in a particular row in D.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Selecting Records from 125 million record table to insert into smaller table
Oracle 11g
I have a large table of 125 million records - t3_universe. This table never gets updated or altered once loaded, but holds data that we receive from a lead company.
I need to select records from this large table that fit certain demographic criteria and insert those into a smaller table - T3_Leads - that will be updated with regard to when the lead is mailed and for other relevant information.
My question is what is the best (fastest) approach to select records from this 125 million record table to insert into the smaller table. I have tried a variety of things - views, materialized views, direct insert into smaller table...I think I am probably missing other approaches.
My current attempt has been to create a View using the query that selects the records as shown below. Then use a second query that inserts into T3_Leads from this View V_Market. This is very slow. Can I just use an Insert Into T3_Leads with this query - it did not seem to work with the WITH clause? My Index on the large table is t3_universe_composite and includes zip_code, address_key, household_key.
CREATE VIEW V_Market as
WITH got_pairs AS
SELECT /*+ INDEX_FFS(t3_universe t3_universe_composite) */ l.zip_code, l.zip_plus_4, l.p1_givenname, l.surname, l.address, l.city, l.state, l.household_key, l.hh_type as l_hh_type, l.address_key, l.narrowband_income, l.p1_ms, l.p1_gender, l.p1_exact_age, l.p1_personkey, e.hh_type as filler_data, 1.p1_seq_no, l.p2_seq_no
, ROW_NUMBER () OVER ( PARTITION BY l.address_key
ORDER BY l.hh_verification_date DESC
) AS r_num
FROM t3_universe e
JOIN t3_universe l ON
l.address_key = e.address_key
AND l.zip_code = e.zip_code
AND l.p1_gender != e.p1_gender
AND l.household_key != e.household_key
AND l.hh_verification_date >= e.hh_verification_date
SELECT *
FROM got_pairs
where l_hh_type !=1 and l_hh_type !=2 and filler_data != 1 and filler_data != 2 and zip_code in (select * from M_mansfield_02048) and p1_exact_age BETWEEN 25 and 70 and narrowband_income >= '8' and r_num = 1
Then
INSERT INTO T3_leads(zip, zip4, firstname, lastname, address, city, state, household_key, hh_type, address_key, income, relationship_status, gender, age, person_key, filler_data, p1_seq_no, p2_seq_no)
select zip_code, zip_plus_4, p1_givenname, surname, address, city, state, household_key, l_hh_type, address_key, narrowband_income, p1_ms, p1_gender, p1_exact_age, p1_personkey, filler_data, p1_seq_no, p2_seq_no
from V_Market;I had no trouble creating the view exactly as you posted it. However, be careful here:
and zip_code in (select * from M_mansfield_02048)
You should name the column explicitly rather than select *. (do you really have separate tables for different zip codes?)
About the performance, it's hard to tell because you haven't posted anything we can use, like explain plans or traces but simply encapsulating your query into a view is not likely to make it any faster.
Depending on the size of the subset of rows you're selecting, the /*+ INDEX hint may be doing your more harm than good. -
Record is not inserting into the Table thourgh forms 10g
Hi All,
I have the form built in 10g(10.1.2.0.2).
Basically the form has 2 blocks.
Block 1 with only one item, where we enter some value and hit enter(this will navigate to block2 and execute the query).
Block 2(tabular) will fetch the records. Now this block2 have 3 columns(caseid, userid, date).
Now when I insert a new record, I just need to enter the caseid only. And userid and date have to be automatically populated.
I can populate the USERID and DATE fields.
And when I enter some value in caseid item of block 2, and then do Control+S(to insert the record and Save the transaction),
i get the message saying FRM-40400: Transaction complete: 1 records applied and saved.
But when I query again for the same, I dont se the record inserted into the table.
Why is this happening?
Help please...@ Inol
There is no promary or foriegn key relation ship. The form is fetching records from just one table. As I said block1 has col1. and Block2 has col2,3,4.
@Andreas
Yes I did select * from table, select count(*) from table in SQL*Plus. Nothing is inserted.
And one thing I have to tall here is, I have a ON-INSERT trigger in block2.
The code in ON-INSERT trigger is
-- :BLOCK2.DATE := TO_DATE(:DATE,'DD-MON-YYYY') ;
/* commented since I was populating date by assigning $$DATETIME$$ to the Initial value property of the data item. */
:BLOCK2.SOURCE_CASE := :BLOCK1.SOURCE_CASEID;Forgot to tell you,
Since I was inserting the record from block2(3 columns), to the table which has 4 columns, there is another item in block 2 which has the visible property No.
So the block 2 has 4 columns. And the hidden column will hold the value that is in the item of block1. This is what i'm pushing in the ON-INSERT trigger.
Edited by: Charan on Sep 20, 2011 1:51 PM -
Oracle 10g performance degrades while concurrent inserts into a table
Hello Team,
I am trying to insert into single table via multiple threads, Some of these threads perform reasonably well but some will take really longer time, As the time goes on performance drastically degrades (even down by 500 to 600 times). With AWR report i see that there quite huge number of buffer gets there. I am not sure how can i reduce those. If i ran on a single thread this operation is consistent.
I tried quite a few options like
1. Increasing SGA Memory
2. Moving redo logs to another disk drive.
3. Trying it on a empty table
4. Trying it on a table which has huge data (4 Million rows)
5. I have even tried partitioning the table with HASH algoritm
Note: Each thread i am pupming equal amount of data (let say 25K rows).
Can any body suggest me a clue what could be the culprit here.
Thanks in Advance
Satish Kumar Ballepuuser11150696 wrote:
Can you please guide me how do i do that, I am not aware of how to generate explain plan for that query.Since you have the trace file already (and I don't mean the tkprof output), you could do the following:
Read the trace file to find the statement you're interested id - the line above it will be a +"PARSING"+ line, and will include a reference to the statement hash_value look like +'hv=3838377475845'+.
Use the hash_value to query v$sql to get the sql_id and child_number;
Use the sql_id and child number in a call to dbms_xplan.display_cursor:
PARSING IN CURSOR #7 len=68 dep=0 uid=55 oct=3 lid=55 tim=448839952404 *hv=3413100263* ad='2f6ede48'
select ... etc. (the statement I want the plan for)
SQL> select sql_id , child_number from v$sql where hash_value = *3413100263*;
SQL_ID CHILD_NUMBER
053tyaz5qzjr7 0
SQL> select * from table(dbms_xplan.display_cursor(*'053tyaz5qzjr7'*,*0*));
PLAN_TABLE_OUTPUT
SQL_ID 053tyaz5qzjr7, child number 0
select /*+ use_concat */ small_vc from t1 where n1 = 1 or n2 = 2
Plan hash value: 82564388
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | 4 |
| 1 | CONCATENATION | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 190 | 2 |
|* 3 | INDEX RANGE SCAN | T1_N2 | 10 | | 1 |
|* 4 | TABLE ACCESS BY INDEX ROWID| T1 | 10 | 190 | 2 |
|* 5 | INDEX RANGE SCAN | T1_N1 | 10 | | 1 |
Predicate Information (identified by operation id):
3 - access("N2"=2)
4 - filter(LNNVL("N2"=2))
5 - access("N1"=1)
Note
- cpu costing is off (consider enabling it)Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
"For every expert there is an equal and opposite expert."
Arthur C. Clarke
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format. -
Hi Everyone,
I am building an application that that contains information about helpdesk calls. I am using 2 tables:
Table 1 contains tracking info- TRK_CALLS
ID -primary key
USER_
ASSIGNED_TO
PROBLEM
SOLUTION
STATUS
EDIT
Table 2 contain date and time info - TRKCALLS_TIME
ID - primary key
CALL_ID - same number as ID in table 1
DATE_
TIME
I have taken the advice that Denes Kubicek gave another poster and created a workspace at apex.oracle.com and places my app in there for others to look at
workspace: kjwebb
username: [email protected]
password: gtmuc
application: calltracking2
I have a report called create/edit call tracking in there that I can either Edit or create an entry into TRK_CALLS. clicking create takes me to a form, after info is entered I have a create button that assigns the PK and inserts info into TRK_CALLS. I then have to click Edit Call Time button to input info on a form that inserts into TRKCALLS_TIME table. I would like to link these tables somehow so that when I go to the (Edit Call Time) form the Call ID is populated with the PK ID from the TRK_CALLS table.
It would be easier to insert this info all in one page but I worked on that for a long time before giving up because I could not get anything to insert into the tables so I have taken this route.
The basic desired outcome is to tie the tables with a PK, ID in table 1 and CALL_ID in table 2. So that they correspond and displayed on the report page.
Please help in any way you can and make changes to my app.
I would not be asking for help unless I have reached the ends of my apex knowledge.
Thanks and please let me know if there are any questions,
KirkI can imagine it is pretty obscure when your knowledge of PL/SQL is not (yet) so big.
The statement I wrote ar meant exactly for your situation.
OK, here we go:
First you have created a view in the Object Browser. Suppose it is called trkcalls_view .
Then you go to SQL Workshop > SQL Commands.
You cut the next statement and paste it in the upper white part of the screen, just under the autocommit checkbox. Replace the bold sequence references by the real name of the sequences that are used to populate the ID's of the two tables.
You say Run and the trigger is created.
A trigger on the view is created. Creation of such a trigger is not possible in the Object Browser, so I understand your confusion. This triggers performs when an insert in the view is performed. As you might see in the code, it creates seperate insert statements for both tables.
CREATE OR REPLACE TRIGGER bi_trkcalls_view
INSTEAD OF UPDATE ON trkcalls_view
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_id number;
bv_id2 number;
BEGIN
select sequence1.nextval into v_id from dual;
select sequence2.nextval into v_id2 from dual;
INSERT INTO TRK_CALLS
( ID
, USER_ASSIGNED_TO
, PROBLEM
, SOLUTION
, STATUS
, EDIT
VALUES
( v_id
, :new.user_assigned_to
, :new.problem
, :new.solution
, :new.status
, :new.edit
insert into TRKCALLS_TIME
( id
, call_id
, date_time
values
( v_id2
, v_id
, :new.date_time
end;
END ;good luck,
DickDral
Maybe you are looking for
-
IPod 4 can't get FaceTime to log in or call
Both my daughters have ipod 4. They were using FaceTime with no problems, then one stopped working and the only way she can login is as me. But then she can't FaceTime me as it says I'm unavailable. How do I get her login right? It won't take her App
-
I can't export my imovie project. Appears this message: "The project could not be prepared for publishing because an error occurred. (-50)" What can I do?
-
IPod 80 GB sync failures. Errorr -46
I keep getting iPod cannot sync error -46 messages when I try to load up new tunes. What does this mean? Why does it happen repeatedly? I'm getting bored of constantly resetting my iPod, is it back to the store time or is there something I can do? Ch
-
Paste over at playhead to insert video while retaining audio not working
I am trying to paste "extra" video over my bad video, using the cross dissolve transition between the original and the pasted, and then back to the original video. All this time, I am seeking to have the original audio playing. I have followed the iM
-
My system IS NOT currently up to date!!
BY THE TIME WE ALL GET THE 2.2 ON THE DI. WE WILL ALL BE SCRAMBLING FOR GINGERBREAD.