Triggers to Update rows in the same table
Hi,
I have a table called as "Cal" which has the following fields
CALID
Description
RecurringID
There will be many records with the same recurring id and If the Description field is Updated, then I would like to Update the same description to all the records with the same recurring id (same table). I have tried it with triggers and the I get the ORA-00036 Maximum number of Recursive SQL reached error.
I have a a row level trigger which captures the change and I use the statment level trigger to update the description field (same table) and I get the error mentioned above.
Thx in advance
Ravi
I have three kind of suggestion.
(1) Use session variables in a package as flag for prevention from infinitely recursive calling.
(2) Use temporary tables for similar reason.
(3) Use instead-of-trigger (need to create view).
Similar Messages
-
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 -
MULTIPLE UPDATES/INSERTIONS TO THE SAME TABLE
How can I update/insert mutiple rows into the same table from one form ?
Hi,
Using the portal form on table you can insert only a single row. You can use master-detail form to insert multiple rows.
Thanks,
Sharmila -
SUM two fileds from different rows from the same table
I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
E.g.
BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787
In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
Please help
ThanksSQL> with tbl as
2 (select 1 as ID, 90 as total from dual
3 union all
4 select 2 as ID, 23 as total from dual
5 union all
6 select 3 as ID, 15 as total from dual
7 union all
8 select 4 as ID, 20 as total from dual)
9 select id , total, sum(total) over (order by ID) as balance from tbl
10 /
ID TOTAL BALANCE
1 90 90
2 23 113
3 15 128
4 20 148
SQL> -
SUM two ROWS in the SAME Table
Hi,
I have a problem with this issue. I want to sum two rows from the same table, but I don´t know how to do that. I tried to do it with CTE, but always I get the same error "Ambiguous". I would like to ask you, if there is other manner to get that
data (sum two rows) and if it is possible to see examples about it.
Thank you in advanceHi Vaibhav,
I leave you my scrip:
USE Modelling
GO
--TABLE Aer_Lingus_Income_Statement
IF OBJECT_ID('Aer_Lingus_Income_Statement') IS NOT NULL
DROP TABLE Aer_Lingus_Income_Statement
GO
CREATE TABLE Aer_Lingus_Income_Statement
ID [nvarchar](255) NOT NULL,
Name_Account [nvarchar](255) NULL,
Company [nvarchar](255) NULL,
Level0_Account [nvarchar](255) NULL,
Level1_Account [nvarchar](255) NULL,
Level2_Account [nvarchar](255) NULL,
Level3_Account [nvarchar](255) NULL,
Level4_Account [nvarchar](255) NULL,
Level5_Account [nvarchar](255) NULL,
Level6_Account [nvarchar](255) NULL,
Level7_Account [nvarchar](255) NULL,
Level8_Account [nvarchar](255) NULL,
Year_2006 decimal (15,2) null,
Year_2007 decimal (15,2) null,
Year_2008 decimal (15,2) null,
Year_2009 decimal (15,2) null,
Year_2010 decimal (15,2) null,
Year_2011 decimal (15,2) null,
Year_2012 decimal (15,2) null,
Year_2013 decimal (15,2) null,
GO
ALTER TABLE Aer_Lingus_Income_Statement
ADD CONSTRAINT PK_Aer_Lingus_Income_Statement PRIMARY KEY (ID)
GO
INSERT INTO Aer_Lingus_Income_Statement
SELECT *
FROM Aer_Lingus_data_Income
IF OBJECT_ID('Aer_Lingus_Income_Statement_Historic') IS NOT NULL
DROP VIEW Aer_Lingus_Income_Statement_Historic
GO
CREATE VIEW Aer_Lingus_Income_Statement_Historic
as
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Revenue'
Group by Level0_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Passenger revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Ancillary revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Other revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Cargo revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Operating expenses'
Group by Level0_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Staff costs' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Depreciation, amortisation and impairment' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Aircraft operating lease costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Fuel and oil costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Maintenance expenses' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Airport charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='En-route charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Distribution costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Ground operations, catering and other operating costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Other (gains)/losses - net' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Employee profit share' and Level0_Account ='Operating expenses'
Group by Name_Account
GO
WITH sumasRevenue
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Revenue'
GROUP BY Name_Account, ID
WITH ROLLUP
, total
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasRevenue
WHERE Name_Account IS NULL
sumasOperatingExpensive
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Operating expenses'
GROUP BY Name_Account, ID
WITH ROLLUP
, total1
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasOperatingExpensive
WHERE Name_Account IS NULL
SELECT distinct ID , s.Name_Account,
(s.Y2006* 1.0 - t.Y2006) AS [V2006] ,(s.Y2007* 1.0 -T.Y2007 ) as [V2007] , (s.Y2008* 1.0 /T.Y2008 ) as [V2008],(s.Y2009* 1.0 /T.Y2009 ) as [V2009],
(s.Y2010* 1.0 /T.Y2010 ) as [V2010],(s.Y2011* 1.0 /T.Y2011 ) as [V2011],(s.Y2012* 1.0 /T.Y2012 ) as [V2012],(s.Y2013* 1.0 /T.Y2013 ) as [V2013]
FROM sumasRevenue AS s , sumasOperatingExpensive AS t
Where ID IS NOT NULL
UNION ALL
SELECT distinct ID,COALESCE(s.Name_Account,'NON CURRENT ASSETS') AS Name_Account ,
sum (s.Y2006* 1.0 / t.Y2006) as V2006,sum (s.Y2007* 1.0 / t.Y2007) as V2007,sum (s.Y2008* 1.0/ t.Y2008) as V2008,sum (s.Y2009* 1.0/ t.Y2009) as V2009,sum (s.Y2010* 1.0/ t.Y2010) as V2010,
sum (s.Y2011* 1.0 / t.Y2011) as V2011,sum (s.Y2012* 1.0/ t.Y2012) as V2012,sum (s.Y2013* 1.0/ t.Y2013) as V2013
FROM sumasRevenue as s , sumasOperatingExpensive as t
Where ID IS NULL and Name_Account IS NULL
GROUP BY Name_Account, ID
WITH ROLLUP
select *
from Aer_Lingus_Income_Statement_Historic
Thank you in advance -
Hi,
I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
These are my source and CSS codes:
Source:
<table width="600" border="0">
<tr>
<td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
<span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
</tr>
</table>
CSS:
.bottomsel {
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
.credits {
text-align: left;
.Cig84 {
color: #F00;
font-family: "Comic Sans MS", cursive;Use paragraph tags with CSS classes.
CSS:
.center {text-align:center}
.left {text-align:left}
HTML:
<table width="600" border="0">
<tr>
<td class="bottomref">
<p class="center">This text is center aligned</p>
<p class="left">This text is left aligned</p>
</td>
</tr>
</table>
Nancy O. -
How do you Copy a row to create a new row in the same table?
Hi,
We have a PurchaseOrderHeaderView object and on click of Copy Purchase Order we want to copy a row in PURCHASE_ORDER_HEADER table to create a new row. We don't want to copy the primary key only the remaining fields.
Regards
MadhuriIf you use ADF BC, you can create a new row programatically via createRow and use a sequence to create the Id and use the "original" row (probably the current row in the view object) to copy the values from to newly created row. Then use insertRow and commit to create the copied row.
Ronald -
How do I select rows from the same table that have multiple occurances
Hi Everybody,
I am trying to select records from a detail table by grouping it. The table has more than 1 million records and the query is not performing well. The basic question is how to select a distinct record from a table which matches all values in one column and any in the other.
desc SCV
ID NUMBER PK (ID + SCRID)
SCRID NUMBER FK(SC)
ID SCRID
1 1
2 1
3 1
4 2
5 2
6 3
7 4
8 4
desc PROJECTS
ID NUMBER PK
NAME VARCHAR2(100)
ID NAME
1 PROJECT1
2 PROJECT2
3 PROJECT3
4 PROJECT4
desc PJS
ID NUMBER
PROID NUMBER FK (PROJECTS)
SCRID NUMBER FK (SCV(SCRID + SCVID)
SCVID NUMBER
ID PROID SCRID SCVID
1 1 1 1
2 1 1 2
3 1 2 5
4 1 3 6
5 1 4 7
6 2 1 3
7 2 2 4
8 2 2 5
9 2 4 7
There are over 1 million records in PJS.
desc TBP
SCRID NUMBER
SCVID NUMBER
SCRID SCVID
1 1
1 2
1 3
2 4
2 5
3 6
4 7
4 8
The requirement is to select projects that have matching SCRID, SCVID from TBP such that
all distinct SCRID should match and within that and any SCVID match will do. (A "AND" between each SCRID and an "OR" for each SCVID in that SCRID like 'SCRID = 1 AND (SCVID = 1 OR SCVID = 2 OR SCVID = 3) AND SCRID = 2 AND (SCVID =....)
So, for the sample data it should return us PROID = 1
I have few queries written for this:
SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 1
INTERSECT
SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 2
INTERSECT
SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 3
INTERSECT
SELECT PROID FROM PJS,TBP WHERE TBP.SCVID = PJS.SCVID AND TBP.SCRID = 4
This query performs well but the cost is very high, hardcoding, sorting.
The 2nd option is to:
SELECT pjs.PROID proid
FROM TBP tbp,
PJS pjs
WHERE pjs.SCVID = tbp.SCVID
AND pjs.SCRID = tbp.SCRID
GROUP BY pjs.PROID
HAVING COUNT(DISTINCT pjs.SCRID) = (SELECT COUNT(DISTINCT SCRID ) FROM TBP)
This has a low cost but runs slowly.
One more way I tried was with the IN operator like
SELECT DISTINCT PROID FROM PJS A,TBP T WHERE T.SCRID = 1 AND T.SCVID = A.SCVID
AND PROID IN (SELECT PROID FROM PJS A,TBP T WHERE T.SCRID = 2 AND T.SCVID = A.SCVID
AND PROID IN (...SO ON with each DISTINCT SCRID.
Again this involves too much of sorting.
Any help will be appriciated.
Thanks in advance.Hi Andrew,
Use DELETE t_itab statement inside the loop.
I have modified your code. It is perfectly working.See bellow -
LOOP AT it_zmember01 INTO wa_zmember01.
WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',
wa_zmember01-mname UNDER 'NAME',
wa_zmember01-mdob UNDER 'DOB'.
WRITE / '-----------------------------------------------------------------'.
DELETE it_zmember01. " Modified
ENDLOOP.
DELETE it_zmember01. statement inside the loop will delete the current row of the table.
Regards
Pinaki -
Concatenate rows from the same table
Hi,
I have a table t1 with one column and 2 rows. I need to make a column with 1 row that is a concatenation of the rows from table t1.
Can someone help me with this?
Thank you.http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
Has lots of examples for you. -
Retriving multiple rows from the same table
Hi all,
I have a table consisting of an id column as well as a start and end date.
What I want to do is select the difference between start and end time for different id's.
For example select (endtime where id = 1 - starttime where id = 2).
Is this possible to do using a single select statement?
Thanks pplOK, so you want every combination of dropped_id 500 with dropped_id 1000? For example:
WITH test_data as (SELECT 500 dropped_id, TO_DATE('13/05/2009', 'DD/MM/YYYY') insert_date, TO_DATE('12/05/2009 12:00:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('12/05/2009 12:30:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL UNION ALL
SELECT 500, TO_DATE('12/05/2009', 'DD/MM/YYYY'), TO_DATE('11/05/2009 12:04:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('11/05/2009 12:41:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL UNION ALL
SELECT 500,TO_DATE('11/05/2009', 'DD/MM/YYYY'), TO_DATE('10/05/2009 12:18:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('10/05/2009 12:59:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL UNION ALL
SELECT 1000,TO_DATE('13/05/2009', 'DD/MM/YYYY'), TO_DATE('12/05/2009 12:30:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('12/05/2009 13:30:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL UNION ALL
SELECT 1000,TO_DATE('12/05/2009', 'DD/MM/YYYY'), TO_DATE('11/05/2009 12:41:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('11/05/2009 14:30:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL UNION ALL
SELECT 1000,TO_DATE('11/05/2009', 'DD/MM/YYYY'), TO_DATE('10/05/2009 12:19:00', 'DD/MM/YYYY HH24:MI:SS') starttime, TO_DATE('10/05/2009 13:30:00', 'DD/MM/YYYY HH24:MI:SS') endtime FROM DUAL)
-- end test data
SELECT tab1.insert_date insert_date1, tab2.insert_date insert_date2, tab1.dropped_id dropped_id1, tab2.dropped_id dropped_id2, ROUND(tab2.endtime - tab1.starttime,2) time_diff
FROM test_data tab1
CROSS JOIN test_data tab2
WHERE tab1.dropped_id = 500
AND tab2.dropped_id = 1000;
INSERT_DA INSERT_DA DROPPED_ID1 DROPPED_ID2 TIME_DIFF
13-MAY-09 13-MAY-09 500 1000 .06
12-MAY-09 13-MAY-09 500 1000 1.06
11-MAY-09 13-MAY-09 500 1000 2.05
13-MAY-09 12-MAY-09 500 1000 -.9
12-MAY-09 12-MAY-09 500 1000 .1
11-MAY-09 12-MAY-09 500 1000 1.09
13-MAY-09 11-MAY-09 500 1000 -1.94
12-MAY-09 11-MAY-09 500 1000 -.94
11-MAY-09 11-MAY-09 500 1000 .05
9 rows selected. -
i have a table1 on the top, but i want to create a view from table 1 as view mentioned beneath the table 2. Could any of you please help me.
table1
ID
office
employee
activity
1
246
-9999
698
2
##-99
21480
698
3
104
-9999
7025
4
##-99
88908
7025
5
108
-9999
2415
6
##-99
17135
2415
7
246
-9999
698
8
##-99
21480
698
9
104
-9999
7025
10
##-99
88908
7025
11
108
-9999
2415
12
##-99
17135
2415
view
ID
office
ID1
employee
activity
1
246
2
21480
698
3
104
4
88908
7025
5
108
6
17135
2415
7
246
8
21480
698
9
104
10
88908
7025
11
108
12
17135
2415declare @forumsTable table (ID int, officeID int, employeeID INT, activityID int)
insert into @forumsTable (ID, officeID, employeeID, activityID)
values
(1 ,246, -9999, 698 ),
(2 ,-99, 21480, 698 ),
(3 ,104, -9999, 7025),
(4 ,-99, 88908, 7025),
(5 ,108, -9999, 2415),
(6 ,-99, 17135, 2415),
(7 ,246, -9999, 698 ),
(8 ,-99, 21480, 698 ),
(9 ,104, -9999, 7025),
(10 ,-99, 88908, 7025),
(11 ,108, -9999, 2415),
(12 ,-99, 17135, 2415)
select f1.ID, f1.officeID, f2.ID as ID1, f1.employeeID, f1.activityID
from @forumsTable f1
inner join @forumsTable f2
on f1.activityID = f2.activityID
and f1.officeID > 0
and f2.employeeID > 0
and f1.id - f2.id = -1
You really need to improve the relationship here.
Perhaps you could make office and activity an exclusive pair. -
Two triggers in the same table and event
If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
RegardsIf I created two triggers on the same table and event
(before insert), which of them will be triggered
first ?...As already mentioned, prior to 11g the order of firing is undetermined.
The problem from the beginning is that I created the
second one as after insert and in the body of the
trigger I wrote (:new.xxx:= value) ... then an error
(that it should be before insert trigger or update
trigger), so I created it as before update ,,, but I
have already before update trigger (for primary
key)..... and the problem -I think- which of them
start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
Can make the second one as after insert and make
update statement instead of assigning (:new.xxx:=
value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this. -
Data of column datatype CLOB is moved to other columns of the same table
Hi all,
I have an issue with the tables having a CLOB datatype field.
When executing a simple query on a table with a column of type CLOB it returns error [POL-2403] value too large for column.
SQL> desc od_stock_nbcst_notes;
Name Null? Type
OD_STOCKID N NUMBER
NBC_SERVICETYPE N VARCHAR(40)
LANGUAGECODE N VARCHAR(8)
AU_USERIDINS Y NUMBER
INSERTDATE Y DATE
AU_USERIDUPD Y NUMBER
MODIFYDATE Y DATE
VERSION Y SMALLINT(4)
DBUSERINS Y VARCHAR(120)
DBUSERUPD Y VARCHAR(120)
TEXT Y CLOB(2000000000)
NBC_PROVIDERCODE N VARCHAR(40)
SQL> select * from od_stock_nbcst_notes;
[POL-2403] value too large for column
Checking deeply, some of the rows have got the data of the CLOB column moved in another column of the table.
When doing select length(nbc_providercode) the length is bigger than the datatype of the field (varchar(40)).
When doing substr(nbc_providercode,1,40) to see the content of the field, a portion of the Clob data is retrieved.
SQL> select max(length(nbc_providercode)) from od_stock_nbcst_notes;
MAX(LENGTH(NBC_PROVIDERCODE))
162
Choosing one random record, this is the stored information.
SQL> select length(nbc_providerCode), text from od_stock_nbcst_notes where length(nbc_providerCode)=52;
LENGTH(NBC_PROVIDERCODE) | TEXT
-------------------------+-----------
52 | poucos me
SQL> select nbc_providerCode from od_stock_nbcst_notes where length(nbc_providerCode)=52;
[POL-2403] value too large for column
SQL> select substr(nbc_providercode,1,40) from od_stock_nbcst_notes where length(nbc_providercode)=52 ;
SUBSTR(NBC_PROVIDERCODE
Aproveite e deixe o seu carro no parque
The content of the field is part of the content of the field text (datatype CLOB, containts an XML)!!!
The right content of the field must be 'MTS' (retrieved from Central DB).
The CLOB is being inserted into the Central DB, not into the Client ODB. Data is synchronized from CDB to ODB and the data is reaching the client in a wrong way.
The issue can be recreated all the time in the same DB, but between different users the "corrupted" records are different.
Any idea?939569 wrote:
Hello,
I am using Oracle 11.2, I would like to use SQL to update one column based on values of other rows at the same table. Here are the details:
create table TB_test (myId number(4), crtTs date, updTs date);
insert into tb_test(1, to_date('20110101', 'yyyymmdd'), null);
insert into tb_test(1, to_date('20110201', 'yyyymmdd'), null);
insert into tb_test(1, to_date('20110301', 'yyyymmdd'), null);
insert into tb_test(2, to_date('20110901', 'yyyymmdd'), null);
insert into tb_test(2, to_date('20110902', 'yyyymmdd'), null);
After running the SQL, I would like have the following result:
1, 20110101, 20110201
1, 20110201, 20110301
1, 20110301, null
2, 20110901, 20110902
2, 20110902, null
Thanks for your suggestion.How do I ask a question on the forums?
SQL and PL/SQL FAQ -
Compare two rows in a same table
Dear all
I need to compare two rows in the same table, I dont know hoe to do it in pl/sql. Some one please help me on this.
example:
tr br price
xya0001 ama7 12
xya0003 ama6 14
xya0004 ama7 16
in the table tr is a unique value for each row, I need to compare price column and see whether the first value is less or greater than the next value and, if it is greater put the corresponding br value to a variable and if it is smaller put the corresponding br value to another variable. I dont know a method to do it, as I'm new to pl/sql. Some one please help me in thisnot sure what you intend to do as you have mentioned that "TR" is unique and you just want to compare each record with just the next record. Hope below query helps. The value "G" or "L" in flag would indicate if the current records price is greater than or less than the price in next record.
select tr,br,price,col4, case when price> col4 then 'G' when price< col4 then 'L' end flag from (
select tr,br,price,lag(price,1,0) over(order by tr) col4 from testcomp
) -
Copy/Paste cells in the same table
How can I copy/paste rows inside the same table?
I tried with ITableModel, but its function CanPaste() returns me kFalse. And I tried with kTableCopyPasteCmdBoss/ITableCopyPasteCmdData, it crashed.
Thank you in advance,
DavidYou are correct, but this behavior has always amazed me. ID *never* inserts the correct amount of copied rows inbetween others -- rather, you have to count how much you are going to copy, then insert blanks, then paste, then double-check you didn't accidentally overwrite existing ones!
If you are writing a general plugin to handle tables, you might think about doing this automatically. I don't know, perhaps you can test how much rows are "in the copy buffer" at the time of pasting.
Maybe you are looking for
-
Connecting a WRT54G2 V1 to a ADSL Ovislink Modem router combo
I am trying to set up my linksy router to a ADSL Ovislink Modem router combo and when I install the CD on the main computer I keep getting this error message "Error 322- New router or gateway not detected" I have hooked everything up correctly as the
-
ABAP Joins or Separate select statements?
Hi, I am working on a simulation of an implementation project as part of my in-house training programme. I am a rookie to ABAP and am now doing a print program that requires master data selection from tables ANLZ, LFA1, MSEG and CSKT, and also rel
-
Accordion throwing an error when you click in it
Hi All, I've got an Accordion (code at end of message) that (when you click in it) throws the following error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at mx.containers::Accordion/focusInHandler()[E:\dev\
-
i need to download a driver for a air card and need to know if the mac book air is 64 bit or not
-
hi have a snap fish account but can not seem to be able to log in to my eprinting to see what emails have been sent to my printer can you help