Select 2 records (rows) in the results.

I am using Oracle R12- Forms.
After searched for all orders for a specific Customer, on the Results, I need to select 2 different rows.
Also tried ft object,but failed.
If manual, I use Keep holding the Ctrl Key, and Click for the first row, and Click 2nd row.
In OATS, I could not do this with the code below:
int rone=2;
int rtwo=5
Robot robot = new Robot();
robot.delay(5000);
// press and hold CONTROL key
robot.keyPress(KeyEvent.VK_CONTROL);      
forms.textField("//forms:textField[(@name='MY_ORDER_NUM_"+rone+"')]").click();          
forms.textField("//forms:textField[(@name='MY_ORDER_NUM_"+rtwo+"')]").click();
robot.keyRelease(KeyEvent.VK_CONTROL);
Any help is greatly appreciated.
Thanks,

What you need is a tree.
See Tomahawk (www.myfaces.org)

Similar Messages

  • How to add a dummy row in the result set of a SELECT statement.

    Hello Everyone -
    I have requirment to add a dummy row in the result set of a SELECT statement.
    For e.g. lets say there is a table Payment having following colums:
    Payment_id number
    status varchar2(10)
    amount number
    payment_date date
    so here is the data :-
    Payment_id Status Amount payment_date
    1 Applied 100 12/07/2008
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    Here is my SQL
    Select * form payment where payment_date >= 01/01/2009
    Output will be
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    My desired output is below
    2 Reversed 200 01/ 06/2009
    3 Applied 300 01/ 07/2009
    2 Reversed -200 01/ 06/2009 ------(Dummy Row)
    Thrid row here is the dummy row which I want to add when status is "Reversed"
    I would be very thankful for any kind of help in this regard ...
    Thanks,
    Gaurav

    Cartesion joining against a dummy table is a useful method of creating a dummy row:
    with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all
                    select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual),
                    --- end of mimicking your table
          dummy as (select 'Reversed' col1, 1 rn from dual union all
                    select 'Reversed' col1, 2 rn from dual)
    select mt.cust_id,
           mt.payment_id,
           mt.status,
           decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount,
           mt.payment_date
    from   my_tab mt,
           dummy
    where  mt.status = dummy.col1 (+)
    order by mt.cust_id, mt.payment_id, dummy.rn nulls first;
    CUST_ID     PAYMENT_ID     STATUS     AMOUNT     PAYMENT_DATE
    1     1     Applied     100     07/12/2008
    1     2     Reversed     200     06/01/2009
    1     2     Reversed     -200     06/01/2009
    1     3     Applied     300     06/01/2009
    2     1     Applied     100     07/12/2008
    2     2     Reversed     200     05/01/2009
    2     2     Reversed     -200     05/01/2009
    2     3     Applied     300     06/01/2009
    2     4     Reversed     -400     06/01/2009
    2     4     Reversed     400     06/01/2009
    2     5     Applied     500     07/01/2009Edited by: Boneist on 07-Jan-2009 23:10
    NB. You may have to mess around with the ordering if that's not come back in the order you wanted. You didn't mention what the rules were for any expected ordering though, so I've made up my own *{;-)
    Also, I added an identifier (cust_id) to differentiate between different sets of payments, since that's usually the case. Remove that if it's not applicable for your case.

  • Selecting a row in the output of alv grid

    hi,
    how do i select a row in the output of alv grid?plz help...
    regards,
    sheeba.

    Hi,
    Please refer the code below:
    *& Report  ZDEMO_ALVGRID_SELROW                                        *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic ALV grid, Enhanced to display capture each row a user has *
    *& selected                                                            *
    REPORT  zdemo_alvgrid_selrow                 .
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      SEl,                         "stores which row user has selected
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    perform display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
    *       Build Fieldcatalog for ALV Report
    form build_fieldcatalog.
    * There are a number of ways to create a fieldcat.
    * For the purpose of this example i will build the fieldcatalog manualy
    * by populating the internal table fields individually and then
    * appending the rows. This method can be the most time consuming but can
    * also allow you  more control of the final product.
    * Beware though, you need to ensure that all fields required are
    * populated. When using some of functionality available via ALV, such as
    * total. You may need to provide more information than if you were
    * simply displaying the result
    *               I.e. Field type may be required in-order for
    *                    the 'TOTAL' function to work.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-col_pos     = 0.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
    *  fieldcatalog-do_sum      = 'X'.
    *  fieldcatalog-no_zero     = 'X'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-datatype     = 'CURR'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      fieldcatalog-col_pos     = 8.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    endform.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
    *       Build layout for ALV grid report
    form build_layout.
      gd_layout-box_fieldname     = 'SEL'.
                                     "set field name to store row selection
      gd_layout-edit              = 'X'. "makes whole ALV table editable
      gd_layout-zebra             = 'X'.
    endform.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
    *       Display report using ALV grid
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                i_callback_program      = gd_repid
    *            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
                i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
    *            IT_EVENTS                = GT_XEVENTS
                i_save                  = 'X'
    *            is_variant              = z_template
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    endform.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
    select ebeln ebelp statu aedat matnr menge meins netpr peinh
    up to 10 rows
      from ekpo
      into corresponding fields of table it_ekko.
    endform.                    " DATA_RETRIEVAL
    *       FORM USER_COMMAND                                          *
    *       --> R_UCOMM                                                *
    *       --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
    * Check function code
      CASE r_ucomm.
        WHEN '&IC1'.
    *   Check field clicked on within ALVgrid report
        IF rs_selfield-fieldname = 'EBELN'.
    *     Read data table, using index of row user clicked on
          READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
    *     Set parameter ID for transaction screen field
          SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
    *     Sxecute transaction ME23N, and skip initial data entry screen
          CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
        ENDIF.
        WHEN '&DATA_SAVE'.  "user presses SAVE
        loop at it_ekko into wa_ekko.
          if wa_ekko-sel EQ 'X'.
    *       Process records that have been selected
          endif.
        endloop.
      ENDCASE.
    ENDFORM.
    Thanks,
    Sriram Ponna.

  • How to exclude the XML declaration from each row of the result set?

    Hi,
    I have a table with an XMLTYPE column and would like to SELECT a set of rows. How can I exclude the XML declaration from each row in the result set? My query currently looks like this, I'm executing it through Spring JDBC:
    SELECT XMLSerialize(CONTENT t1.xmltext) FROM myschema.event t1 WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e") ORDER BY t1.time DESC
    After selecting, in my application I convert each row into a String and concatenate all rows into one big string in order to parse it into a DOM model. I get a parser exception (org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed) because there are multiple XML declarations in my big string. Of course, I could manually check the String of each row whether it starts with the XML declaration, but it would be nicer if I could instruct the DB not to add it in the first place. Is there a way?
    Thanks!
    -- Daniela

    Hi,
    A couple of options I can think of :
    SELECT XMLSerialize(CONTENT
    XMLtransform(t1.xmltext,
      xmltype('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/> 
    <xsl:template match="/"><xsl:copy-of select="*"/></xsl:template>
    </xsl:stylesheet>')
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;or simply,
    SELECT XMLSerialize(CONTENT
      extract(t1.xmltext,'/')
    FROM myschema.event t1
    WHERE XMLEXISTS('$e/Event' PASSING XMLTEXT AS "e")
    ORDER BY t1.time DESC
    ;

  • Getting specific row of the result set.

    table: employee
    empno           number(20)
    ssan           varchar2(9)
    date_time_stamp date
    My Sql gets all the empno where ssan and date_time_stamp are equal.
    However I need previous row from max(empno) where ssan & date_time_stamp are equal.
    For eg:
    empno     ssan           date_time_stamp
    100     123456789     01-FEB-2004
    101     000000000     02-FEB-2004
    102     123456789     01-FEB-2004
    103     123456789     01-FEB-2004
    105     123456789     01-FEB-2004
    I need row with empno = 103.
    My current sql fetches all rows for particular ssan where ssan and date time stamp are equal that fetches all empno for particular ssan and date time stamp. I want the max(empno) -1 (previous row of the result set).
    Here is my sql:
    select empno,ssan,date_time_stamp
    from employee e
    where date_time_stamp in (select date_time_stamp from employee where e.ssan = ssan)
    order by empno,ssan;
    The above sql will fetch
    empno     ssan           date_time_stamp
    100     123456789     01-FEB-2004
    102     123456789     01-FEB-2004
    103     123456789     01-FEB-2004 ---&gt; I need this row, previous row from max(empno) where ssan and date time
    stamp are matching.
    105     123456789     01-FEB-2004
    101     000000000     02-FEB-2004

    If I understand correctly, you want the second highest empno for each unique combination of ssan and date_time_stamp. If so, given
    SQL> SELECT * FROM employee;
         EMPNO SSAN      DATE_TIME_S
           102 123456789 01-feb-2004
           103 123456789 01-feb-2004
           105 123456789 01-feb-2004
           100 123456678 01-feb-2004
           102 123456678 01-feb-2004
           103 123456678 01-feb-2004
           101 000000000 02-feb-2004
           105 123456678 01-feb-2004
           100 123456678 02-feb-2004
           102 123456678 02-feb-2004
           103 123456678 02-feb-2004
           105 123456678 02-feb-2004
           100 123456789 01-feb-2004Then something like this should do it.
    SQL> SELECT empno,ssan,date_time_stamp
      2  FROM (SELECT empno,ssan,date_time_stamp,
      3               RANK() OVER (PARTITION BY ssan,date_time_stamp
      4                            ORDER BY empno DESC) rk
      5        FROM employee)
      6* WHERE rk = 2;
         EMPNO SSAN      DATE_TIME_S
           103 123456678 01-feb-2004
           103 123456678 02-feb-2004
           103 123456789 01-feb-2004HTH
    John

  • INSERTing a blank row in the result set

    Hi friends,
    SELECT * FROM EMPLOYEES ORDER BY DEPARTMENT_ID;
    In the result of the above, I need to INSERT a blank row in the result for each DEPARTMENT_ID. i.e., the result should look like the following:
    EMP_ID - NAME - SALARY - DEPARTMENT_ID
    101 - Albert - 10,000 - 10
    102 - Benjamin - 8,000 - 10
    103 - Chitra - 10,500 - 20
    104 - David - 4,500 - 20
    105 - Elango - 6,000 - 20
    106 - Fathima - 6,000 - 30
    107 - Ganga - 9,000 - 30
    etc.
    I don't want to insert into the table. Just in display I need a blank row.
    Thanks in advance.
    Edited by: Iniyavan on Mar 8, 2010 11:37 AM

    Are you looking for this?
    satyaki>select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
    14 rows selected.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>break on deptno
    satyaki>
    satyaki>
    satyaki>select empno,
      2            ename,
      3            sal,
      4            deptno
      5     from emp
      6     order by deptno;
         EMPNO ENAME             SAL     DEPTNO
          7782 CLARK            2450         10
          7839 KING             5000
          7934 MILLER           1300
          7566 JONES            2975         20
          7902 FORD             3000
          7876 ADAMS            1100
          7369 SMITH             800
          7788 SCOTT            3000
          7521 WARD             1250         30
          7844 TURNER           1500
          7499 ALLEN            1600
         EMPNO ENAME             SAL     DEPTNO
          7900 JAMES             950         30
          7698 BLAKE            2850
          7654 MARTIN           1250
    14 rows selected.
    Elapsed: 00:00:00.04
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • How to hide the all rows except the result row in a report?

    Hi Experts,
    We have a report in which the user is interested to see only the result rows and I need to HIDE the characteristics in the rows. I was successfull in doing the same for Key figures in columns using "Calculate single value as suppress result". But I am not finding a way out to hide the characteristics in the rows.
    If I move the characteristics in rows to Free characteristics, the result row is not getting dispalyed. Also, the characteristics are  used dynamically by the formulae in columns and hence i cant remove these characteristics from the query. . The user wants the query to contain only one characteristic in the row and the result row for the key figures in columns. The report currently displays Invoice level data for each customer and this needs to be eliminated and it should display the summarised  data for every customer. Please suggest how this can be accomplished
    Regards,
    Kavitha

    Moving the char to free char will show the equivalent of result.
    Your issue likely is that this breaks the calculations since you do want the calculations done at detail level.
    To achieve this, move your char to free char (say it is 0CUSTOMER).
    For the CKF/Formula, go to aggregation tab, set the exception aggregation as Total (or whatever it was in standard behavior) and specify reference characteristic (in this case 0CUSTOMER), also check the 'Before aggregation' if you have that checkbox there.
    This will ensure the calculation is done at detail level even though the char is not included in the rows.
    If you have multiple chars to be moved to free char but included in detailed calculation, you will need to build cascading CKFs (CKF1 with ref char1, CKF2 eq to CKF1 with exception aggr on ref char2...and so on).
    Added:
    I understand you do want 0CUSTOMER in there, but something else (let us say 0DOCNO) removed. Use 0DOCNO in place of 0CUSTOMER in the case described above.
    Edited by: Ajay Das on Aug 5, 2009 8:57 AM

  • Select records based on the closest given time

    Dear SQL gurus,
    I have a table T1:
    Name Null? Type
    ID NOT NULL NUMBER(5)
    MOMENT NOT NULL DATE [DD.MM.YYYY HH24:MI]
    MEASUREMENT NOT NULL NUMBER(8,3)
    Example (ID, MOMENT, MEASUREMENT)
    -- START OF EXAMPLE --
    9380 18.11.2000 03:45 17.6
    9380 18.11.2000 04:30 17.3
    9380 18.11.2000 05:45 16.8
    9380 18.11.2000 06:15 16.8
    9380 18.11.2000 07:00 16.2
    9380 18.11.2000 07:30 16.2
    9380 18.11.2000 08:15 16
    9380 18.11.2000 08:45 15.7
    9380 18.11.2000 09:30 15.4
    9380 18.11.2000 10:00 15.4
    9380 18.11.2000 11:15 15.4
    9380 18.11.2000 11:45 15.4
    9380 18.11.2000 12:30 15.4
    9380 18.11.2000 13:00 15.4
    9380 18.11.2000 13:45 15.4
    --- END OF EXAMPLE --
    How to select records based on the:
    - time period specified by the day only [DD.MM.YYYY] - CONDITION 1
    - with values for 6AM only, and if not available, with values closest to 6AM - CONDITION 2
    (if the time gap in MOMENT field is too big, lets say > 5h then choose the average between the value before 6AM (ex. 4:15AM) and the value after the 6AM (ex. 9:45AM))
    CONDITION 1 (something like): moment between '01.01.2005' and '31.12.2004' - this is OK
    CONDITION 2: I do not know how to formulate, especially if 6AM value is not availabe, and I have to find the closest available value, or get the avergae from the two adjacent values.
    Maybe cursor magic??? Thanks a lot for your help.
    Rado

    About condition two, would the following select be of use to you? Picking the first record could be achived by rownum, analytic function, etc.
    WITH t1 AS (SELECT 9380 id, TO_DATE('18.11.2000 03:45', 'dd.mm.yyyy hh24:mi') moment,  17.6 measurement
                  FROM dual
                 UNION 
                SELECT 9380 id, TO_DATE('18.11.2000 04:30', 'dd.mm.yyyy hh24:mi') moment,  17.3 measurement
                  FROM dual
                 UNION
                SELECT 9380 id, TO_DATE('18.11.2000 05:45', 'dd.mm.yyyy hh24:mi') moment,  16.8 measurement
                  FROM dual
                 UNION
                SELECT 9380 id, TO_DATE('18.11.2000 06:15', 'dd.mm.yyyy hh24:mi') moment,  16.8 measurement
                  FROM dual
    SELECT id, moment, measurement, diff
      FROM (SELECT id, moment, measurement,
                   moment - TO_DATE(TO_CHAR(moment, 'dd.mm.yyyy ') || '06:00', 'dd.mm.yyyy hh24:mi') diff
              FROM t1
    ORDER BY abs(diff) asc, SIGN(diff) desc;
      C.

  • Selecting records based on the flag

    Hi All,
    I have records like the following
    Program_Name Effective_Date Valid_Flag
    ABCD 2/10/2012 N
    ABCD 2/14/2012 N
    ABCD 2/20/2012 Y
    ABCD 3/01/2012 N
    ABCD 3/10/2012 N
    ABCD 3/14/2012 Y
    ABCD 3/25/2012 N
    ABCD 3/26/2012 N
    ABCD 3/27/2012 N
    ABCD 3/28/2012 N
    ABCD 3/29/2012 N
    ABCD 4/25/2012 Y
    I have to write a select statement to to keep the first record and then pull only the records when the Valid_Flag changed. The result set should be like below.
    Program_Name Effective_Date Valid_Flag
    ABCD 2/10/2012 N -- I have preserved the first record
    ABCD 2/20/2012 Y -- Valid_Flag chages to a Y for teh first time and so on.
    ABCD 3/01/2012 N
    ABCD 3/14/2012 Y
    ABCD 3/25/2012 N
    ABCD 4/25/2012 Y
    If there is no change in the flag, I do not have to pull that record. Please help with SQL suggestions. Thanks for your time and help.

    ssk1974 wrote:
    Hi All,
    I have records like the following
    Program_Name Effective_Date Valid_Flag
    ABCD 2/10/2012 N
    ABCD 2/14/2012 N
    ABCD 2/20/2012 Y
    ABCD 3/01/2012 N
    ABCD 3/10/2012 N
    ABCD 3/14/2012 Y
    ABCD 3/25/2012 N
    ABCD 3/26/2012 N
    ABCD 3/27/2012 N
    ABCD 3/28/2012 N
    ABCD 3/29/2012 N
    ABCD 4/25/2012 Y
    I have to write a select statement to to keep the first record and then pull only the records when the Valid_Flag changed. The result set should be like below.
    Program_Name Effective_Date Valid_Flag
    ABCD 2/10/2012 N -- I have preserved the first record
    ABCD 2/20/2012 Y -- Valid_Flag chages to a Y for teh first time and so on.
    ABCD 3/01/2012 N
    ABCD 3/14/2012 Y
    ABCD 3/25/2012 N
    ABCD 4/25/2012 Y
    If there is no change in the flag, I do not have to pull that record. Please help with SQL suggestions. Thanks for your time and help.In the future, it would be nice if you could provide the sample data like i created below.
    ME_XE?with data as
      2  (
      3     select 'ABCD' as col1, to_date('2/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      4     select 'ABCD' as col1, to_date('2/14/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      5     select 'ABCD' as col1, to_date('2/20/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
      6     select 'ABCD' as col1, to_date('3/01/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      7     select 'ABCD' as col1, to_date('3/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      8     select 'ABCD' as col1, to_date('3/14/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
      9     select 'ABCD' as col1, to_date('3/25/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
    10     select 'ABCD' as col1, to_date('3/26/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
    11     select 'ABCD' as col1, to_date('3/27/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
    12     select 'ABCD' as col1, to_date('3/28/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
    13     select 'ABCD' as col1, to_date('3/29/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
    14     select 'ABCD' as col1, to_date('4/25/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual
    15  )
    16  select *
    17  from
    18  (
    19     select
    20             col1, col2, col3,
    21             lag(col3) over (partition by col1 order by col2 asc) as last_flag
    22     from data
    23  )
    24  where last_flag    != col3
    25  or    last_flag    is null;
    COL1         COL2                       COL LAS
    ABCD         10-FEB-2012 12 00:00       N
    ABCD         20-FEB-2012 12 00:00       Y   N
    ABCD         01-MAR-2012 12 00:00       N   Y
    ABCD         14-MAR-2012 12 00:00       Y   N
    ABCD         25-MAR-2012 12 00:00       N   Y
    ABCD         25-APR-2012 12 00:00       Y   N
    6 rows selected.
    Elapsed: 00:00:00.08
    ME_XE?Cheers,

  • Format the returned record out from the result

    Hi All,
    Please help me again.
    i have this query...
    Query:
    select* from patient where id = '9'
    Result:
    id fluX fluY fluZ Created_on
    1 Y - - 06/15/2007 2:06:05 AM
    1 - - - 06/15/2007 2:06:05 AM
    1 - - Y 06/15/2007 2:06:05 AM
    I want only to return only one row out from the result above.
    ID      fluX        fluY       fluZ
    1 Y - Y
    Thanks in advance for help.
    Edited by: jresh on Jun 21, 2009 10:11 PM

    Hi jresh,
    Try following
    select id, max(fluX), max(fluY), max(fluZ), Created_on
    from patient where id = '9'
    group by id, Created_on;
    Please mark, if it help you
    Regards,
    Danish

  • Randomly selecting some rows from the database table

    Hi can some one help me in selecting some rows from a database table which has around 90,000 rows.
    Thanks.

    One thing you might try is the "sample" clause if you have 8i which is supposed to return a random percentage of the table. Say for example, you have a sequence number on your table as the pkey. Then you might try:
    select * from <table_name> where pkey in(select pkey from <table_name> sample(10));
    This should give you a random 10 percent of the rows in the table but I tried this once and the results seemed unpredictable. For example it returned a different number of rows each time even though the number of rows in the table didn't change.
    Hope this works for you.

  • How to refresh a child table each time I select a row in the master table

    I've 2 tables, a master table and a child table.
    When i click on each row of the master table, the child table needs to be refreshed.
    I've given the id of table1(master) as the CreatePartialTrigger value in table2(child).
    The refresh does happen but it happens in an inconsistent manner.
    For eg. in my scenario,
    1.I add a row to the master table
    2.Click on the create button of the child table, this opens a popup and i enter a few values and the child row gets added.
    3.Now when i toggle between the rows in my master table, the refresh does not happen and I see duplicate rows in the child table but in the datebase only one record gets stamped..
    Is there any clean way to refresh the child table based on the row selection in the master table.
    Kindly let me know.
    Table1
    <fnd:applicationsTable tableId="table">
    <af:table value="#{bindings.Actions1.collectionModel}" var="row"
    rows="#{bindings.Actions1.rangeSize}"
    fetchSize="#{bindings.Actions1.rangeSize}"
    selectedRowKeys="#{bindings.Actions1.collectionModel.selectedRow}"
    selectionListener="#{bindings.Actions1.collectionModel.makeCurrent}"
    rowSelection="single" id="table1"
    contentDelivery="immediate" editingMode="clickToEdit"
    columnSelection="multiple" autoHeightRows="10"
    summary="#{HcmActionsTopGenBundle['Header.Action.ActionCode']}" rowBandingInterval="0"
    styleClass="AFStretchWidth"
    partialTriggers="::create ::createMenuItem">
    <af:column id="column1" headerText=" " width="5"
    rowHeader="true"/>
    <af:column sortProperty="ActionCode" sortable="true"
    headerText="#{bindings.Actions1.hints.ActionCode.label}" width="150"
    showRequired="true" rendered="true" id="c1">
    <af:inputText value="#{row.bindings.ActionCode.inputValue}"
    label="#{bindings.Actions1.hints.ActionCode.label}"
    required="#{bindings.Actions1.hints.ActionCode.mandatory}"
    columns="#{bindings.Actions1.hints.ActionCode.displayWidth}"
    maximumLength="#{bindings.Actions1.hints.ActionCode.precision}"
    shortDesc="#{bindings.Actions1.hints.ActionCode.tooltip}" id="it1"
    autoSubmit="true"
    />
    </af:column>
    </fnd:applicationsTable>
    Table 2
    <fnd:applicationsTable tableId="table2"
    styleClass="AFStretchWidth"
    id="AT2"
    actionsMenuRendered="false"
    secondaryToolbarRendered="false"
    createPatternType="secondaryWindow"
    createText="#{hcmActionsBundle['Action.Add']}"
    createAction="#{backingBeanScope.SetupUiBean.invokeCreatePopUp}"
    createPopupId="create1"
    editEnabled="false"
    createPartialTriggers="table1"

    Hi Frank,
    As you mentioned I already have the id of my master table which is 'table1' as the createPartialTrigger in my child table.
    In my case there are 2 scenarios.
    I add a row to the Master table and when I click on the create button on the chile table, I get a pop with 'Yes' , 'No' and 'Cancel'
    Scenario1
    If I click 'Yes' , then I get another popup where I enter the values for the ActionReasonsActionReasonUsagesVO which is a combination of the ActionReasonsEO and the ActionReasonUsagesEO, now when I click on OK, a new row gets created in the ActionReasonsActionReasonUsagesVO.
    In the above scenario things work fine, as I toggle between the rows in the Master table the child table gets refreshed.
    Scenario2
    If I click 'No' I get a search popup where I can query up the ActionReasonsVO and select existing data,on clicking OK, the values get mapped from the ActionReasonsVO to the ActionReasonsActionReasonUsagesVO.
    Now when I toggle between the rows in my master table, I observe 2 types of behaviors
    1.Due to incorrect refresh, the child table rows vanishes from the UI.
    2.There are duplicate rows in the child table.
    The issue is specific to this scenario where the refresh of the child table rows does not happen correctly.
    Edited by: 944295 on Apr 18, 2013 5:16 PM

  • How do I select a row from the middle of a recordset?

    UserID QuestionID Answered
    10 9 N
    10 8 N
    10 7 N
    10 6 N
    10 5 Y
    10 4 Y
    10 1 Y
    From the table sorted by QuestionID DESC, how do I select the first row from the bottom going up with Answered value equal to 'N'?
    Which in the example above would be:
    10 6 N
    I need to select this row and get the QuestionID value equal to 6.
    Right now I have:
    select QuestionID
    from tblMap
    where Answered = 'N'
    and ROWNUM = 1
    order by QuestionID ASC;
    This always the top most row, which would be:
    10 9 N

    Here i used DUAL to generate a list of numbers for me.
    ME_XE?select *
      2  from
      3  (
      4     select row_number() over (order by col1 desc) as rn, count(*) over() as cnt, col1
      5     from
      6     (
      7        select level as col1 from dual connect by level <= 9
      8     )
      9  )
    10  where ceil(cnt/2) = rn
    11  /
                    RN                CNT               COL1
                     5                  9                  5
    1 row selected.
    Elapsed: 00:00:00.07
    ME_XE?Edited by: Tubby on Jul 8, 2009 1:47 PM
    Seems i misread the question :)

  • Inserting row in the result set

    Hi
    need to insert a row in resultset when previous row typ=c and next row typ=p then need to insert one row in between typ c and p with typ =s see the #temp_result table for result expected
    --drop table temp1
    --drop table temp1_result
    --presently data:-
    create table temp1
    (id int,
    ord int,
    typ varchar(2),
    dt date)
    insert into temp1 values (101, 1, 'c', '2001-10-01')
    insert into temp1 values (101, 2, 'p', '2001-11-11')
    insert into temp1 values (102, 1, 'c', '2002-10-01')
    insert into temp1 values (102, 2, 'p', '2002-11-01')
    insert into temp1 values (102, 3, 'p', '2002-12-01')
    insert into temp1 values (103, 1, 'c', '2003-10-01')
    insert into temp1 values (103, 2, 'p', '2003-11-01')
    insert into temp1 values (104, 1, 'c', '2004-10-01')
    insert into temp1 values (104, 2, 'c', '2004-11-01')
    insert into temp1 values (104, 3, 'p', '2004-12-01')
    insert into temp1 values (105, 1, 'c', '2005-10-01')
    insert into temp1 values (105, 2, 'p', '2005-11-01')
    insert into temp1 values (105, 3, 'c', '2005-12-01')
    insert into temp1 values (106, 1, 'c', '2006-08-01')
    insert into temp1 values (106, 2, 'p', '2006-09-01')
    insert into temp1 values (106, 3, 'c', '2006-10-01')
    insert into temp1 values (106, 4, 'p', '2006-11-01')
    insert into temp1 values (106, 5, 'p', '2006-12-01')
    select * from temp1
    order by id, ord
    --result expected:-
    create table temp1_result
    (id int,
    ord int,
    typ varchar(2),
    dt date)
    insert into temp1_result values (101, 1, 'c', '2001-10-01')
    insert into temp1_result values (101, 2, 's', '')
    insert into temp1_result values (101, 3, 'p', '2001-11-11')
    insert into temp1_result values (102, 1, 'c', '2002-10-01')
    insert into temp1_result values (102, 2, 's', '')
    insert into temp1_result values (102, 3, 'p', '2002-11-01')
    insert into temp1_result values (102, 4, 'p', '2002-12-01')
    insert into temp1_result values (103, 1, 'c', '2003-10-01')
    insert into temp1_result values (103, 2, 's', '')
    insert into temp1_result values (103, 3, 'p', '2003-11-01')
    insert into temp1_result values (104, 1, 'c', '2004-10-01')
    insert into temp1_result values (104, 2, 'c', '2004-11-01')
    insert into temp1_result values (104, 3, 's', '')
    insert into temp1_result values (104, 4, 'p', '2004-12-01')
    insert into temp1_result values (105, 1, 'c', '2005-10-01')
    insert into temp1_result values (105, 2, 's', '')
    insert into temp1_result values (105, 3, 'p', '2005-11-01')
    insert into temp1_result values (105, 4, 'c', '2005-12-01')
    insert into temp1_result values (106, 1, 'c', '2006-08-01')
    insert into temp1_result values (106, 2, 's', '')
    insert into temp1_result values (106, 3, 'p', '2006-09-01')
    insert into temp1_result values (106, 4, 'c', '2006-10-01')
    insert into temp1_result values (106, 5, 's', '')
    insert into temp1_result values (106, 6, 'p', '2006-11-01')
    insert into temp1_result values (106, 7, 'p', '2006-12-01')
    select * from temp1_resultregards
    Edited by: @2**** on 31-Jan-2012 06:48

    Well, in an Oracle database, something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with temp as (select 101 as id, 1 as ord, 'c' as typ, date '2001-10-01' as dt from dual union all
      2                select 101, 2, 'p', date '2001-11-11' from dual union all
      3                select 102, 1, 'c', date '2002-10-01' from dual union all
      4                select 102, 2, 'p', date '2002-11-01' from dual union all
      5                select 102, 3, 'p', date '2002-12-01' from dual union all
      6                select 103, 1, 'c', date '2003-10-01' from dual union all
      7                select 103, 2, 'p', date '2003-11-01' from dual union all
      8                select 104, 1, 'c', date '2004-10-01' from dual union all
      9                select 104, 2, 'c', date '2004-11-01' from dual union all
    10                select 104, 3, 'p', date '2004-12-01' from dual union all
    11                select 105, 1, 'c', date '2005-10-01' from dual union all
    12                select 105, 2, 'p', date '2005-11-01' from dual union all
    13                select 105, 3, 'c', date '2005-12-01' from dual union all
    14                select 106, 1, 'c', date '2006-08-01' from dual union all
    15                select 106, 2, 'p', date '2006-09-01' from dual union all
    16                select 106, 3, 'c', date '2006-10-01' from dual union all
    17                select 106, 4, 'p', date '2006-11-01' from dual union all
    18                select 106, 5, 'p', date '2006-12-01' from dual)
    19  --
    20  -- end of test data
    21  --
    22  select id
    23        ,row_number() over (partition by id order by ord, typ) as ord
    24        ,typ
    25        ,dt
    26  from (
    27        select id
    28              ,ord
    29              ,case when rn = 2 and add_typ = 's' then add_typ else typ end as typ
    30              ,case when rn = 1 then dt else null end as dt
    31        from (
    32              select t.id, t.ord, t.typ, t.dt
    33                    ,case when typ = 'c' and lead(typ) over (partition by id order by ord) = 'p' then 's'
    34                     else null end as add_typ
    35              from   temp t
    36             ) x
    37             cross join (select rownum rn from dual connect by rownum <= 2)
    38        where not (rn = 2 and add_typ is null)
    39       )
    40* order by id, ord
    SQL> /
            ID        ORD T DT
           101          1 c 01-OCT-2001 00:00:00
           101          2 s
           101          3 p 11-NOV-2001 00:00:00
           102          1 c 01-OCT-2002 00:00:00
           102          2 s
           102          3 p 01-NOV-2002 00:00:00
           102          4 p 01-DEC-2002 00:00:00
           103          1 c 01-OCT-2003 00:00:00
           103          2 s
           103          3 p 01-NOV-2003 00:00:00
           104          1 c 01-OCT-2004 00:00:00
           104          2 c 01-NOV-2004 00:00:00
           104          3 s
           104          4 p 01-DEC-2004 00:00:00
           105          1 c 01-OCT-2005 00:00:00
           105          2 s
           105          3 p 01-NOV-2005 00:00:00
           105          4 c 01-DEC-2005 00:00:00
           106          1 c 01-AUG-2006 00:00:00
           106          2 s
           106          3 p 01-SEP-2006 00:00:00
           106          4 c 01-OCT-2006 00:00:00
           106          5 s
           106          6 p 01-NOV-2006 00:00:00
           106          7 p 01-DEC-2006 00:00:00
    25 rows selected.

  • In tabular form, is there a way to select one row as the default row?

    Hi, I have a tabular form which lists the many addresses that a fisherman may have. The query is: select default_addr_flag, addr1, addr2, city, state, zip from addresses where fisher_id = :PXX_fisher_id.
    I would like to have them set the default_addr_flag = 'Y' for ONLY ONE record....so even if they have many addresses, one must be selected as the default for any correspondence.
    Are there any examples, or does anyone have a suggestion. thank you!
    karen

    Hi Karen,
    I think first of all you should get yourself a browser and add-ons that allow you to inspect the HTML DOM elements. E.g. FF/Firebug/Error Console. Once you have the required tools you will be able to see for yourself what the DOM has, and then work out what you need to do.
    Most members, including myself, at times post solutions without really trying them out as they appear to be "obvious" even when they are not.
    Taking forward from the point where you have made the default address indication a "simple checkbox" from the Report Attributes tab, if you inspect the checkbox element you will find that it is somewhat more complex and Apex has created the elements with some JS code. E.g. this is a snippet from one of my application pages.
    <td headers="IS_CUSTOMER">
    <label class="hideMeButHearMe" for="f08_0001">Is Customer</label>
    <input type="checkbox" onclick="if (this.checked) {apex.jQuery('#f08_0001').val('Y');} else {apex.jQuery('#f08_0001').val('');}" id="f08_0001_01" checked="checked" value="Y" name="f08_NOSUBMIT" autocomplete="off">
    <input type="hidden" id="f08_0001" value="Y" name="f08" autocomplete="off">
    </td>You will see that
    a.Apex has created a onclick event trigger
    b. If sets the value of Unchecked checkbox to null ("").
    c. In my page the checkbox maps to f08, you need to see which item it maps to in your page.
    d. The id of the rendered checkbox is id of hidden element + _01.
    The consequence of this is that if you define a onclick trigger in the Element attributes it overrides and suppresses Apex from inserting its own JS code!
    To be able to uncheck all checkboxes other than the one the user has currently checked you will need to do this:
    i. In the Column's Element Attributes field write onclick="doDftAddr(this);"You could name the function the way you want it, this is an example.
    ii.In the Page HTML Header write
    <script type="text/javascript">
    function doDftAddr(pThis) {
      va = pThis.id.split("_");
      var vb = va[0]+'_'+va[1];
    if (pThis.checked) {
        vy = 'input:checked[id^="'+va[0]+'_"]'
        $("["+vy+"]").attr("checked",false);
        apex.jQuery("["+vy+"]").val('N');
        apex.jQuery('['+'input:hidden[id^="'+va[0]+'"_]'+']').val('N');
        apex.jQuery('#'+pThis.id).attr("checked",true);
        apex.jQuery('#'+pThis.id).val("Y");
        apex.jQuery('#'+vb).val('Y');
       } else {
        apex.jQuery('#'+vb).val('N');
    </script>Cheers,

Maybe you are looking for