Get Latest Records?
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
ADVERTISEMENT
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
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
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
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
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
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
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
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
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
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
May 11, 2013
which is really a HA zone clustered in VCS(not important for installation of the database).
What parameters do I need to set or change in the Solaris zone, there seems to be no /etc/system file.
View 3 Replies
View Related
Jul 11, 2012
I need to install Oracle client to get latest sql plus working on client pc as the problem is, i am not able to find out where i can download this , i just need the sql plus as i am not able use many commands because when i installed oracle forms 6i client tool , sql plus 8.0 got installed.
View 4 Replies
View Related
Jun 1, 2010
I am trying to update records in the target table based on the records coming in from source. For instance, if the incoming record is present in the target table I would update them in the target else I would simply insert. I have over one million records in my source while my target has 46 million records. The target table is partitioned based on calendar key. I implement this whole logic using Informatica. Looking at the informatica session log I find that the informatica code is perfectly fine but its in the update part it takes long time (more than 5 days to update one million records). find the TARGET TABLE query and the UPDATE query as below.
TARGET TABLE:
CREATE TABLE OPERATIONS.DENIAL_REGRET_FACT
(
CALENDAR_KEY INTEGER NOT NULL,
DAY_TIME_KEY INTEGER NOT NULL,
SITE_KEY NUMBER NOT NULL,
RESERVATION_AGENT_KEY INTEGER NOT NULL,
LOSS_CODE VARCHAR2(30) NOT NULL,
PROP_ID VARCHAR2(5) NOT NULL,
[code].....
View 9 Replies
View Related
Feb 21, 2011
I have written the following PL/SQL procedure to delete the records and count the number of records has been deleted.
CREATE OR REPLACE PROCEDURE Del_emp IS
del_records NUMBER:=0;
BEGIN
DELETE
FROM candidate c
WHERE empid in
(select c.empid
from employee e,
candidate c
where e.empid = c.empid
and e.emp_stat = 'TERMINATED'
);
[code]....
View 6 Replies
View Related
Sep 19, 2011
I am having trouble retrieving the Max, latest date, from a table with a join to one another table and other fields from both.I was able to get the MAX service_date grouped by id. But once I tried to add more fields to the query and another table it won't work.
Here is what I have:
selectMAX(cs.service_date), cs.notes, cs.applicant_id,wr.program_code,wr.last_name,wr.first_name,wr.region_code,wr.status_cd
from cs join wr on cs.applicant_id=wr.applicant_id
where wr.status_cd='AC'
group by cs.applicant_id
View 3 Replies
View Related
Dec 14, 2011
I have backup my db many times in one day,and there are many backup sets,how to know which is the the latest backup sets?
View 10 Replies
View Related
Sep 6, 2010
I am running a query in our Clarity PPM database to return a list of all Support projects. This returns a simple list of project code and project name:
The query has the project resource tables associated with it, so I am able to list all resources allocated to the project. But for now i am only selecting a DISTINCT list of projects.
Query for anyone interested:
Select distinct
Project_code,
project_name
from
niku.nbi_project_current_facts nbip,
niku.odf_ca_project cst,
niku.prtask t,
[code]........
I have a separate query which returns a list of support resources.
select res.full_name, res.unique_name , dep.description
from niku.srm_resources res,
niku.pac_mnt_resources pac,
niku.departments dep
where res.unique_name = pac.resource_code
and pac.departcode = dep.departcode
and res.is_active = 1
and description like 'IMS%'
and UPPER(dep.description) like '%SUP%'
What I need to be able to do in the first query, is return only projects that do NOT have a resource that appears in the resource list in the second query.
(the res.unique_name field in the second query can be linked to the same in the first query)
Logically, the process would be:
1. Identify Support Project
2. Identify Resources allocated to the project team
3. Compare with List of Support Resources
4. If any Resources in that list do NOT appear on the project, then return project.
View 18 Replies
View Related