Get three previous records of the current record in an Oracle Form

Hi,
I need to get three previous records of the current record in an Oracle Form
Sorry for the lengthy explanation:
I have a table name: ARCHIVE_DATA with column name: coll_time and its data type DATE.
SQL> SELECT COLL_TIME FROM ARCHIVE_DATA;
COLL_TIME
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
12-AUG-05
10 rows selected.
SQL> select to_char(coll_time,'dd-mon-yyyy:HH:MI:SS') from ARCHIVE_DATA;
TO_CHAR(COLL_TIME)
12-aug-2005:02:42:00
12-aug-2005:02:43:00
12-aug-2005:02:44:00
12-aug-2005:02:45:00
12-aug-2005:02:46:00
12-aug-2005:02:47:00
12-aug-2005:02:48:00
12-aug-2005:02:49:00
12-aug-2005:02:50:00
12-aug-2005:02:51:00
10 rows selected.
This is the Requirement:
In a Form's Block(BLK1), for example: the current_record is the fifth record from the top
(i.e. 12-aug-2005:02:46:00)
When the fifth record is the current_record and When I click a button, three previous records of the
current_record should be populated on the screen.
See what I did:
I created another table same as the first table(ARCHIVE_DATA) and its name is: THREE_RECS.
I am inserting three records from the first table(ARCHIVE_DATA) into the second table: THREE_RECS
which are less than the current record and ORDER BY DESC.
CANVAS:
Two blocks (BLK1, BLK2) based on ARCHIVE_DATA and THREE_RECS are on the same CANVAS.
But the first block (BLK1) which is based on the first table:ARCHIVE_DATA is populated with one record and the
second block (BLK2) is empty.
So when I click a particular button (ex: prev_recs), the second block(BLK2) should be populated with
three previous records of the current record( :BLK1.COLL_TIME)
(off course :BLK2 populates with one record and use arrows or scrollbar to get the other two records)
This is the code I wrote in the trigger and followed by the error:
1 BEGIN
2 DECLARE
3 cursor c1 IS
4           SELECT MONITOR_ID,
5               SAMPLE_ID,
6               COLL_TIME,
7               DEW_POINT
8          FROM ARCHIVE_DATA;
9 cursor c2(passing_date IN date) IS
10           SELECT MONITOR_ID,
11               SAMPLE_ID,
12               COLL_TIME,
13               DEW_POINT
14          FROM (SELECT MONITOR_ID,
15               SAMPLE_ID,
16               COLL_TIME,
17               DEW_POINT
18          FROM ARCHIVE_DATA
19          ORDER BY COLL_TIME desc)
20      WHERE COLL_TIME < passing_date;
21     BEGIN
22     FOR cur_rec in c1
23     LOOP
24          IF (cur_rec.COLL_TIME = to_date(:BLK.COLL_TIME,'dd-mon-yyyy:HH24:mi:ss')) then
25     FOR second_cur_rec in c2(second_cur_rec.COLL_TIME)
26          LOOP
27      IF c2%rowcount < 4 then
28               BEGIN
29               INSERT INTO THREE_RECS
30                    values(second_cur_rec.MONITOR_ID,
31                         second_cur_rec.SAMPLE_ID,
32                         second_cur_rec.COLL_TIME,
33                         second_cur_rec.DEW_POINT);
34               COMMIT;
35               END IF;
36 END LOOP;
37 END IF;
38 END LOOP;
39 END;
40 END;
This is the error I am getting:
Error 103 at line 14
Encountered the symbol "(" when expecting one of the following
a PL/SQL variable or double quoted string
an expanded name
an expanded name link
a table reference __expression
a key word
Resuming parse at line 126, column 46
Thanks in advance

Change C2 to:
cursor c2(passing_date IN date) IS
  SELECT MONITOR_ID, SAMPLE_ID,
               COLL_TIME, DEW_POINT
    FROM ARCHIVE_DATA
    WHERE COLL_TIME < passing_date
    ORDER BY COLL_TIME desc;And rather than populating a table with the three records, you could just select the three records using: where COLL_TIME between Prev3_time and Prev1_time

Similar Messages

  • Get three previous records of the current record

    Hi,
    I need to get three previous records of the current record in an Oracle Form
    Sorry for the lengthy explanation:
    I have a table name: ARCHIVE_DATA with column name: coll_time and its data type DATE.
    SQL> SELECT COLL_TIME FROM ARCHIVE_DATA;
    COLL_TIME
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    12-AUG-05
    10 rows selected.
    SQL> select to_char(coll_time,'dd-mon-yyyy:HH:MI:SS') from ARCHIVE_DATA;
    TO_CHAR(COLL_TIME)
    12-aug-2005:02:42:00
    12-aug-2005:02:43:00
    12-aug-2005:02:44:00
    12-aug-2005:02:45:00
    12-aug-2005:02:46:00
    12-aug-2005:02:47:00
    12-aug-2005:02:48:00
    12-aug-2005:02:49:00
    12-aug-2005:02:50:00
    12-aug-2005:02:51:00
    10 rows selected.
    This is the Requirement:
    In a Form's Block(BLK1), for example: the current_record is the fifth record from the top
    (i.e. 12-aug-2005:02:46:00)
    When the fifth record is the current_record and When I click a button, three previous records of the
    current_record should be populated on the screen.
    See what I did:
    I created another table same as the first table(ARCHIVE_DATA) and its name is: THREE_RECS.
    I am inserting three records from the first table(ARCHIVE_DATA) into the second table: THREE_RECS
    which are less than the current record and ORDER BY DESC.
    CANVAS:
    Two blocks (BLK1, BLK2) based on ARCHIVE_DATA and THREE_RECS are on the same CANVAS.
    But the first block (BLK1) which is based on the first table:ARCHIVE_DATA is populated with one record and the
    second block (BLK2) is empty.
    So when I click a particular button (ex: prev_recs), the second block(BLK2) should be populated with
    three previous records of the current record( :BLK1.COLL_TIME)
    (off course :BLK2 populates with one record and use arrows or scrollbar to get the other two records)
    This is the code I wrote in the trigger and followed by the error:
    1 BEGIN
    2 DECLARE
    3 cursor c1 IS
    4           SELECT MONITOR_ID,
    5               SAMPLE_ID,
    6               COLL_TIME,
    7               DEW_POINT
    8          FROM ARCHIVE_DATA;
    9 cursor c2(passing_date IN date) IS
    10           SELECT MONITOR_ID,
    11               SAMPLE_ID,
    12               COLL_TIME,
    13               DEW_POINT
    14          FROM (SELECT MONITOR_ID,
    15               SAMPLE_ID,
    16               COLL_TIME,
    17               DEW_POINT
    18          FROM ARCHIVE_DATA
    19          ORDER BY COLL_TIME desc)
    20      WHERE COLL_TIME < passing_date;
    21     BEGIN
    22     FOR cur_rec in c1
    23     LOOP
    24          IF (cur_rec.COLL_TIME = to_date(:BLK.COLL_TIME,'dd-mon-yyyy:HH24:mi:ss')) then
    25     FOR second_cur_rec in c2(second_cur_rec.COLL_TIME)
    26          LOOP
    27      IF c2%rowcount < 4 then
    28               BEGIN
    29               INSERT INTO THREE_RECS
    30                    values(second_cur_rec.MONITOR_ID,
    31                         second_cur_rec.SAMPLE_ID,
    32                         second_cur_rec.COLL_TIME,
    33                         second_cur_rec.DEW_POINT);
    34               COMMIT;
    35               END IF;
    36 END LOOP;
    37 END IF;
    38 END LOOP;
    39 END;
    40 END;
    This is the error I am getting:
    Error 103 at line 14
    Encountered the symbol "(" when expecting one of the following
    a PL/SQL variable or double quoted string
    an expanded name
    an expanded name link
    a table reference __expression
    a key word
    Resuming parse at line 126, column 46
    Thanks in advance

    Why not just a simple select that doesn't involve a second table and PL/SQL?
    sql>select * from t1 order by dt;
    DT
    08/12/2005 02:42:00am
    08/12/2005 02:43:00am
    08/12/2005 02:44:00am
    08/12/2005 02:45:00am
    08/12/2005 02:46:00am
    08/12/2005 02:47:00am
    08/12/2005 02:48:00am
    08/12/2005 02:49:00am
    08/12/2005 02:50:00am
    08/12/2005 02:51:00am
    10 rows selected.
    sql>select dt
      2    from (select dt, row_number() over (order by dt desc) rn
      3            from t1
      4           where dt < to_date('12-aug-2005:02:46:00', 'dd-mon-yyyy:hh:mi:ss'))
      5   where rn <= 3
      6   order by dt;
    DT
    08/12/2005 02:43:00am
    08/12/2005 02:44:00am
    08/12/2005 02:45:00am
    3 rows selected.If the use of an analytical function (row_number()) is a problem with Forms, then the query can also be done as:
    sql>select dt
      2    from (select dt
      3            from (select dt
      4                    from t1
      5                   where dt < to_date('12-aug-2005:02:46:00', 'dd-mon-yyyy:hh:mi:ss')
      6                   order by dt desc)
      7           where rownum <= 3)
      8   order by dt;
    DT
    08/12/2005 02:43:00am
    08/12/2005 02:44:00am
    08/12/2005 02:45:00am
    3 rows selected.

  • How can we get a alert message in  the current browser we are using the mom

    how can we get a alert message in the current browser we are using the moment we have entered some data in
    the table...
    I need a popup alert the moment a new record is added in a table... in apex database is 11g xe..
    The idea is I am using a apex application. .The moment new data is added in the table ..I am alerted by a message window..that a new record has been added...
    Thanks
    Edited by: pauljohny on Jun 11, 2012 10:23 AM

    pauljohny wrote:
    how can we get a alert message in the current browser we are using the moment we have entered some data in the table...
    "Current browser"? When viewing anything, or just when using an APEX app?
    Ans .. Just when using apex app....even if the apex app is minimised ..The current browser will be the one where I am using apex app...
    What i am looking for some scheduler .. to check ..in the table every 5 minute for change if there is a change..then a popup alert be shown...
    Split it into [at least] 2 components, database and browser. I'd expect someone calling themself a "DBA Architect" to have some ideas about the database side of things, even if not clued up on JavaScript and AJAX?
    I dont think its a database isssue... When i say to check every 5 minutes ..it could be easily done via dbms_scheduler ...I am having issue in getting the popup alert message...
    in apex... Dont know wether there is a plugin like modal window(available from skill builder) which shall help in this scenario,.Or might be have to use java scripting and ajax ..
    and if it is that (Java scripting and Ajax) .....then shall have to be familiar with java scripting and Ajax...and this shall be a bit time consuming..
    Had a feeling this could be accomplished via java scripting and ajax.. ...but still looking for some easy way..

  • Calculate previous Sunday from the current day

    Hi Gurus,
    Can anybody tell what is the name of the function module which caluclates the previous Sunday from the Current system date. or any other idea how to calculate previous sunday from the current system date in Query.
    Thanks
    Liza

    Hello,
    See my previous thread to you for a similar Re: Find out previous Monday based on 0CALDAY
    Thanks
    Chandran

  • HT1491 How do I get a previous version of the Kindle app?

    How do I get a previous version of the Kindle app?

    If you don't already have a previous copy backed up somewhere on your computer, you can't. The iTunes Store will have only the most recent version of any app.
    Regards.

  • Will the iPod nano 7 get a new update from the current 1.0.3?

    Hey Guys I was wondering will the iPod nano 7 get a new update from the current 1.0.3?
    If anyone knows or has and info or rumors pleas tell me.
    Thanks
    email *****
    <edited by host>

    Apple might release small updates for 4th generation iPods touch if they find serious issues like the FaceTime problem that made Apple release iOS 6.1.5 for the 4th generation iPod touch. However, this device won't receive any major iOS update.
    The 4th generation iPod touch has got 256 MB of memory, and iOS 7 devices have got 512 MB or more of memory

  • ORA-13605: The specified task or object Get does not exist for the current

    Dear all,
    11.1.0.6 on solaris 10
    SQL>
    SQL> DECLARE
    2 taskname varchar2(100);
    3 taskdesc varchar2(128);
    4 task_id number;
    5 object_id number;
    6 timeLimit varchar2(25);
    7 numDaysToRetain varchar2(25);
    8 objectName varchar2(100);
    9 objectType varchar2(100);
    10 BEGIN
    11 taskname := 'SEGMENTADV_8980096';
    12 taskdesc :='Get';
    13 numDaysToRetain :='30';
    14 dbms_advisor.create_task('Segment Advisor','',taskname,taskdesc,NULL);
    15 dbms_advisor.create_object(taskname, 'TABLE', 'TRPT', 'CRM_CHECK', ' ', NULL, object_id);
    16 dbms_advisor.set_task_parameter(taskname, 'RECOMMEND_ALL', 'TRUE');
    17 dbms_advisor.set_task_parameter(taskname, 'DAYS_TO_EXPIRE', numDaysToRetain);
    18 END;
    19 /
    DECLARE
    ERROR at line 1:
    ORA-13605: The specified task or object Get does not exist for the current
    user.
    ORA-06512: at "SYS.PRVT_ADVISOR", line 4766
    ORA-06512: at "SYS.PRVT_ADVISOR", line 4637
    ORA-06512: at "SYS.DBMS_ADVISOR", line 56
    ORA-06512: at line 14
    Am running the above as sys user ..
    Any idea ?
    Kai

    Hi,
    This link may help:
    ORA-13605: The specified task or object ADDM:<task number> does not exist.
    Thanks and Regards,
    Rajesh K.

  • Will the iPad 3 that I purchased in March get Siri update or just the current purchasers?

    Will the iPad 3 that I purchased in March get Siri update or just the current purchasers?

    When it's released you will be able to install iOS 6 on your iPad 3 and you will get Siri : http://www.apple.com/ios/ios6/siri/ (though the features that you get might depend upon which country that you are in - see the bottom of that page)

  • How to Find the Current Instance Id in Oracle 10g

    Hi,
    how to find the current instance id in oracle 10g studio,
    I have the below code :
    if (InstanceScreenFlow.processInstance.id.id.indexOf(text : ins.id) < 0) {
    /// do something
    it is saying that "'processInstance' is not a function"
    Thanks,
    Brijesh Kumar Singh.

    Why not just pass in the "id" predefined variable into your screenflow? Once you do that you'll be able to refer to it as "id.id" anywhere inside your screenflow.
    Dan

  • Has anybody read the Windows user from an Oracle Form?

    Hi
    Has anybody read the Windows Login from an Oracle Form?
    Regards,
    Néstor Boscán

    in 6i, u can use d2kwutil
    in 9i/10g use webutil. Search in this forum and u can see the previous posting.
    Rajesh

  • How to define the tab space in the PL/SQL editor with Oracle Forms 4.5?

    When I use the PL/SQL editor with Oracle Form Builder, I found the tab space is very long that affects my programs readability quite a lot. Then, I tried to use Textpad to type my program. It looks fine with Textpad. However, when i tried to 'cut and paste' my code back to the PL/SQL editor, all tab spaces (approx. 8-character) are detected and the program looks awful again ~~ Would any one help me to solve my mentioned problem?
    Thanks for any advices!

    In 4.5 you cannot change this. In Forms 5.0 and above there is a registry value DE_PREFS_TABSIZE which allows you to set a value for the tabsize.

  • For some reason every time I start Firefox I get a window to print the current page. Am I the only one this happens to? Is there any way to get rid of it? It just started with the previous update.

    When I start Firefox, the standard print window comes up as if I had clicked on print under the file menu. I close the window without problems, and it doesn't show up again until the next time I start Firefox. When I click on print under the file menu, I get the print window without any problems.

    See:
    * http://kb.mozillazine.org/Software_Update (Software Update not working properly)
    Remove the files in the updates and updates\0 folder.<br />
    You may need to delete active-update.xml and updates.xml as well if present.
    C:\Documents and Settings\&lt;user&gt;\Local Settings\Application Data\Mozilla\Firefox\Mozilla Firefox\updates
    (%USERPROFILE%\Local Settings\Application Data\Mozilla\Firefox\Mozilla Firefox)
    If you have problems with updating then easiest is to download the full version and uninstall the currently installed version and remove the Firefox program folder to do a clean install of the new version.
    * Download a fresh Firefox copy and save the file to the desktop.
    * Firefox 4.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Uninstall your current Firefox version and remove the Firefox program folder before installing that copy of the Firefox installer.
    * Do not remove personal data if you uninstall the current version.
    * It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    Your bookmarks and other profile data are stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder] and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.

  • Get username and password of the currently logged-in user in CRM and pass it to the plugin

    Hi,
    I am integrating CRM Online and SharePoint Online. Right now I am using Office365 trial version for both. Hence, the same username and password works for both.
    I want to create sub-site in SharePoint on create of an entity record. Currently, I am passing the admin credentials. But, I want to pass the credentials of the currently logged-in user in CRM to the plugin which is getting executed on create of account entity.
    So that I can then create sub-site in SharePoint using the current user credentials instead of admin credentials.
    Is there way to achieve this?

    Hello,
    You would not be able to get login/password of currently logged in user. I believe usage of admin credentials is the best way to achieve your goal.
    Dynamics CRM MVP
    My blog

  • I need to reinstall Media Encoder CC (previous version than the current) because i need flv export...Any advice ?

    Hi,
    Some client of mine still needs to get flv videos for his website, and i've seen that Media Encoder CC 2014 doesn't have this option anymore.
    Unfortunately i already uninstalled the previous version, any way to get it back ?
    Or is there any plugin for the current version that allow flv export ?
    Any help would be really appreciated, i need to deliver ... tomorrow :/
    Thanks a lot !

    ame is downloaded and installed with flash, after effects and premiere pro.  install one of those cc versions and see if ame cc is also installed.

  • How compare previous records in runtime, in forms

    Hi
    Please help me in below
    I have a form with columns Country_name,Country_code,Risk_level,Currency(unique) and Bank. and form is having multiple records.
    Here I can enter duplicate values in Country_name,Country_code,Risk_level.
    1) In currency Column, If I give USD it should check previous record of currency column,whether currency column is having a value for particular country. if yes, it should not allow. If now it should allow.
    2) If I give any currency other than ALL, then it should not allow ALL in next record.
    3) If I give ALL in currency column for first record, in next record it should not allow others currencies including ALL for particular country.
    Need help....
    Regards,
    Raghu
    Edited by: 914330 on 13-May-2012 22:25
    Edited by: 914330 on 14-May-2012 01:05

    This would be a fine sample for an analytic function. Look up lead and lag at http://tahiti.oracle.com and build a view upon your table using the analytic functions.
    cheers

Maybe you are looking for