Updating values with in the same table for other records matching conditions
Hi Experts,
Sorry for not providing the table structure(this is simple structure)
I have a requirement where i need to update the columns of a table based on values of the same table with some empid and date match. If the date and empid match then i have take these values from other record and update the one which is not having office details. I need the update query
Before update my table values are as below
Sort_num Emp_id office start_date
1 101 AUS 01/01/2013
2 101 01/01/2013
3 101 15/01/2013
4 103 USA 05/01/2013
5 103 01/01/2013
6 103 05/01/2013
7 104 FRA 10/01/2013
8 104 10/01/2013
9 104 01/01/2013
After update my table should be like below
Sort_num Emp_id office start_date
1 101 AUS 01/01/2013
2 101 AUS 01/01/2013
3 101 15/01/2013
4 103 USA 05/01/2013
5 103 01/01/2013
6 103 USA 05/01/2013
7 104 FRA 10/01/2013
8 104 FRA 10/01/2013
9 104 01/01/2013
Thanks in advance
I do not have time to create the table with data but basically you should be able to code the following
update table a
set office = ( select office from table b where b.emp_id = a.emp_id
and b.start_date = a.start_date
and b.office is not null
where exists ( [same query as in set] )
and a.office is null
I believe that will do the trick.
HTH -- Mark D Powell --
Similar Messages
-
Can I plot 2 locations at the same time for each record in a table
I'm trying to plot 2 Locations (2 points on a Power View Map) at the same time for each record/project in a table
I can plot 1 location for each project of course with no problem
but I'm trying to show the Begin Point and the
End Point for each project at the same time
Is this even possible?First of all THANKS this worked!
But now I stumbled on another issue. So I actually have 3 tables (and I've adopted them to the file you sent)
Table 1 => TripData
Trip
LongLat
Location
Type
TypeCode
Size
NW Tour
47.568077, -122.320800
Seattle, WA
Begin
0
1
NW Tour
47.035608, -122.884812
Olympia, WA
End
1
1
Cali Trip
37.808848, -122.412580
San Francisco, CA
Begin
0
1
Cali Trip
32.682611, -117.178348
San Diego, CA
End
1
1
Table 2 =>
TripInfo
Trip
OneLongLat
NTP
NW Tour
47.568077, -122.320800
1/1/2015
Cali Trip
37.808848, -122.412580
1/5/2015
Table 3 =>
ALLTrips
Trip
Stop
Owner
NW Tour
1
Owner1
NW Tour
2
Owner2
NW Tour
3
Owner3
NW Tour
4
Owner4
NW Tour
5
Owner5
Cali Trip
1
Owner6
Cali Trip
2
Owner7
Cali Trip
3
Owner8
Cali Trip
4
Owner9
Cali Trip
5
Owner10
Cali Trip
6
Owner11
This is how the Diagram View looks like in PowerPivot
Trip Data => Trip Info <= ALLTrips
Since I don't know how to post pictures
The MAP FIELDS are as follows
SIZE - Count of Stop(s)
LOCATIONS - OneLongLat followed by
LongLat (drill down feature)
COLOR - Trip
The problem now happens with the drill down feature
You can either plot OneLongLat which is the general location for each trip
Or LongLat of each trip which shows the begin and end points
But you can't use the drill down feature???
If instead of OneLongLat you use a
State Column it actually works!!!
I wonder if it has to do with the fact that both locations used for the drill down are Long/Lat numbers???
Any suggestions???
And again Thanks for the response! -
Trigger in mutation - Update another rows in the same table with a trigger
Hi ,
I try to do a before update trigger on a table , but the trigger is in mutation. I understand why it do that but my question is :
How can I update other rows in the same table when a UPDATE is made on my table??????
Here is my trigger :
CREATE OR REPLACE TRIGGER GDE_COMPS_BRU_5 BEFORE
UPDATE OF DEPARTEMENT--, DISCIPLINE, DEG_DEMANDE, CE_ETAB
ON GDEM.COMPOSITION_SUBV
FOR EACH ROW
Organisme : FQRNT-FQRSC
Date de création : 14-07-2011
Date de modification :
Modifié par :
Auteur : Johanne Plamondon
Description : Ce déclencheur s'executera lors de la modification
du responsable dans la table COMPOSITION_SUBV
DECLARE
V_OSUSER V$SESSION.OSUSER%TYPE;
V_PROGRAM V$SESSION.PROGRAM%TYPE;
V_TERMINAL V$SESSION.TERMINAL%TYPE;
V_MACHINE V$SESSION.MACHINE%TYPE;
V_MODULE V$SESSION.MODULE%TYPE;
V_LOGON_TIME V$SESSION.LOGON_TIME%TYPE;
V_AUDIT_ID NUMBER;
vSEQ NUMBER;
i NUMBER;
vID DEMANDE.ID%TYPE;
BEGIN
begin
SELECT OSUSER, PROGRAM, TERMINAL,MACHINE,MODULE, LOGON_TIME
INTO V_OSUSER,V_PROGRAM,V_TERMINAL,V_MACHINE,
V_MODULE,V_LOGON_TIME
FROM V$SESSION
WHERE TYPE = 'USER'
AND USERNAME = USER
AND LAST_CALL_ET IN (0,1)
AND ROWNUM < 2;
exception when others then null; end;
IF NVL(:NEW.SC_PART,' ') = 'CHC' THEN
SELECT COUNT(*)
INTO i
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
IF i = 1 THEN
SELECT ID
INTO vID
FROM DEMANDE
WHERE DEM_REF = :NEW.DEM_ID
AND PER_NIP = :NEW.PER_NIP;
UPDATE COMPOSITION_SUBV
SET --CE_ETAB = :NEW.CE_ETAB,
--DISCIPLINE = :NEW.DISCIPLINE,
DEPARTEMENT = :NEW.DEPARTEMENT,
--DEG_DEMANDE = :NEW.DEG_DEMANDE,
DATE_MODIF = SYSDATE,
USER_MODIF = V_OSUSER
WHERE DEM_ID = vID
AND PER_NIP = :NEW.PER_NIP
AND ANNEE = :NEW.ANNEE;
END IF;
END IF;
/*EXCEPTION
WHEN OTHERS THEN
NULL;*/
END;A standard disclaimer, the mutating trigger error is telling you that you really, really, really don't want to be doing this. It generally indicates a major data model problem when you find yourself in a situation where the data in one row of a table depends on the data in another row of that same table. In the vast majority of cases, you're far better off fixing the data model than in working around the problem.
If you are absolutely sure that you cannot fix the data model and must work around the problem, you'll need
- A package with a collection (or global temporary table) to store the keys that are modified
- A before statement trigger that initializes the collection
- A row-level trigger that adds the keys that were updated to the collection
- An after statement trigger that iterates over the data in the collection and updates whatever rows need to be updated.
If you're on 11g, this can be simplified somewhat by using a compound trigger with separate before statement, row-level, and after statement sections.
Obviously, though, this is a substantial increase in complexity over the single trigger you have here. That's one of the reasons that it's generally a bad idea to work around mutating table exceptions.
Justin -
Comparing SQL data in the same table for two different dates
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
Hello,
We have a batch scheduling tool that automatically runs Oracle jobs and when it runs the jobs it stores a record from the instance in a table. I am trying to write a query that pulls up all of the jobs that ran today and compares them with what ran on the same day last week to find out what jobs didnt run today. So far I have the below but I can't get it to return anything. I am using Toad for this
select *
from xxcar_abat_instances
where trunc(to_date(start_datetime)) = trunc(sysdate-7)
and completion_status = 'Success'
AND NOT EXISTS
(select script_name
from xxcar_abat_instances
where trunc(to_date(start_datetime)) = trunc(sysdate)
and completion_status = 'Success')Thank youHi,
964188 wrote:
It is a date
Such as
10/31/2012 11:55:03 PMThen, as Hoek says, you don't want TO_DATE. For example:
WHERE TRUNC (start_datetime) = TRUNC (SYSDATE - 7) or the more efficient
WHERE start_datetime >= TRUNC (SYSDATE - 7)
AND start_datetime < TRUNC (SYSDATE - 6)Also, it doesn't look like the EXISTS sub-query is corelated to the main query. That's almost certainly a mistake.
If you're still having trouble, post your revised query, a little sample data (CREATE TABLE and INSERT statements). Point out where that query is givimg the wrong results, and explain how to get te right results.
See the forum FAQ {message:id=9360002} -
Update/Insert/Delete into the same table
Hi,
I'm writing pl/sql code :
nvoice_id will be passed as parameter and based on invoice_id I need to see whether any records exist in history table.If not any then insert record into table.If more than one record exist then I need delete all except most recent one based hist_seq column in that table.
Then I need to update that record for description column .How to put dml operation one after another in an efficient manner?As one statement depend on another do I need to use autonomous transaction?
Thanks,
Kiranuser518071 wrote:
Hi,
I'm writing pl/sql code :
nvoice_id will be passed as parameter and based on invoice_id I need to see whether any records exist in history table.If not any then insert record into table.If more than one record exist then I need delete all except most recent one based hist_seq column in that table.
Then I need to update that record for description column .How to put dml operation one after another in an efficient manner?As one statement depend on another do I need to use autonomous transaction?
Thanks,
KiranBasic idea.
create procedure p_deal_with_invoice
p_invoice_id number
l_max_hist_seq number;
is
begin
select max(hist_seq)
into l_max_hist_seq
from your_table
where invoice_id = p_invoice_id;
if l_max_hist_seq is not null
then
delete from your_table
where invoice_id = p_invoice_id
and hist_seq != l_max_hist_seq;
update your_table set some_columns = some_new_value
where invoice_id = p_invoice_id
and hist_seq = l_max_hist_seq;
else
insert into your_table () values ();
end if;
end p_deal_with_invoice;
/An autonomous transaction would probably be the last thing you'd want here. Just a simple plsql procedure that accepts a INVOICE_ID as an input.
Cheers,
Edited by: Tubby on Jun 18, 2012 2:53 PM -
Update and Select from the same table
Hello,
i have this select - i tested it and its working
[code]
select
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT
else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
end
as KTBT_ISO,
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN
else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
end
as KTZN_ISO,
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB
else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
end as KTAB_ISO,
DTF_REEW_201301.brnrn,
DTF_REEW_201301.ktat
from
reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
reewdq.DTF_REEW_201301 DTF_REEW_201301
where
(DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
[/code]
With the result from KTBT_ISO, KTZN_ISO and KTAB_ISO i want to update the table "reewdq.DTF_REEW_201301" - and this table is in the select-statement!
I believe, i tried every update-statement - but no update is working.
I need something like this:
[code]
update reewdq.DTF_REEW_201301 t1 set t1.KTBT_ISO=
select
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT
else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
end
as KTBT_ISO
from
reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
reewdq.DTF_REEW_201301 DTF_REEW_201301
where
(DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
t1.KTZN_ISO=
select
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN
else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
end
as KTZN_ISO
from
reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
reewdq.DTF_REEW_201301 DTF_REEW_201301
where
(DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
t1.KTAB_ISO=
select
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB
else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
end as KTAB_ISO
from
reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
reewdq.DTF_REEW_201301 DTF_REEW_201301
where
(DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT)
and CTF_REEW_KUM_201301.KTMO = (DTF_REEW_201301.KTMO - 1)
[/code]
But this code isn´t working. Has someone an idea please? Can someone please help me.
Best regards
HeidiUse MERGE:
merge
into reewdq.DTF_REEW_201301 t1
using (
select case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTBT
else DTF_REEW_201301.KTBT - CTF_REEW_KUM_201301.KTBT
end as KTBT_ISO,
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTZN
else DTF_REEW_201301.KTZN - CTF_REEW_KUM_201301.KTZN
end as KTZN_ISO,
case
when DTF_REEW_201301.KTMO =1 then DTF_REEW_201301.KTAB
else DTF_REEW_201301.KTAB - CTF_REEW_KUM_201301.KTAB
end as KTAB_ISO,
reewdq.ROWID as rid
from reewcore.CTF_REEW_KUM_201301 CTF_REEW_KUM_201301,
reewdq.DTF_REEW_201301 DTF_REEW_201301
where DTF_REEW_201301.BRNRN = CTF_REEW_KUM_201301.BRNRN
and DTF_REEW_201301.KTAT = CTF_REEW_KUM_201301.KTAT
and CTF_REEW_KUM_201301.KTMO = DTF_REEW_201301.KTMO - 1
) t2
on (
t1.rowid = t2.rid
when mathed
then
update
set t1.KTBT_ISO = t2.KTBT_ISO,
t1.KTZN_ISO = t2.KTZN_ISO,
t1.KTAB_ISO = t2.KTAB_ISO
SY. -
How to implement multiple Value Helps within the same Application ??
Dear Experts,
I want to implement multiple value helps in the same view.For that I have declared exporting parameters of type 'wdy_key_value_table.' within the component controller for each of the value helps.While I do activate and test the application I get the following error :
The following error text was processed in the system HE6 : A row with the same key already exists.
The error occurred on the application server hsdnt24s11_HE6_00 and in the work process 4 .
The termination type was: RABAX_STATE
The ABAP call stack was:
Method: VALUESET_BSART of program /1BCWDY/9VSHJWRNR0EZPKFT3ZKC==CP
Method: IF_PO_VIEW1~VALUESET_BSART of program /1BCWDY/9VSHJWRNR0EZPKFT3ZKC==CP
Method: WDDOINIT of program /1BCWDY/9VSHJWRNR0EZPKFT3ZKC==CP
Method: IF_WDR_VIEW_DELEGATE~WD_DO_INIT of program /1BCWDY/9VSHJWRNR0EZPKFT3ZKC==CP
Method: DO_INIT of program CL_WDR_DELEGATING_VIEW========CP
Method: INIT_CONTROLLER of program CL_WDR_CONTROLLER=============CP
Method: INIT_CONTROLLER of program CL_WDR_VIEW===================CP
Method: INIT of program CL_WDR_CONTROLLER=============CP
Method: GET_VIEW of program CL_WDR_VIEW_MANAGER===========CP
Method: BIND_ROOT of program CL_WDR_VIEW_MANAGER===========CP
I dont know how to implement multiple value helps.Need your help on this.
Regards,
Mamai.Hi
Hint is : A row with the same key already exists it means , It is assigning the same value/Key to row and you are calling it at WDDOINIT so it giving error at the time of initialization .
Better way to do the coding at some event in view OR if not possible than just execute the first value help in wddoinit later clear all the value before gettig the other Value help. Code it at WdDoModify View to get its run time behaviour.
BR
Satish Kumar -
I had an interview question that is:
How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) From another server ex: Transaction server?
Set up steps so inset, update or delete operation takes place across the servers.
It would be great if someone please enlighten me in details about this process in MS SQL Server 2008 R2.
Also please describe would it be different for SQL Server 2012?
If so, then what are the steps?I had an interview question that is:
How to update a table (Customer) on a server ex: Report Server with the data from the same table (Customer) from another server ex: Transaction server?
Set up steps so that inset, update or delete operation gets done correctly across servers.
I was not sure about the answer, it would be great if someone please put some light on this and explain in details about this process in MS SQL Server 2008 R2.
Also it would be very helpful if you please describe would it be different for SQL Server 2012? If so, then what are the steps? -
Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
I am using this code :
<HTML>
<HEAD>
<SCRIPT>
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++ ) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;}}}
function deleteRow(tableID) {
try {var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 2) {
alert("Cannot delete all the rows.");
break;}
table.deleteRow(i);
rowCount--;
i--;}}}catch(e) {alert(e);}}
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD width="32"></TD>
<TD width="119" align="center"><strong>Activity</strong></TD>
<TD width="177" align="center"><strong>Cost</strong></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>
<select name="s1" id="s1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</TD>
<TD><input type="text" name="txt1" id="txt1"></TD>
</TR>
</TABLE>
</BODY>
</HTML>Hi,
Let me make sure u r working with table control.
First u have to create a event(VALIDATE) to do the validation.
Inside the event,
1. First get the current index where user has pointed the curson
2. Once u get the index read the internal table with index value.
3. Now u can compare the col1 and col2 values and populate the error message.
1. DATA : lo_elt TYPE REF TO if_wd_context_element,
l_index type i.
lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
CALL METHOD LO_ELT->GET_INDEX( RECEIVING MY_INDEX = l_index.
above code should be written inside the event.
Thanks, -
As the title says.
I was installing the new EFI software update on my macbook pro and I became stuck on the grey screen with the window that said "installing 2 items", its been on the same screen for 2 1/2 hours. does anyone know what I can do?
I don't want to restart it because im scared that something might go wrong.
operating lionLimitLess- wrote:
Hi,
I had the power supply connected when I attempted it previously but even so my problem occurred. My rom is different and so I still need to update it.
Thanks
I wanted to mark your answer helpful too but I didn't know that I could only put it for 2 answers. Sorry
That was good advice by G-N and s/he is correct about it. Unfortunately, ASC allows only 2 "helpful" and 1 "correct" marks per thread. -
With in the internal table can I READ the same internal table for a record?
With in the internal table can I READ the same internal table?
For Suppose
LOOP AT itab.
can I do as below
READ TABLE itab with key bukrs = itab-bukrs
belnr = itab-belnr.
*and I have to compare
IF itab-shkzg = itab-shkzg_ia.
ENDIF.
ENDLOOP.Hi,
Yes..But use work area to differentiate..
EX.
DATA: WA LIKE ITAB.
DATA: WA_READ LIKE ITAB.
LOOP AT itab <b>INTO WA</b>.
can I do as below
READ TABLE itab <b>INTO WA_READ</b>
with key bukrs = itab-bukrs
belnr = itab-belnr.
*and I have to compare
IF <b>WA</b>-shkzg = <b>WA_READ</b>-shkzg_ia.
ENDIF.
ENDLOOP.
Please reward for helpful answers.
Thanks,
Naren -
UPDATE involving the same table in sub query
DB version: 11.2
We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
UPDATE shp_gc_track a
SET f_tran_proc = 'Y'
WHERE last_update_date <
(SELECT MAX (last_update_date)
FROM shp_gc_track b
WHERE a.shp_trx_rowid = b.shp_trx_rowid
AND a.c_shp_inst = b.c_shp_inst
AND a.f_tran_proc = b.f_tran_proc
AND b.f_ltr_received = 'D'
AND f_rec_code IN ('G', 'W')
AND b.f_rec_status = 'B'
AND b.c_shp_inst = :b1
AND a.c_shp_inst = :b1
AND a.f_ltr_received = 'D' -----------------> part of composite index
AND a.f_tran_proc = 'N' -----------------> part of composite index
AND a.f_rec_code IN ('G', 'W') --------------> part of composite index
AND a.f_rec_status = 'B'; -----------------> part of composite index This UPDATE takes a long time to execute and sometime get hung.
We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
Is there anyway to rewrite this query or any other suggestions ?Steve_74 wrote:
DB version: 11.2
We have a table called SHP_GC_TRACK which has around 8 million records with partitions . In the below UPDATE, it is updating a column based on the SELECT on the same table in a subquery.
UPDATE shp_gc_track a
SET f_tran_proc = 'Y'
WHERE last_update_date <
(SELECT MAX (last_update_date)
FROM shp_gc_track b
WHERE a.shp_trx_rowid = b.shp_trx_rowid
AND a.c_shp_inst = b.c_shp_inst
AND a.f_tran_proc = b.f_tran_proc
AND b.f_ltr_received = 'D'
AND f_rec_code IN ('G', 'W')
AND b.f_rec_status = 'B'
AND b.c_shp_inst = :b1
AND a.c_shp_inst = :b1
AND a.f_ltr_received = 'D' -----------------> part of composite index
AND a.f_tran_proc = 'N' -----------------> part of composite index
AND a.f_rec_code IN ('G', 'W') --------------> part of composite index
AND a.f_rec_status = 'B'; -----------------> part of composite index This UPDATE takes a long time to execute and sometime get hung.
We have a composite index on four columns f_ltr_received, f_rec_code, f_rec_status, f_tran_proc . Explain plan shows this composite index is being used.
Is there anyway to rewrite this query or any other suggestions ?Tuning updates with subqueries can be hard :(. Sadly my suggestions below are of the try-it-and-see-what-happens variety - nothing certain
First, check the index. Is it bitmap or b-tree? If b-tree see if the most restrictive columns are listed first - this can help with b-tree index efficiency. Also if b-tree a composite bitmap for columns with lots of repeating values instead might help
Its a correlated subquery so you can't just run the subquery first putting the result into a scalar varaiable and using the variable in the SQL instead. You can try putting the results of the subuqery w/join keys in a GTT first using the GTT in the SQL to see if I/O is reduced overall during both operations.
Do you have the licence for the parallel query option? Using parallel DML (this must be turned on manually) might help. Check the docs for the ALTER SESSION command to do this. Also, the PARALLEL_INDEX() hint might help
Post the execution plan of the SQL -
Nsert/Update and Add Column at the same Table and at the "same" Time
Hello,
I want Insert/Update and Add Column at the same Table and at the "same" Time but in different sessions.
Example:
At first the "insert/update" statement:
Insert into TestTable (Testid,Value) values (1,5105);
After that the "add" statement:
Alter table TestTable add TestColumn number;
- sadly now I get the message: ORA-00054: resource busy and acquire with NOWAIT specified
"insert/update" statement:
Insert into TestTable (Testid,Value) values (2,1135);
After that the execute commit.
I don't know when the first session set the commit statement so I want that the DB the "Alter Table..." statement execute if it's possible.
If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.
Thanks for ideasWell I want to walk in the rain without and umbrella and still stay dry, but it ain't gonna happen.
You can't run a DDL statement against a table with transactions pending. Session 2 has to wait until session commits or rollbacks (or until the session is killed). That's just the way it is.
This makes sense if you think about it. The data dictionary has to be consistent across all sessions. If session 2 was allowed to change the table structure whilst session 1 has a pending transaction then the database is in an inconsistent state. This is easier to see if you consider the reverse situation - the ALTER TABLE statement run by session 2 does a DROP COLUMN TESTID rather than adding a column: now what should happen to session 1's INSERT statement? You have retrospectively invalidated a statement that was perfectly legal when it was executed.
If it's possible I want to save a repeat loop with the "Alter Table..." statemtent.Fnord.
Cheers, APC -
Hello! How I can be on the same page with the same table insert and update operations using 2 different forms (single form and tabular form)
I have little knowledge of Apex, but I know PLSQL
Thanks
Ginger
EcuadorThank you Gramps. It took some time, but I've got it working now. I had to re-do all the user authentication actions from scratch for one of the databases, but it's finally behaving itself now. I appreciate you pointing me in the right direction.
-
Trigger to Update in the same table.
Hi,
I would like to create a trigger that when we insert into table ALL_CAPACITY_SNS_CELL1 it updates column Action on teh same table,if teher is an update, it will update the same table , column ACTION.
This is what I have attempted but seems to be technically wrong.
<pre>
create table ALL_CAPACITY_SNS_CELL1
( A varchar2,
action char(2),
date_executed date);
create or replace
TRIGGER ALL_CAPACITY_HISTORY_TRACKING
AFTER INSERT OR DELETE OR UPDATE ON ALL_CAPACITY_SNS_CELL1 FOR EACH ROW
DECLARE
v_operation VARCHAR2(10) := NULL;
BEGIN
IF INSERTING THEN
v_operation := 'I';
ELSIF UPDATING THEN
v_operation := 'U';
ELSE
v_operation := 'D';
END IF;
IF INSERTING
UPDATE ALL_CAPACITY_SNS_CELL1
SET ACTION =v_operation,
DATE_EXECUTED =sysdate ;
ELSIF UPDATING THEN
UPDATE ALL_CAPACITY_SNS_CELL1
SET ACTION =v_operation,
DATE_EXECUTED =sysdate ;
END IF;
END;
</pre>CrackerJack wrote:
But above query made all ACTION nul...so we shoudl after insert or update trigger right?Obviously it is not working. You modified my code the way it does not make sense.
IF INSERTING
THEN
:NEW.ACTION := 'I';
IF UPDATING
THEN
:NEW.ACTION := 'U';
ELSE
:NEW.ACTION := 'X';
END IF;The code above checks if trigger fired on INSERT (IF INSERTING). In THEN branch of that IF you check if trigger fired on UPDATE. It makes no sense. Now, if you would use my trigger:
SQL> create table ALL_CAPACITY_SNS_CELL1
2 ( A varchar2(1),
3 action char(2),
4 date_executed date);
Table created.
SQL> create or replace
2 TRIGGER ALL_CAPACITY_HISTORY_TRACKING
3 BEFORE INSERT
4 OR UPDATE
5 ON ALL_CAPACITY_SNS_CELL1
6 FOR EACH ROW
7 BEGIN
8 IF INSERTING
9 THEN
10 :NEW.ACTION := 'I';
11 ELSE
12 :NEW.ACTION := 'U';
13 END IF;
14 :NEW.DATE_EXECUTED := sysdate ;
15 END;
16 /
Trigger created.
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('A')
2 /
1 row created.
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('B')
2 /
1 row created.
SQL> alter session set nls_date_format='mm/dd/yyyy hh24:mi:ss'
2 /
Session altered.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
A I 05/13/2009 08:56:02
B I 05/13/2009 08:56:09
SQL> update ALL_CAPACITY_SNS_CELL1
2 set a = 'X'
3 where a = 'B'
4 /
1 row updated.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
A I 05/13/2009 08:56:02
X U 05/13/2009 08:57:05
SQL> update ALL_CAPACITY_SNS_CELL1
2 set a = 'Y'
3 /
2 rows updated.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
Y U 05/13/2009 08:57:21
Y U 05/13/2009 08:57:21
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('C')
2 /
1 row created.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
Y U 05/13/2009 08:57:21
Y U 05/13/2009 08:57:21
C I 05/13/2009 08:57:53
SQL> SY.
Maybe you are looking for
-
LDAP Server Configuration in Weblogic
Hi, While configuring LDAP provider in the existing weblogic server, I am facing issue while importing the certificate [.cer files] into the weblogic server for installation. Could someone provide the sequential steps that need to be followed to setu
-
Updated email lists on all devices?
I have migrated from mobile.me to iCloud. I cannot get all devices to make emails appear as read. Emails that I have read on the Mac appear as unread on my iPhone and iPad and vice versa. Of course I want my emails to be u to date on all devices. Is
-
Troubles in dual boot system after BIOS update
Hello: PC: Thinkpad T500 1. I had for one year Linux Fedora 10 and Vista Ultimate working in dual boot with Grub, no problems at all. Three days ago Lenovo support recommended I update my BIOS from 2.07 to 3.12, as I had some intermitent Sleep proble
-
Can I create a JTA EntityManagerFactory in a utility class in a .jar file?
I have utility classes in a .jar file inside of a .war file deployed in Glassfish 3.1. One of these utility classes, CredentialsUtil, needs to access a database. I can't inject an EntityManager into CredentialsUtil since it is not an EJB. (For securi
-
Need info about making brush strokes into objects
I have been using a Wacom graphics tablet and Freehand to create my illustrations for many years (since Freehand v.2). Since Freehand's days are obviously numbered, I have finally decided to make the switch. So far, it hasn't been that difficult, but