Sql query-based on transactions

Hi,
The below table is currently having 78,000 records and is running in the production environment, performance should be taken into account.
For example, the table is having the data in the below format.
Date     Value
22.01.08 5 PM     49
22.01.08 5:30 PM     50
22.01.08 5:45 PM     48
22.01.08 6:00 PM     45
Here the last transaction occurred at 6 PM with value 45.
I have to display the value of the previous transaction from the last transaction that is the expected output value is 48.
Kindly let me know the query how to retrieve it considering the load and performance issues.

CREATE TABLE TRY ("DAT" DATE,VALUE NUMBER);
alter session set nls_date_format = 'DD-MON-YYYY HH24 MI:SS';
insert into try values(sysdate,32);
insert into try values(sysdate,32);
insert into try values(sysdate,32);
insert into try values(sysdate,32);
insert into try values(sysdate,40);
insert into try values(sysdate,45);
insert into try values(sysdate,48);
insert into try values(sysdate,31);
select * from try;
DAT                       VALUE
05-MAR-2008 17 56:59         32
05-MAR-2008 17 57:26         32
05-MAR-2008 18 02:26         32
05-MAR-2008 18 02:29         32
05-MAR-2008 18 02:42         40
05-MAR-2008 18 02:45         45
05-MAR-2008 18 02:47         48
05-MAR-2008 18 02:54         31select dat,value
from (select dat,value,dense_rank() over(order by dat desc) as rank
from try)
where rank=2;
DAT                       VALUE
05-MAR-2008 18 02:47         48I hope this will work for you.

Similar Messages

  • Include Button that executes PL/SQL procedure to SQL query based region

    I would like to add two columns to a SQL query region.
    These columns would not be sourced from the query, but rather would be used to execute a PL/SQL procedure.
    For example, I would like to have a manager approve or deny adding an additional employee to the department.
    There would be one button for APPROVE. And, one button for DENY.
    The PL/SQL procedure would execute to perform the required DML based upon the selected action (either APPROVE or DENY).
    A sample output would look like this:
    <APPROVE>, <DENY>, John Doe, Accountant
    <APPROVE>, <DENY>, Jane Doe, Accountant
    Is there any way to add a button to a SQL Query based report region where that button executes a stored proc? If so, what is the basic process for doing this?
    Thanks!
    -Reid

    Is there any way to add a button to a SQL Query based report region where that button executes a stored proc? If so, what is the basic process for doing this?Conditional page item? You can associate processes with buttons on a page

  • SQL Query based BI Pub report - Taking too long to produce the output

    Hi All,
    I was trying to produce a BI Publisher based report through enterprise edition of BI Publisher 10.1.3.4
    Its a sql query based report and it has around 20 columns and it has around 1 lakh records.
    The query actually takes only 2 seconds to execute in the database but when we execute from BI Publisher it takes a long time and also it times out most of the time
    Is there something I am missing in the configuration options ?
    Thanks
    Shasi

    I am facing the same problem as well. I am using the Publisher Web service API to run a report with 1 Million records. This report is configured to use OBIEE. It takes a lot of time to generate the report ( around 30 Mins) and even though OBIEE generates the data, my web service client either timesout. Even after increasing the timeout, a 500 internal server error is thrown . Does anyone know of a solution to this.
    Thanks

  • SQL query to get transaction detail from DEFERRED_TRAN_ID

    Hi,
    I'm using Oracle Advance Replication and get the transaction detail from Enterprise Manager Console.
    So instead of using the console.
    Is there a way any SQL query which get transaction details like SQL query fired, old and new column value etc from DEFERRED_TRAN_ID.
    thanks

    quote:
    Originally posted by:
    lucapac
    I have two tables: tblWorkers and tblSkills. tblWorkers has a
    column, Skills, which is populated from a multiple-checkbox form
    field with one or more skill_IDs from tblSkills, so each
    tblWorkers.Skills consists of a list of one or more comma-delimited
    values. For any Skill_ID, I need to generate a listing of all
    Workers with the corresponding skill, so I have tried to do
    something along the lines of SELECT WorkerName FROM tblWorkers
    WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
    (ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
    got data type mismatches out of the way) return all Workers, not
    just those with the desired Skill. There must be an easy way to do
    this ... How do people with a bit more CF/SQL experience than I
    have do this???
    As Kronin implied, we normalize our databases. If you don't
    understand that answer, the book "Database Design for Mere Mortals"
    is often mentioned on this forum.

  • Setting current values in Multiple Select List in SQL Query based Report

    Hi,
    I have a report based on a sql query that contains a multiple select list. Unfortunately I cannot get the multiple select list to display the current values (p_value) correctly. I have created a page item, :p311_current_versions, that is set using a pre-header process and it returns a value with a colon delimited format e.g. '10.1.2.1.0:10.1.2.2.0'. Then this item is used in the sql query to set the current value (p_value) of the apex_item.select_list_from_query function. However when the table is displayed, instead of having two entries, 10.1.2.1.0 and 10.1.2.2.0 selected, it has an extra entry '10.1.2.1.0:10.1.2.2.0' selected.
    Here is my code:
    select distinct a.product, a.version from (
    select distinct
    apex_item.display_and_save(2,product)||apex_item.hidden(1,env_product_id) PRODUCT,
    APEX_ITEM.SELECT_LIST_FROM_QUERY(3,decode(product, 'HTTP Server' , :p311_current_versions, version), 'SELECT distinct version d, version r FROM ebs_tech_stack where
    product ='''||PRODUCT||'''',
    decode(PRODUCT, 'HTTP Server' ,'multiple="multiple" style="width:170px"','style="width:170px"'),
    'NO') as version
    from ebs_environment_tech_stack
    where environment_id = :p311_umgebung_id) a order by a.product
    If anyone can help me figure out how to set the current values correctly I'd be really grateful!!
    Thanks in advance,
    Jean

    Jean,
    I don't think this is possible using the apex_item package. The select_list_from_query function accepts only a single value for the second parameter.
    Scott

  • Why field length is shorter than the actual one in a SQL query based grid?

    Hi,
    I have a grid based on a SQL query on a UDO table, but I found when I retrieve the data from a SQL query some column show only part of data. For example, in SQL server the query should return one column data like "ABCD", but in the grid it only shows "A" or "AB". I think the SQL query should be good because when copy the same query executing in SQL server side, it returns me all complete data. But when it is executed in add-on inside a grid, then some column only returns me partial data. In most case it only return the first one or two characters. I don't see any special in the query. Basically it is normal SELECT query, the only possible special is it is using "UNION".
    The SQL query looks like below:
    SELECT fieldA, fieldB FROM table1
    UNION ALL
    SELECT fieldA, fieldB FROM table2
    When it is executed in SQL side, everything looks good, but when i run it in a grid in add-on then fieldB column only display partial data.
    Any idea?
    Thanks,
    Lan
    Edited by: ZHANGLAN on Oct 4, 2011 11:55 PM

    Hi All,
    Thanks for all your replies, I agree that the issue is caused by the UNION in SQL query. Because when i create a view in SQL based on that query and the grid is based on that SQL view then everything is fine now. I think Petr's solution should work in this case.
    Thank you again!
    Lan

  • SQL Query based Tree Table

    Dear All,
    I would like to know. Can I create af:TreeTable with SQL Query without using Entity Object because of the Database allow to use only Query view object. Please show to me the ways how to tackle in this scenario.
    Regards
    KT

    here some discussion going on here.
    i will suggest you the same.
    Is it possible to create a multi-level tree table based on a single VO ?

  • Executing SQL-query based on user input in text-box on APEX page

    Hi,
    I'm new to developing in APEX, and I encountered a problem...
    Is it even possible to make such thing: use text area for input of some SQL-query and then execute it on my schema and show results in report item? And if the answer is yes, can somebody provide me tips on how to do that?
    Thanks in advance.

    Denes Kubicek wrote:
    I think this example shows something similar:
    https://apex.oracle.com/pls/apex/f?p=31517:91
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    https://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------I see there is executing stored queries example, and text area showing executed one, but not quite understand how to sent sql-query directly from text input, based on your example :/

  • How to execute PL/SQL query based on given input parameter

    Hi all,
    I have a pl/sql code which is in Region source. It extracts data from database. I want to execute the code based on input I give. I have to give date as a input parameter.
    e.g.
    If I give date1 as a parameter, then following code should executed
    select col1, col2,..... from Table where date1 between '01-jan-2010' and '31-jan-2010'
    If I give date2 as a parameter, then following code should executed
    select col1, col2,..... from Table where date2 between '01-jan-2010' and '31-jan-2010'
    Your help is very much appreciated.
    Leo

    Check the datatemplate,lexicals and beforeTrigger for this in documentation.
    check this
    Lexical reference issue in EBS

  • Populating item using a sql query based on other item of diff table

    Hi,
    It would be great if someone could help.
    I have two items on my form page .
    My first item P1_sub_prog is of select list with submit, it fetches values from table prog "mv_cap_prog_subprog" of the same schema whihc I am using for teh current application.
    I want my second item P1_PROGRAM to be populated with value corresponding to my first item value, after being fetched from the same table on the basis of the first item value (P1_SUB_PROG)
    Both the item values have a relation.
    I tried by creating sql as well as LOV for the second item but its not working.
    It displays nulll in the second item field.
    While using sql I tried the following query
    in the source request of second item i.e P1_PROGRAM
    SELECT DISTINCT a.program_id d,a.program_id r FROM
    mv_cap_prog_subprog
    WHERE SUB_PROGRAM_ID = :P1_sub_prog

    Hi,
    Search this forum for "cascading select list".
    You will find lots of help.
    Cheers,
    Patrick

  • SQL Query based on prority

    All,
    I've 3 task - A,B and C,each task have different prority
    Task A has higer priority and then task B and then Task C.
    Scenario#1:
    clientid      - tname      - sdate      - edate
    100      - A      - 20 Jan 11     - 22 Jan 11
    100      - B      - 22 Jan 11     - null
    in this task A has higer priority then task B ,so outcome should be:
    100 - A - 20 Jan 11 - null
    Scenario#2:
    clientid      - tname      - sdate      - edate
    200      - A      - 25 Jan 11     - 25 Jan 11
    200      - B      - 25 Jan 11     - 25 Jan 11
    200      - C      - 25 Jan 11     - null
    in this scenario all task start and end on same day,so final outcome should be:
    200      - A      - 25 Jan 11     - 25 Jan 11
    200      - B      - 25 Jan 11     - 25 Jan 11
    200      - C      - 25 Jan 11     - null
    Scenario#3:
    clientid      - tname      - sdate           - edate
    400      - C      - 1 Mar 11     - 6 Mar 11
    400      - B      - 6 Mar 11     - null
    in this scenario task B has higer priority then task C ,so outcome should be:
    400      - B      - 6 Mar 11     - null
    SQL for all scenario: Pls help to do it through sql or any procedure or function.
    WITH task_dtl AS
    (SELECT 100 client_id, 'A' tname ,to_date('20/1/2011','DD/MM/YYYY') stdate,to_date('22/1/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
    SELECT 100 , 'B' tname ,to_date('22/1/2011','DD/MM/YYYY') stdate ,NULL edate FROM DUAL UNION ALL
    SELECT 200 ,'A' tname ,to_date('25/1/2011','DD/MM/YYYY') stdate,to_date('25/1/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
    SELECT 200, 'B' tname ,to_date('25/1/2011','DD/MM/YYYY'),to_date('25/1/2011','DD/MM/YYYY') etdate FROM DUAL UNION ALL
    SELECT 200, 'C' tname ,to_date('25/1/2011','DD/MM/YYYY')stdate ,NULL edate FROM DUAL UNION ALL
    SELECT 300 , 'A' tname ,to_date('20/2/2011','DD/MM/YYYY') stdate , NULL edate FROM DUAL UNION ALL
    SELECT 400 , 'C' tname ,to_date('1/3/2011','DD/MM/YYYY') stdate,to_date('6/3/2011','DD/MM/YYYY') edate FROM DUAL UNION ALL
    SELECT 400 , 'B' tname ,to_date('6/3/2011','DD/MM/YYYY') stdate ,NULL edate FROM DUAL
    SELECT * FROM task_dtl;
    Thanks,

    Please learn to post your data and code using {noformat}{noformat} tags as per the FAQ: {message:id=9360002}
    As for your question, I'm not sure I understand the logic behind these 'priorities'.
    scenario 1 appears to be... if the sdates' are different then take the tname and sdate from the higher priority A, and the null edate regardless of priority.
    scenario 2 appears to be... if the sdates = the edate then ignore priorities, including where the edate is null?
    scenario 3 appears to be... if the sdates' are different then take the tname and sdate from the higher priority A, and the null edate (similar to scenario 1)
    Where is the consistency in the logic?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Sql Query based on timestamp

    Hi All,
    I need to write a select statement which fetches all records from current time to previous 2 hours.
    i.e. from current time to current time - 2 hours.
    ID
    Timestamp
    1
    10/OCT/13 11:09:21.994000000 AM
    2
    10/OCT/13 12:07:51.989000000 AM
    3
    10/OCT/13 01:11:04.621000000 PM
    4
    10/OCT/13 03:02:36.897000000 PM
    Please suggest how can we achieve this.
    TIA,
    Bob

    select mytimestamp-(2/24) from mytable
    Ramin Hashimzade

  • Oaf: putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    VO extension will not work as the
    Standard Controller code : oracle.apps.pos.supplier.webui.QuickUpdateCO is calling the AM's method on the click of save button and AM is dynamically invoking the methods in VO.
    Standard Controller code:
    OAApplicationModule oaapplicationmodule = oapagecontext.getApplicationModule(oawebbean);
    if(oapagecontext.getParameter("btnSave") != null)
    oaapplicationmodule.invokeMethod("updateVendor");
    oaapplicationmodule.invokeMethod("updateVendorSites");
    oaapplicationmodule.getTransaction().commit();
    Corressponding standard standard AM code...
    CallableStatement callablestatement;
    Exception exception;
    oadbtransaction = getOADBTransaction();
    connection = oadbtransaction.getJdbcConnection();
    Object obj = null;
    oaviewobjectimpl = (OAViewObjectImpl)findViewObject("SupplierVO");
    callablestatement = null;
    try
    callablestatement = oadbtransaction.createCallableStatement(" BEGIN savepoint upd_vndr_ab ; END;", 0);
    callablestatement.executeQuery();
    catch(SQLException sqlexception1)
    throw OAException.wrapperException(sqlexception1);
    finally
    if(callablestatement == null) goto L0; else goto L0
    if(callablestatement != null)
    try
    callablestatement.close();
    catch(SQLException sqlexception) { }
    break MISSING_BLOCK_LABEL_97;
    try
    callablestatement.close();
    catch(SQLException sqlexception2) { }
    throw exception;
    VendorsVORowImpl vendorsvorowimpl;
    label0:
    oaviewobjectimpl.reset();
    vendorsvorowimpl = (VendorsVORowImpl)oaviewobjectimpl.first();
    String s = vendorsvorowimpl.getPosModified();
    String s1 = vendorsvorowimpl.getHzModified();
    Number number = vendorsvorowimpl.getVendorId();
    int i = number.intValue();.....
    Extending the VO will not server the good as the handle will not be given to extended class....
    Edited by: user13791631 on Jun 20, 2012 9:29 PM

  • Putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    {forum:id=210} is the OAF forum

  • Validation in VO based on sql query

    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    {forum:id=210} is the OAF forum

Maybe you are looking for

  • Video from camera won't play in iphoto

    I can import video from my camera into IPhoto and the thumbnail shows up just fine. When I double click to play, nothing happens. Does anyone know what the problem is?

  • Error in File content Conversion

    HI All, I am gettng  "Consistency error: field(s) missing - specify 'lastFieldsOptional' parameter to allow this" What this error means?

  • Change font in Hangman widget

    Is there anyway to change the font for the letters in the hangman widget?  I love the game, but the font is really hard to read.  I am working with low level literacy learners, and this would be a fantastic game, but the font has to be cleaner so it

  • How do i get the daily manager to stop printing

    apparently when i set up my new printer i accidentally requested the "daily manager" to print.  But i don't want this to print. how do I stop it.

  • Relase strategy characteristic with several material groups

    Dear Experts, Actually I'm implementing the MM Module, 6.00 version and I have the following issue: I created the release strategy Purchase Order, with these characteristics: - Material group - Net total purchase order - Plant The error consists in t