SQL & PL/SQL :: How To Select Latest Updated Record From Table
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
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.
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.)
There are two tables like I posted below.I want a SQL query which selects all the rows from TABLE A which are not present in TABLE B. Also the select statement should pick all those rows which has updated value of COL_A2 in TABLE A.
TABLE A COL_A1COL_A2
AAAMOBILE BBBTABLET CCCDESKTOP DDDUNKNOWN
TABLE B COL_B1COL_B2
AAAMOBILE BBBUNKNOWN CCCDESKTOP
The select statement should return following rows from TABLE A
I have a multi record block . I need to implement a functionality where the user updates a field in the record but the form saves the previous version of the record in another table ..
I have a fairly standard Purchase Order form which contains pre-loaded data (been uploaded from an XML file).When the Purchase Order is processed, the form updates a Price History table only if the Price on the PO_Details changes.The code for updating the price history table is contained in a PRE_UPDATE trigger on the PO_Details Data Block.
No other data changes on the PO_Details table.I now want to change this so that the Price History table is updated even if the price does not change i.e I want to create a history record for each record on the PO_Details irrespective of whether it was updated or not.
Is there an alternative trigger that I can move my code to (ie move it from PRE_UPDATE) to some other trigger that is fired for each PO_Details record even if there is no change.
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.
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'
I have a table(emp): empno, ename, job, created by, creation_date
My form :
windows: 1. main window 2. find window
Main Window: It contains data block(emp block) on table emp. Shows 'empno', 'ename', 'job', 'INSERT' button,and 'UPDATE' button.
Find Window: It contains 'empno', 'ename', 'job','created_by','creation_date', and 'FIND' button.
If i search through FIND window, it will fetch the data from 'EMP' table and shows in MAIN window, emp block.
FIND BUTTON: SELECT empno, ename, job FROM emp WHERE empno=:blockemp.empno AND ename=:blockemp.ename AND job=:blockemp.job AND created_by=:blockemp.created_by AND creation_date=:blockemp.creation_date
[code]....
If i query data(F11) on block emp, i can update data any number of times, it's working fine.But if i search through the FIND window, if i udpate a record, first time, it's updating; but second time if i try update the record,it's giving below error.
ERROR:frm-40654 Record has been updated by another user.Re Query to see change
I understand that it's locking the table if manually update it(when i search data through FIND window).
I'm looking for a solution to select the first row that is not currently locked in a table and insert a record to another table that reference that first row. this is my scenario:
create table ticket ( id number(10) not null,, ticket_type number(1) not null,, is_sold number(1) not null, CONSTRAINT ticket_pk PRIMARY KEY (id) );
cust_id cust_name ticket_id ------------ -------------------- ---------- 1 John 10000004 2 Sara 10000005
my goal is finding the first free ticket ( not sold ) in the ticket table and insert buyer information of that ticket in customer_ticket table. at last I will mark that ticket as a sold one in ticket table with update.
Problem is that the first transaction locks the the first row in ticket table and the second transaction running the same query goes to wait untill the first transaction commit or rollback. However when first transaction finish successfully, second transaction select duplicate id from ticket table that was selected by the first transaction!
I tried to solve problem with "skip locked" and "nowait" options with select for update, but they didn't work.
I want to write a simple stored procedure and I want to keep it as simple as possible (no loop, the least amount of parameters ...etc.)
Basically, the procedure receives a Table Of Record as input parameters and needs to merge it with existing table, the table of record is of the rowtype of the existing table.
I have difficulties to merge these data. Below is what I tried
CREATE or REPLACE PACKAGE BIZ_xxx_MERGE IS TYPE xxx_ACTIVITE_Type IS TABLE OF MyTbl%RowType INDEX BY BINARY_INTEGER; PROCEDURE MERGE_xxx_ACTIVITE_SP ( MyLP IN xxx_ACTIVITE_Type ); END BIZ_xxx_MERGE;
CREATE OR REPLACE PACKAGE BODY BIZ_xxx_MERGE AS PROCEDURE MERGE_xxx_ACTIVITE_SP ( MyLP IN xxx_ACTIVITE_Type ) AS BEGIN MERGE INTO MyTbl [code].........
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.
how to select 1st record from duplicate vales in a table.
If we created one table with out primary key column In form in search block have uwi value and top_depth value when i enter uwi and top_depth value then when i click search button then it will display all values in master block.
but here duplicate values r there.
SQL> select rownum,uwi,top_depth,base_depth,test_start_date from well_pre_header;
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
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 want to know that How to find which table got last updated and how to find last DDL and DML operation obtained in which table? here I know the table name
SQL> SELECT LAST_DDL_TIME FROM DBA_OBJECTS WHERE OBJECT_NAME='PREM';
LAST_DDL_ --------- 20-MAR-12
SQL> TRUNCATE TABLE PREM;
Table truncated.
SQL> SELECT LAST_DDL_TIME FROM DBA_OBJECTS WHERE OBJECT_NAME='PREM';
LAST_DDL_ --------- 10-APR-12
Note: With out enable the auditing I want to know that .
when the tables are updated, the following detals must be correct to ensure that the links in the affected tables are in place.
PLUPDATE_NEW(PLUP_SAVE_SEQ field value) must be the same with PLUPDATE_BENEF_NEW (PLUP_NEW_BENEF_SAVE_SEQ field value) PLUPDATE_OLD(PLUP_SAVE_SEQ field value) must be the same with PLUPDATE_BENEF_OLD (PLUP_OLD_BENEF_SAVE_SEQ field value)?
[Code]....
i tried this code, what should i do in the link for this tables?
The requirement is, the combination of col1,col2,col3 and col4 should always be unique, and wherever the col1, col2,col3 are same then col4 should be the sequence, starting from 1. Likewise the data should be updated back to the table.I'm able to do this using PL/SQL. Can I do the same using a single update statement?
I have approximately 1200 transaction to be updated to a master table. There are other columns in the master table but only one column is being updated. I would like to use sqlloader if possible or any other efficient means. Those 1200 record is stored in an excel spreadsheet. The col1 of the excel spreadsheet have to match col1 of the master table inorder for update col2 from the excel spreadsheet. Here is an example of the data. My operation system is HPUX and database is Oracle 10g.
Master table col1 col2 col3 col 4 4238 susan 56e 5879 h698c rich 12g 7091 joyce 34b 0876 mike 25n 7501 k956b robert 87c 9498 angela 67r 3645 doris 92y
I am having a table with 4 columns as mentioned below
For a particular prod the value greater less than 5 should be rounded to 5 and value greater than 5 should be rounded to 10. And the rounded quantity should be adjusted with in a product starting with order by of rank with in a prod else leave it
I have taken all the records in to a cursor. Once after rounding the request of 1st rank and adjusting the values of next rank is done. Trying to round the value for 2nd rank as done for 1st rank. Its not taking the recently updated value(i,e adjusted value in rounding of 1st rank).
This is because of using a cursor having a value which is of old value. Is there any way to handle such scenario's where cursor records gets dynamically updated when a table record is updated.