SQL & PL/SQL :: How To Find Last Or Latest Inserted Row
Apr 22, 2013
i have a table in that every month i insert rows and my table doesn't have primary key,index and date filed.for example:-table is like this
name salary Id
john5000101
brat4500102
smith4600103
john5500101
brat4600102
smith4800103
i think one cannot tell in above table whether "john" salary is 5000 or 5500(last insert row is 5000 then john salary is 5000)
when it comes to retrieve i have to pick the latest(last) insert row of particular Name.Is there any auto generated row_numbers in Oracle.
View 1 Replies
ADVERTISEMENT
Jul 31, 2010
SQL> select * from emp;
SINO BOOK UPDATION_
---------- ---------- ---------
1 UB 01-MAR-10
2 UB 12-MAR-10
3 SB 12-MAR-10
4 DB 12-MAR-10
4 MB 12-JUN-10
4 MB 31-JUL-10
6 rows selected.
SQL> SELECT sino, book, updation_date
2 FROM emp
3 WHERE updation_date IN (SELECT MAX (updation_date)
4 FROM emp
5 GROUP BY book);
SINO BOOK UPDATION_
---------- ---------- ---------
2 UB 12-MAR-10
3 SB 12-MAR-10
4 DB 12-MAR-10
4 MB 31-JUL-10
I would like to know, how to find out the latest date from above query without using group functions like max, min,order by and group by.
View 10 Replies
View Related
May 30, 2012
i m create a table emp . all user of database have privileged to read and write the emp table. now How can identify that which user have insert row in emp file ?
View 4 Replies
View Related
Mar 25, 2010
I have a table with lot of records.In this table, how do I find, which record is inserted just before a record in my question.
consider this example..
SQL> desc test1
Name Null? Type
------------------------------- -------- ----
SEQ_ID NUMBER
NAME VARCHAR2(1)
[code]....
in the above data, if I want to know what record is inserted before "1018", how can I find it.
Can we find out based on ROWID.?
View 13 Replies
View Related
Oct 5, 2010
I have a table where there is no sequence maintained and there is no time stamp column to track the inserted record.How do I find the latest inserted record in the table.
View 5 Replies
View Related
Sep 21, 2013
I am using an Oracle Forms application. When you click a check-box in the form and save it,a record is inserted to a log table, they say. The DB schema has over 1000 tables and over50 log tables. Is there way using the data dictionaly to find out which table was inserted tomost recently? I don't have access to the Forms code. My goal is to find out the table that the Form inserted the log entry to.
View 7 Replies
View Related
Oct 20, 2010
I have a table which is getting populated from a source. I dont have a time-stamp column in the table. Is there anyway to find the time when a record was inserted into the table?
View 3 Replies
View Related
Oct 7, 2012
I tried to find out recently updated table list. I couldn't find anything.
CODE>> JUST SAMPLE TRANSACTIONS >>
SQL> conn sam
Enter password:
Connected.
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$y1TXhcjGApvgQAB/AQBOpA==$0 TABLE
TAB1 TABLE
[code]........
View 1 Replies
View Related
Apr 3, 2012
I would like to retrieve only the latest repair information based on the latest date regardless of the other information, so I would like to query only items 3 and 5 in the following example.
drop table a;
create table a(
seq number,
custom_id number,
repair_id number,
repair_date date);
[code]........
View 10 Replies
View Related
Jun 9, 2011
I have a table that contains history for vehicle positions. In order to find the latest positions quickly, I've included a LATEST column that is 1 if the record is the latest position and 0 otherwise. The table is maintained via a stored procedure. The procedure first sets the latest record for the vehicle to history...
UPDATE vehicle_positions SET latest = 0 WHERE vehicle_id = <vehicle ID> AND latest = 1
It then inserts the new latest record...
INSERT INTO vehicle_positions (vehicle_id, longitude, latitude, insert_time, latest) VALUES (<vehicle_id>, <x pos>, <y pos>, SYSDATE, 1)
Is it possible for me to end up with 2 latest records?Consider this scenario...
Session #1: UPDATE vehicle_positions SET latest = 0 WHERE vehicle_id = 123 AND latest = 1
Session #2: UPDATE vehicle_positions SET latest = 0 WHERE vehicle_id = 123 AND latest = 1
Session #1: INSERT INTO vehicle_positions (vehicle_id, longitude, latitude, insert_time, latest) VALUES (123, 32.8533, -117.1180, SYSDATE, 1)
Session #2: INSERT INTO vehicle_positions (vehicle_id, longitude, latitude, insert_time, latest) VALUES (123, 32.8534, -117.1178, SYSDATE, 1)
I'd end up with 2 latest records. How can I protect against this? I considered using SELECT FOR UPDATE, but seems like there are too many negatives going that route
View 4 Replies
View Related
Aug 9, 2013
I have a query where i need to pull back the latest dated record for a tariff
my data looks like
Col_A Col_B Col_C
1| 100 29-Sep-11 Tariff_1
2| 200 24-Apr-12 Tariff_2
3| 300 17-Oct-12 Tariff_3
and i need to add a subquery which pull back the col_c with the larges Col_B i.e i need to pull back tariff_3 only
i tried using a max but dont think that will work.
...
and c.Col_c in ( select col_c where max(col_b))
View 21 Replies
View Related
Feb 4, 2011
I tried to post this issue earlier but it was not very clear. Well. Let me try to put in more better way.I have four tables storing order & customer information.
For given order number and cust _id I need to display latest record. here are my four tables.
SQL> select * from so;
ORD_NO ORD_DATE CUST_ID
---------- --------- ----------
1 01-JAN-10 10
2 02-JAN-09 20
3 03-FEB-11 30
SQL> select * from sol;
FK_ORD_NO FK_CUST_ID CUST_NAME LOCATION
---------- ---------- ------------------------- ----------
1 10 abc MA
2 20 xyz CA
3 30 ijk LA
[code]...
There will be a stored procedure that will take order_no and cust_id as input paremeters and return out ref cursor.
create procedure P1( in_ord_no in number,
in_cust_id in varchar2,
out_cur out sys_refcursor);
Here is the expected output.
Case 1 - in_ord_no =4 , in_cust_id = 10
Expected output - Empty cursor. Because bothe tables does not have matching record.
Case 2- in_ord_no = 3 in_cust_id = 30
Expected output =
[code]...
View 7 Replies
View Related
Aug 23, 2012
have a bit of a SQL trouble. I have a simple table (pcuk_BG_alloc_TAB) which stores Parts, Quantities and Applied dates
PART_NO QUANTITY APPLIED
PartA 100 10/8/2012
PartA 200 12/8/2012
PartB 30 12/8/2012
PartC 50 10/8/2012
PartC 75 15/8/2012
PartC 80 21/8/2012
I am only interested the latest applied date for each part and am looking for this to be returned in a select statement (as below)
PART_NO QUANTITY APPLIED
PartA 200 12/8/2012
PartB 30 12/8/2012
PartC 80 21/8/2012
I have tried using the max function (select part_no, quantity, max(applied) from pcuk_BG_alloc_TAB group by part_no, quantity) but seems as the records have different quantities it treats them separately.
View 21 Replies
View Related
Oct 14, 2010
identify the latest Critical Patch Update for 10g RAC. My DB server is 10g RAC 2 node cluster running on IBM Aix Pseries servers. The version is 10.2.0.3.
View 1 Replies
View Related
May 3, 2011
I want download latest critical patches of 11.1.0.7.0, 11.1.0.6.0. how can i download
View 1 Replies
View Related
Mar 17, 2011
DROP TABLE TESTING CASCADE CONSTRAINTS;
CREATE TABLE TESTING
(
DATAPERIOD DATE,
EMPLID VARCHAR2(20 BYTE),
B_OS_REASON VARCHAR2(9 BYTE)
)
TABLESPACE USERS;
[Code] ........
SQL> select * from testing order by 1;
DATAPERIO EMPLID B_OS_REAS
--------- -------------------- ---------
01-OCT-10 2387972
01-NOV-10 2387972
01-DEC-10 2387972 XXXXXX
01-JAN-11 2387972
01-FEB-11 2387972
In the above result, We need to go from bottom up and when we hit some value we need to update with the lastest record as below.("Blank" space are considered as null.)
DATAPERIO EMPLID B_OS_REAS
--------- -------------------- ---------
01-OCT-10 2387972
01-NOV-10 2387972
01-DEC-10 2387972 XXXXXX
01-JAN-11 2387972
01-FEB-11 2387972 XXXXXX
View 5 Replies
View Related
Jul 2, 2012
How to export latest n records from a table using the below query(latest n records)
select * from (select empid,ename,sal,joining_date from emp order by joining_date desc) where rownum<n;
View 3 Replies
View Related
Apr 11, 2013
Platform: windows 64 bit
Oracle database 11.2.0.3
I successfully upgraded my database from oracle 11.2.0.1.0 to 11.2.0.3.0 and the upgrade worked fine. I installed the 11.2.0.3.0 in a new oracle home.
Now my task is to install the latest patch set release on the new oracle home(Make database upto date with latest fixes indeed). I am confused with the available documentations in my oracle support.
As CPU is now considered as a subset of PSU patch, i believe i have to apply the latest PSU only.Is this correct? Is there a step by step guide for applying latest patch?I saw there are 5 PSUs released (latest 11.2.0.3.5), do i need to apply each of them or just this final one?
Give me the latest available patchset/patch(Still not clear) install guide and latest available patch download links.
View 3 Replies
View Related
Jun 18, 2012
I wanted to know the latest salary(last 2 updated records ) getting by emp- id 252 based on below mentioned information
source desti sal emp id MGR
1-Jan 1-Feb 1000 252 venkat
2-Jan 2-Feb 4000 252 venkat
2-Feb 2-Feb 5000 252 venkat
View 4 Replies
View Related
Aug 9, 2012
I want to get rows by latest date for each group pf rows.
say my data is :
TYPE1 TYPE2 quantity DATE-ORDERED
sweets chocolate 10 05-FEB-2012
sweets chocolate 10 04-DEC-2012
sweets chocolate 10 08-FEB-2012
pastries chocolate 20 08-AUG-2012
[Code] ..........
I want to get results by latest date,
sweets chocolate 10 04-DEC-2012
pastries chocolate 20 08-AUG-2012
sweets vanilla 10 05-DEC-2012
pastries vanilla 20 05-NOV-2012
I have tried Queries with Max(DATE-ORDERED) and grouping it..its not showing me results because I don't have indexes in my data.
View 2 Replies
View Related
Mar 12, 2013
I am trying to run an Oracle report with a query that has an embeded sql. this sql is returning more than 1 row, and the report is failing.
I need to pick the latest record entered that this sql return.
I tried rownnum and it works but only i can get the rown num I specify, not the latest record. I try to order, but I am getting an error back.
select w.emp_no, (select t.timestamp
from tob.work_unit t
where t.work_date = to_date('20130312', 'YYYYMMDD')
and rownum = 1
order by t.timestamp desc)
,w. spare_type
from work.work_unit w
where w.work_date = to_date('20130312', 'YYYYMMDD')
I am getting missing right parenthesis at the order by keyword My report is much complex than this, but I am tring to see if I can get the row that I want.
View 10 Replies
View Related
Sep 21, 2011
I want to know like How we can select the latest updated record from xyz table. that record has STATUS column. I also want to check if the status is RED or GREEN query should return if the status is red then 1 and if the status is GREEN then it should return 0
View 8 Replies
View Related
Mar 13, 2012
I need a query to get data for the latest date for some purchases.
My expected output would be
Date - Item - Price - Qty
10/6/2011 10129 .5 1
6/8/2011 10130 13.33 9
2/6/2011 10131 21.74 24
Below are the scripts for this.I have also attached it.
CREATE TABLE XX_PO_LINES_ALL
( CREATION_DATE DATE,
ITEM_ID NUMBER,
UNIT_PRICE NUMBER,
QUANTITY NUMBER )
[code]......
View 4 Replies
View Related
Oct 2, 2013
I read previous post "Can I use the latest features in Oracle Developer Tools 11g and still use ODP.NET version 10.x or 9.x in my application?".In this the solution was: "Solution: Yes, you can use the newest 11g version of Oracle Developer Tools while developing code that relies on ODP.NET version 10g or 9i. In almost all cases it will work fine. The only exception is with the automatic .NET code generation feature. Here is what you need to do:
a) Install both ODT 11g *and* ODP.NET 10g or 9i. They must be placed in different Oracle Homes!
b) You will now be able to use the 11g Oracle Developer Tools for Visual Studio and all of the newest features. To ensure the correct version of ODP.NET is used by your application continue to the next steps:
c) Make sure that in the "References" section in your solution, the Oracle.DataAccess.dll that is referenced is coming from the Oracle 10 or Oracle 9 Oracle home.
d) Finally, you must "ungac" (gacutil /u) the ODP.NET 11g policy DLL's or else your application will silently begin using the 11g version of ODP.NET even though the reference points to the correct DLL. There are several Oracle policy DLLs with varying names, for example: "Policy.2.102.Oracle.DataAccess.dll". Ungac them all."
Are the steps the same if i have Oracle Developer Tools 12c and still use ODP.NET version 11g R2 in my application?
View 1 Replies
View Related
Jan 22, 2013
I am having a table with 5 lakhs transactions. I want to fetch the last balance for a particular date. So i have have returned a query like below.
SELECT curr_balance
FROM transaction_details
WHERE acct_num = '10'
[Code]...
This has to be executed for incrementing of 12 months to find the last balance for each particular month. But this query is having more cpu cost, 12 times it is taking huge time. how to remodify athe above query to get the results in faster way using analytical query. Whether this can be broken into two part in PL/SQL to achive the performance. ?
View 9 Replies
View Related
Oct 17, 2012
I have not used Oracle Forms and Reports for some time. The last version I used was Developer version 6.
Has there been major changes between Oracle Developer version 6 and Oracle Developer version 11 or is Oracle Developer basically the same with some incremental improvements? What would be a good way to update my skills from Oracle Developer version 6 and Oracle Developer version 11?
View 1 Replies
View Related
Apr 19, 2010
I am trying to retrieving the latest create_date and pay_total for each act_id from the table. Table is having more than 5000000 records. I prepared the below query but it didn't the data even after 6 hours.
select a.act_id,a.create_DATE,a.Pay_TOTAL
from payment_tab a
where 1 = (select count(distinct b.create_DATE)
from payment_tab b
where b.act_id=a.act_id
and
b.create_DATE >= a.create_DATE)
i cannot create the indexes on this table.
View 11 Replies
View Related
Feb 23, 2010
How do i find out the information regarding the latest patch installed for ORACLE_HOME..
OR
If given a patch number, how do i find out whether it's applied to ORACLE_HOME
View 1 Replies
View Related
Sep 1, 2010
Am working on a workbook to count the number of enrolments and withdrawals in the program. My data looks like this
name semester status year
A 1 enrol 2010
A 2 withdraw 2010
A 3 enrol 2010
B 1 enrol 2010
B 2 withdraw 2010
I want to count their latest status only. It should come up with
Total Enrol - 2
Total Withdrawn - 1
For total Withdrawn, I tried 'rank' and filter to equals 1 but it does not allow me. Is there any way to have this work?
Here's my calculation:(decode((FIRST_VALUE(status) OVER(PARTITION BY year, name ORDER BY semester DESC)),'withdraw', name)) It tells me that 'Aggregation of Analytic function not allowed'
View 3 Replies
View Related
Oct 19, 2010
My code format is:
Insert into table1
select val1,val2
from table2,table3
where table2.col2=table3.col2
and....(some more conditions)
I am working with Oracle 10g.This insert statement is called from a procedure for nearly 3000 to 4000 time.Now my problem is even though the select statement selects correct no. of rows but still it insert only 2 or 3 rows.Apart from it ,it's working fine for some cases i.e it insert the actual no. of rows that is being selected from the select statement.
View 3 Replies
View Related