Split and mark the records

Hi all,
I have the below scenario where i need to mark every 4 records with a number. The count of ids can vary for example i am taking 10 id's. Can any one suggest a sql statement to achieve this. Thanks for looking into it.
id         mark_id
1            1
2            1
3            1
4            1
5            2
6            2
7            2
8            2
9            3
10           3

Hi,
Here's one way:
SELECT       id
,       CEIL ( ROW_NUMBER () OVER (ORDER BY id)
            / 4
            )     AS mark_id
FROM       table_x
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.

Similar Messages

  • Can we split and fetch the records in Database Adapter

    Hi,
    I designed a Database Adapter to fetch the records from oracle Database. Some time, the Database Adapter need to fetch around 5000, or 10,000 records in single shot. In that case my BPEL process is choking and getting error as
    java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2882) at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
    Could someone help me to resolve this?
    In Database Adapter can we split and fetch the records, if number of records more then 1000.
    ex. First 100 rec as one set and next 100 as 2nd set like this.
    Thank you.

    You can send the records as batches useing the debatching feature of db adapter. Refer documentation for implementation details.

  • Comparing two internal tables and deleting the record not present in second

    Hi All,
    I have a internal table itaba with PERNR as primary key and various other columns (1000 records) and table B with PERNR as primary key and 800 records.
    Now what is the best way to compare these two and delete the record from table A when its corresponding record is not present in table B?
    Thanks and Regards,
    Mohan

    HI SIR
    u trained us in accenture
    Hi all
    when ever m running this session in SM35 , M getting error as :
    "LEAVE TO TRANSACTION" MARA-BISMT is not allow
    in batch input
    REPORT YASEC_BDC_NIK_SESSION
    no standard page heading
    message-id zmm
    line-count 65
    line-size 150.
    tables : mara.
    *Top includr program
    INCLUDE YNEW_MAIN_TOP.
    *include yasec_bdc_nik_session_top.
    ***********selection screen *******************
    selection-screen begin of block b1 with frame title text-001.
    selection-screen skip.
    PARAMETERS: p_ifile(128) TYPE c .
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS: rad1 TYPE c RADIOBUTTON GROUP 1 USER-COMMAND gr1,
    rad2 TYPE c RADIOBUTTON GROUP 1 .
    SELECTION-SCREEN SKIP.
    PARAMETERS: p_sess TYPE c.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK b1.
    Subroutine call***************************
    INCLUDE YNEW_MAIN_F01.
    *include yasec_bdc_nik_session_f01.
    *********At selection event triggered *************
    at selection-screen on value-request for p_ifile.
    To get F4 help for the input file path
    PERFORM f_f4_input_file.
    AT SELECTION-SCREEN ON p_ifile.
    To validate and upload the input file
    PERFORM f_load_file.
    AT SELECTION-SCREEN ON p_sess.
    To validate the Number of Sessions field
    IF rad2 IS NOT INITIAL AND sy-ucomm EQ c_onli.
    PERFORM f_check_sessions.
    ENDIF.
    ***********Start of selection *******************
    start-of-selection.
    *To process BDC
    PERFORM f_process_bdc.
    TOP OF PAGE
    TOP-OF-PAGE.
    Writes the report heading and for displaying line number.
    PERFORM f_report_header.
    TYPES : BEGIN OF t_final,
    matnr(50) TYPE c,
    bismt(18) type c,
    end of t_final.
    TYPES: BEGIN OF t_fdata,
    data(256) TYPE c,
    END OF t_fdata.
    TYPES: BEGIN OF t_error,
    message(100) TYPE c,
    END OF t_error.
    *Internal table declarations
    *Internal table to load the data from the file that is changed throgh BDC
    DATA : i_final TYPE STANDARD TABLE OF t_final,
    wa_final TYPE t_final.
    *Internal table to store the error messages
    DATA : i_error TYPE STANDARD TABLE OF t_error,
    wa_error TYPE t_error.
    *Internal table to load the raw data
    DATA : i_fdata TYPE STANDARD TABLE OF t_fdata,
    wa_fdata TYPE t_fdata.
    *Internal table to store records of BDC
    DATA : i_bdcdata TYPE STANDARD TABLE OF bdcdata INITIAL SIZE 0,
    wa_bdcdata TYPE bdcdata.
    Internal table to store BDC messages
    DATA: i_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll INITIAL SIZE 0,
    wa_bdcmsgcoll TYPE bdcmsgcoll.
    VARIABLE DECLARATIONS
    DATA: v_ifile TYPE string,
    v_input TYPE i,
    c_delimiter TYPE c VALUE 'X',
    v_mode TYPE c VALUE 'A',
    v_sessions TYPE i.
    CONSTANTS
    CONSTANTS : c_flagx TYPE c VALUE 'X',
    c_slash TYPE c VALUE '/',
    c_onli(4) TYPE c VALUE 'ONLI',
    c_vl02(4) TYPE c VALUE 'VL02',
    c_s TYPE c VALUE 'A'.
    FORM f_f4_input_file .
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    IMPORTING
    file_name = p_ifile.
    ENDFORM. " f_f4_input_file
    *& Form f_load_file
    FORM f_load_file .
    v_ifile = p_ifile.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_ifile
    filetype = 'ASC'
    has_field_separator = 'X'
    TABLES
    data_tab = i_fdata
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    IF sy-subrc <> 0.
    *Text-103-Input file does not exist.
    MESSAGE e000 WITH text-103 .
    ELSEIF NOT i_fdata IS INITIAL.
    DELETE i_fdata WHERE data = space.
    DESCRIBE TABLE i_fdata LINES v_input.
    ENDIF.
    IF v_input EQ 0.
    Text-104 - Input file is empty.
    MESSAGE e000 WITH text-104 .
    ENDIF.
    ENDFORM. " f_load_file
    *& Form f_check_sessions
    FORM f_check_sessions .
    IF p_sess IS INITIAL.
    MESSAGE e000 WITH text-106.
    ELSE.
    v_sessions = v_input DIV p_sess.
    ENDIF.
    ENDFORM. " f_check_sessions
    *& Form f_process_bdc
    text
    FORM f_process_bdc.
    LOOP AT i_fdata INTO wa_fdata.
    SPLIT wa_fdata AT cl_abap_char_utilities=>horizontal_tab
    INTO wa_final-matnr
    wa_final-bismt.
    APPEND wa_final TO i_final.
    CLEAR wa_fdata.
    ENDLOOP.
    IF rad1 = c_flagx.
    PERFORM f_passbdc_vl02.
    ELSEIF rad2 = c_flagx.
    PERFORM f_sessions_vl02.
    ENDIF.
    ENDFORM. "f_process_bdc
    To populate the Screen information
    p_program Program Name
    p_dynpro Screen Number
    FORM bdc_dynpro USING p_program TYPE any
    p_dynpro TYPE any.
    CLEAR wa_bdcdata.
    Populate the BDC structure with the Screen Information.
    Move the Program name PROGRAM
    wa_bdcdata-program = p_program.
    Move the Screen Number DYNPRO
    wa_bdcdata-dynpro = p_dynpro.
    Indicate the beginning of a new screen
    wa_bdcdata-dynbegin = c_flagx.
    APPEND wa_bdcdata TO i_bdcdata.
    ENDFORM. "f_bdc_dynpro
    *& Form f_passbdc_vl02
    text
    FORM f_passbdc_vl02.
    DATA: l_lines_im TYPE i.
    SORT i_final BY matnr ASCENDING.
    CLEAR wa_final.
    LOOP AT i_final INTO wa_final.
    CLEAR: i_bdcmsgcoll[],
    wa_bdcmsgcoll,
    wa_bdcdata.
    CLEAR: i_bdcdata[].
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'RMMG1-MATNR'
    wa_final-matnr.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
    'X'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-BISMT'.
    perform bdc_field using 'MARA-BISMT'
    wa_final-bismt.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM02'.
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM03'.
    CALL TRANSACTION 'MM02' USING i_bdcdata
    MODE v_mode
    UPDATE c_s
    MESSAGES INTO i_bdcmsgcoll.
    If error occurred in call transaction 'VA02' then stores all
    information of failed records into internal table i_error_im.
    IF sy-subrc NE 0.
    DESCRIBE TABLE i_bdcmsgcoll LINES l_lines_im.
    CLEAR wa_bdcmsgcoll.
    READ TABLE i_bdcmsgcoll INTO wa_bdcmsgcoll INDEX l_lines_im.
    To capture success and error messages in BDC.
    CALL FUNCTION 'FORMAT_MESSAGE' "#EC *
    EXPORTING
    id = wa_bdcmsgcoll-msgid
    lang = wa_bdcmsgcoll-msgspra
    no = wa_bdcmsgcoll-msgnr
    v1 = wa_bdcmsgcoll-msgv1
    v2 = wa_bdcmsgcoll-msgv2
    v3 = wa_bdcmsgcoll-msgv3
    v4 = wa_bdcmsgcoll-msgv4
    IMPORTING
    msg = wa_error-message
    EXCEPTIONS
    not_found = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    ENDIF.
    ELSE.
    WRITE: text-111 COLOR 7.
    ENDIF.
    CLEAR: wa_final.
    REFRESH i_bdcdata.
    ENDLOOP.
    ENDFORM. "f_passbdc_va02
    *& Form bdc_field
    text
    -->P_FNAM text
    -->P_FVAL text
    FORM bdc_field USING p_fnam TYPE any
    p_fval TYPE any.
    CLEAR wa_bdcdata.
    Populate the Field Name
    wa_bdcdata-fnam = p_fnam.
    Populate the field value
    wa_bdcdata-fval = p_fval.
    APPEND wa_bdcdata TO i_bdcdata.
    ENDFORM. "f_bdc_field
    *& Form f_sessions_vl02
    text
    FORM f_sessions_vl02 .
    DATA: l_sindex TYPE sy-tabix VALUE 1,
    l_eindex TYPE sy-tabix,
    l_flag TYPE c VALUE space.
    l_eindex = v_input.
    SORT i_final BY matnr ASCENDING.
    DO p_sess TIMES.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    client = sy-mandt
    group = 'Y_VL02_NIK'
    user = sy-uname
    keep = c_flagx
    EXCEPTIONS
    client_invalid = 1
    destination_invalid = 2
    group_invalid = 3
    group_is_locked = 4
    holddate_invalid = 5
    internal_error = 6
    queue_error = 7
    running = 8
    system_lock_error = 9
    user_invalid = 10
    OTHERS = 11.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    CLEAR wa_final.
    CLEAR: i_bdcdata[].
    LOOP AT i_final INTO wa_final FROM l_sindex TO l_eindex .
    IF l_flag = v_sessions.
    CLEAR l_flag.
    EXIT.
    ENDIF.
    l_flag = l_flag + 1.
    CLEAR: i_bdcdata[].
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'RMMG1-MATNR'
    wa_final-matnr.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
    'X'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'MARA-BISMT'.
    perform bdc_field using 'MARA-BISMT'
    wa_final-bismt.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM02'.
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_CURSOR'
    'MSICHTAUSW-DYTXT(01)'.
    perform bdc_field using 'BDC_OKCODE'
    '=ENTR'.
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE'
    '/00'.
    perform bdc_field using 'BDC_CURSOR'
    'RMMG1-MATNR'.
    perform bdc_dynpro using 'SAPLSPO1' '0300'.
    perform bdc_field using 'BDC_OKCODE'
    '=YES'.
    perform bdc_transaction using 'MM03'.
    l_sindex = l_sindex + 1.
    ENDLOOP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
    not_open = 1
    queue_error = 2
    OTHERS = 3.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDDO.
    ENDFORM. " f_sessions_vl02
    *& Form f_report_header
    FORM f_report_header .
    FORMAT COLOR COL_HEADING INTENSIFIED ON.
    ULINE.
    text-201 - Company: Carrier
    text-102- Batch Data Communication.
    text-202 - System: SAP
    WRITE: /1 sy-vline,
    3 text-201,
    50 text-102,
    100 text-202,
    AT sy-linsz sy-vline.
    text-203 - Program:
    text-204 - Date/Time:
    WRITE: /1 sy-vline,
    3 text-203, sy-repid ,
    100 text-204,sy-datum ,c_slash, sy-uzeit,
    AT sy-linsz sy-vline.
    text-205 - User ID:
    text-206 - Page:
    WRITE: /1 sy-vline,
    3 text-205, sy-uname,
    100 text-206, sy-pagno,
    AT sy-linsz sy-vline.
    FORMAT COLOR OFF.
    ULINE.
    ENDFORM. " f_report_header
    FORM bdc_transaction USING tcode.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    tcode = tcode
    TABLES
    dynprotab = i_bdcdata
    EXCEPTIONS
    internal_error = 1
    not_open = 2
    queue_error = 3
    tcode_invalid = 4
    printing_invalid = 5
    posting_invalid = 6
    OTHERS = 7.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ELSE.
    WRITE: / text-109 ,wa_final-matnr,
    text-110 .
    ENDIF.
    ENDFORM. "bdc_transaction

  • I have a huge file which is in GB and I want to split the video into clip and export each clip individually. Can you please help me how to split and export the videos to computer? It will be of great help!!

    I have a huge file which is in GB and I want to split the video into clip and export each clip individually. Can you please help me how to split and export the videos to computer? It will be of great help!!

    video
    What version of Premiere Elements do you have and on what computer operating system is it running?
    Please review the following workflow.
    ATR Premiere Elements Troubleshooting: PE11: Project Assets Organization for Scene and Highlight Grabs from Collection o…
    But please also determine if your project goal is supported by
    a. format of your source
    and
    b. computer resources
    More later based on details that you will post.
    ATR

  • I called 888 442 4551 and when the recording told me to press any number its not working,

    I called 888 442 4551 and when the recording ask me to press any number on dial pad its not working, means I can not make any choices,,,

    No, Apple does not support downgrading iOS. Never has.
    Start with a reset: Simultaneously hold down the Home and On buttons until the device shuts down. Ignore the off slider if it appears. Once shut down is complete, if it doesn't restart on it own, turn the device back on using the On button. In some cases it also helps to double click the Home button and close all apps BEFORE doing the reset.
    If that doesn't work, you may need do a full restore.

  • How to update and insert the records without using Table_comparison and Map_operation?

    How to update and insert the records without using Table_comparison and Map_operation?

    Use either join or MERGE see this Inserting, Updating, and Deleting Data by Using MERGE

  • I need my keyboard to be split and at the bottom

    my keyboard was split and at the bottom of my screen and all of the sudden quit and is back in the middle, how do i get it back?

    When you have the keyboard in the 'split' option, via the Keyboard, holding down the Botton and selecting 'split', when you go to marge it back, it gives the command of "Merge and Dock". This says to me, that when you choose 'split' that it will split and go centre screen. If it was to stay at the bottom, it would just say "Merge" with the Dock, so im thinking its not a Bug, its intended, and Apple wrote the Manual wrong.
    Its easier to write words in a Manual, than it is to write code to have it 'split' and 'docked'. So it seems a intentional thing to have in mid screen IMHO anyways.

  • DECODE function to validate date value and sort the records

    Hi Friends,
    I am looking for some query which can give me the required output,
    I need to do this using SQL query only and I have tried using the MIN() and MAX() functions it was working fine with limited data, now after inserting the last record(in the below table) which has date for start_range and end_range in(mm/dd/yyyy hh24:mi:ss) format.
    Because the data type is VARCHAR2 if I am using the MIN() function it is sorting as a string value, hence the min date is incorrect. I tried using validating the value to date or non date and tried to using MIN() and MAX() functions using the DECODE function, I am getting this error "ORA-01840: input value not long enough for date format".
    select table_name,
    DECODE(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1),'// ::',
    to_char(min(to_date(start_range,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),min(start_range)) MIN_RUNS_START_RANGE,
    DECODE(substr(END_RANGE,3,1)||substr(A.END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1),'// ::',
    to_char(max(to_date(END_RANGE,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),max(END_RANGE)) MAX_RUNS_END_RANGE
    from MY_TABLE
    GROUP BY table_name,
    (substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1)),
    (substr(END_RANGE,3,1)||substr(END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1))
    Can sombody please advise what is the best way I can query this data with the required output.
    The following are the source table and records and the out put records using the sql query.
    MY_TABLE
    TABLE_NAME(VARCHAR2),START_RANGE(VARCHAR2),END_RANGE(VARCHAR2)
    TABLE1,1000,10000
    TABLE2,ABCD,EEEE
    TABLE3,01/12/2010 00:00:00,12/31/2010 23:59:59
    TABLE1,10001,20000
    TABLE2,EEEF,GGGG
    TABLE3,01/01/2011 00:00:00,01/31/2011 23:59:59
    OUTPUT :
    TABLE_NAME,MIN(START_RANGE),MAX(END_RANGE)
    TABLE1,1000,20000
    TABLE2,ABCD,GGGG
    TABLE3,01/12/2010 00:00:00,01/31/2011 23:59:59
    Thanks
    Kalycs

    i also think this is a very bad table design ...
    but if you are not able to change it, you could split the select (date and non-date data) and combine the result with UNION like this:
    with t as
    SELECT 'TABLE1' table_name,'1000' start_range,'10000' end_range FROM dual UNION
    SELECT 'TABLE2','ABCD','EEEE' FROM dual UNION
    SELECT 'TABLE3','01/12/2010 00:00:00','12/31/2010 23:59:59' FROM dual UNION
    SELECT 'TABLE1','10001','20000' FROM dual UNION
    SELECT 'TABLE2','EEEF','GGGG' FROM dual UNION
    SELECT 'TABLE3','01/01/2011 00:00:00','01/31/2011 23:59:59' FROM dual
    SELECT table_name,
           TO_CHAR(MIN(TO_DATE(start_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS'),
           TO_CHAR(MAX(TO_DATE(end_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS')
    FROM t
    WHERE start_range LIKE '%/%/%:%:%'
    GROUP BY table_name
    UNION
    SELECT table_name,
           MIN(start_range),
           MAX(end_range)
    FROM t
    WHERE start_range NOT LIKE '%/%/%:%:%'
    GROUP BY
        table_name;
    TABLE_ MIN_VALUE           MAX_VALUE
    TABLE1 1000                20000
    TABLE2 ABCD                GGGG
    TABLE3 01/12/2010 00:00:00 01/31/2011 23:59:59

  • How to select and duplicate the records and update some column values using cursor

    I have a table with 920 records, we need to update the end date to 6/30/2014 for 920 records and I need to create all 920 records with start date is 7/1/2014 and update the external value to
    CCC.
    Note: the table primary key is not auto increment, but I have sp to get the latest key for that.
    Existing table.  
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    1
    XXX
    AAA
    BBB
    1/1/2013
    6/30/2015
    Create new records
    ID
    Source Name
    Internal value
    External value
    Start date
    End date
    921
    XXX
    AAA
    CCC
    7/1/2013
    12/30/2015

    Hi ManuGT
    If I understand what you need then you ask for:
    1. updating all current rows (920 rows in the table now)
    2. insert new rows which are duplicates of the preiviews rows, but with value 'CCC' insteade of 'BBB'
    If so, there is not reason to use a cursor and it is highly NOT RECOMMENDED to use ant type of loop.
    You should work with SET and do it all in 2 simple queries:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    Unfortunately you did not post DDL+DML! Therefore we cant see your table structure and the data sample and we can only guess. I used Saeid's post as the basic DDL+DML.
    Please next time post DDL+DML
    here is the full code with the DDL+DML that i used:
    -- This is our DDL - A create table query:
    create table test
    ( id int identity(1,1) primary key,
    SourceName nvarchar(3),
    InternalValue nvarchar(3),
    ExternalValue nvarchar(3),
    StartDate date,
    EndDate date
    go
    -- This is our DML - A query that insert some sample data
    declare @i int = 1 ;
    while @i < 921
    begin
    insert test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    values ('XXX', 'AAA', 'BBB', '1/1/2014', '6/30/2014' ) ;
    set @i += 1 ;
    end ;
    GO
    -- Here is the solution for the problem as I understood your needs:
    -- first we duplicate the existing rows,
    -- but we use the values 'CCC" and '20140107' for the new rows values
    INSERT test (SourceName, InternalValue, ExternalValue, StartDate, EndDate)
    select SourceName, 'CCC', ExternalValue, '20140107' , EndDate
    from test
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Now we update the old rows (check the filter! I get only the old rows since I filter the new rown out)
    UPDATE test
    SET EndDate = '20140107' -- I use date in format yyyymmdd, You can use other formats as well
    where
    -- You can use any filter that you need if you dont want to update all rows
    InternalValue = 'AAA' and ExternalValue = 'BBB' and StartDate = '20140101' and EndDate = '20140630'
    -- Here we just check how the result look like :-)
    select *
    from test ;
    -- And since we do not realy need this table in our server... Here we clean the DDL (you probaby DO NOT WANT TO EXECUTE THIS!)
    DROP table test
    GO
    I hope this was useful :-)
    [Personal Site] [Blog] [Facebook]

  • Splitting and executing the query for each 1 lac and executing parallel.

    Hi All,
    We have a table with around 10 keys and each key is having more than millions of records for a given date.
    And my requirement is to find the sum of the sale_price of each keys.
    ( example :
    Select key, sum(sale_price) from table1 where date1=sysdate
    group by key
    Since, each set of key contains more than a millions of records, It's time consumption is too high.
    Is thr any way to achieve as below,
    For key 1 (assume 1 million records)
    and we will spilt these into 100 parts and execute parallelly.
    At the end get sum of all 100 parts.
    Similarly for other keys....
    Is it possible to divide the records into 1 lac each and give it for parallel execution ?

    If the key column is also the partition key, I would expect that to work well with parallel query. What have you tried that isn't working? Also what is your Oracle version?

  • RE: Pbm in alv for copying and inserting the record....

    Hi,
       I am developing alv gird  report...............what my issue is:
      while selecting a record...........he should copy the record and insert a new record
      below on which he selected....
      Regarding this if anybody helps me that will be appreciable...
    Regards,
    Naveen M.

    hai Do like This:
    at user command
    FORM PICK USING COMMAND LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD. "Pick is name  given in REUSE_ALV_GRID
    READ TABLE idata INTO wa_data INDEX SELFIELD-TABINDEX.
    CASE COMMAND.
    WHEN '&IC1'.
    Select second data according to your requirement in Another internal  table.
    newdata[] = idata[]. "Move ur first table display data to one new internal tabe.
    clear idata[].
    append wa_data to idata.
    now move data which was selected in select statement to idata table and append data. "it will add new data in idata table
    after this get previous data in idata
    READ TABLE newdata INTO wa_data INDEX SELFIELD-TABINDEX.
    clear wa_data.
    modify newdata index sy-tabix.
    delete newdata where "it is initial.
    loop at newdata.
    idata = newdata.
    append idata.
    endloop.
    after this call reuse_alv_grid_display.
    endcase
    endform.

  • Insert a DB record and receive the Record ID

    Hi !
    I'm trying to populate a DB (two tables) based
    on the classic master/detail approach.
    These steps represent what I would like to achieve :
    1) add the master record and get the corresponding primary key
    2) add multiple records in another table using the Master Prim.key
    That seems to be so simple,
    but I have no idea how to get the Master PrimaryKey.
    Thanks.
    GB.

    You can't get a result back from the standard database call. If there is another unique field, you could query again based on that. I needed something with one child record. I did the whole thing in a PL/SQL block passing all the parameters to one call.
    To get a value back from a call, look at this thread: http://www.adobeforums.com/webx/.59b7d6b1/3

  • Split and find the real delimeter

    Hi,
    i have some long string.
    String str=key\\++value;ke\\;y\\+key+value;key\\+key+value\\;value;key+value
    first i have to split base on ';' and not base on \\;
    and get the following:
    key\\++value
    ke\\;y\\+key+value
    key\\+key+value\\;value
    key+value
    then i need to split base on + and not base on \\+
    key                  value
    key\\+              value
    ke\\;y\\+key     value
    key\\+key        value\\;value
    key                 value
    please advice how i should do that and which regular expression i need to use or not use but split base on above manner.
    Thanks.

    i have some long string. 
    String str=key\\++value;ke\\;y\\+key+value;key\\+key+value\\;value;key+value
    Why are you basically just ignoring the advice you got in your other thread about how to properly create delimited strings?
    https://forums.oracle.com/thread/2569685
    You were told there the requirements that you needed to follow to handle embedded delimiters and the rules you need to use to parse such strings. This is what you just said above:
    first i have to split base on ';' and not base on \\;
    then i need to split base on + and not base on \\+
    That is NOT what you were told in your other thread. What I said there is still true whether you choose to believe it or not:
    THERE ARE NO SHORTCUTS! You either have to do it right or be willing to suffer the consequences.

  • Need to get the input dynamically and write the records

    hi everyone,
    iam having a doubt in scripts,
    1.i need to get the input from user
    (input is the table name)
    2.if the input matches with the tables in the database and the n it has to write the records in a csv format.
    3.the fields should be delimited by comma.
    is it possible to write a script or procedure.
    the script should be a generic one.
    thanks and Regards,
    R.Ratheesh

    hi
    ,,actually my column_names are.
    select T24_ACCOUNT_NUMBER||','||
    NULLIF(T24_CUSTOMER,NULL)||','||
    NULLIF(T24_CATEGORY,NULL)||','||
    NULLIF(T24_ACCOUNT_TITLE_1,'')||','||
    NVL(T24_ACCOUNT_TITLE_2,'')||','||
    NULLIF(T24_SHORT_TITLE,'')||','||
    NULLIF(T24_SHORT_TITLE,'')||','||
    NULLIF(T24_POSITION_TYPE,'')||','||
    NULLIF(T24_CURRENCY,'')||','||
    NULLIF(T24_LIMIT_REF,NULL)||','||
    NULLIF(T24_ACCOUNT_OFFICER,NULL)||','||
    NULLIF(T24_OTHER_OFFICER,NULL)||','||
    NULLIF(T24_POSTING_RESTRICT,NULL)||','||
    NULLIF(T24_RECONCILE_ACCT,'')||','||
    NULLIF(T24_INTEREST_LIQU_ACCT,NULL)||','||
    NULLIF(T24_INTEREST_COMP_ACCT,NULL)||','||
    NULLIF(T24_INT_NO_BOOKING,'')||','||
    NULLIF(T24_REFERAL_CODE,NULL)||','||
    NULLIF(T24_WAIVE_LEDGER_FEE,'')||','||
    NULLIF(T24_PASSBOOK,'')||','||
    NVL(TO_CHAR(T24_OPENING_DATE,'YYYYMMDD'),'')||','||
    NULLIF(T24_LIMK_TO_LIMIT,'')||','||
    NULLIF(T24_CHARGE_ACCOUNT,NULL)||','||
    NULLIF(T24_CHARGE_CCY,'')||','||
    NULLIF(T24_INTEREST_CCY,'')||','||
    NULLIF(T24_ALT_ACCT_IDa,NULL)||','||
    NULLIF(T24_PREMIUM_TYPE,'')||','||
    NULLIF(T24_PREMIUM_FREQ,'')||','||
    NULLIF(T24_JOINT_HOLDER,NULL)||','||
    NULLIF(T24_RELATION_CODE,NULL)||','||
    NULLIF(T24_JOINT_NOTES,'')||','||
    NULLIF(T24_ALLOW_NETTING,'')||','||
    NULLIF(T24_LEDG_RECO_WITH,NULL)||','||
    NULLIF(T24_STMT_RECO_WITH,NULL)||','||
    NULLIF(T24_OUR_EXT_ACCT_NO,'')||','||
    NULLIF(T24_RECO_TOLERANCE,NULL)||','||
    NULLIF(T24_AUTO_PAY_ACCT,NULL)||','||
    NULLIF(T24_ORIG_CCY_PAYMENT,'')||','||
    NULLIF(T24_AUTO_REC_CCY,'')||','||
    NULLIF(T24_DISPO_OFFICER,NULL)||','||
    NULLIF(T24_DISPO_EXEMPT,'')||','||
    NULLIF(T24_ICA_DISTRIB_RATIO,NULL)||','||
    NULLIF(T24_LIQUIDATION_MODE,'')||','||
    NULLIF(T24_INCOME_TAX_CALC,'')||','||
    NULLIF(T24_SINGLE_LIMIT,'')||','||
    NULLIF(T24_CONTINGENT_INT,'')||','||
    NULLIF(T24_CREDIT_CHECK,'')||','||
    NULLIF(T24_AVAILABLE_BAL_UPD,'')||','||
    NULLIF(T24_CONSOLIDATE_ENT,'')||','||
    NULLIF(T24_MAX_SUB_ACCOUNT,NULL)||','||
    NULLIF(T24_MASTER_ACCOUNT,'')||','||
    NULLIF(T24_FUND_ID,'') FROM T24_CACCOUNT;
    this is the order
    but while my output looks like
    SQL> set serveroutput on
    SQL> set verify off
    SQL> set heading off
    SQL> spool /emea/dbtest/tamdbin/bnk/bnk.run/DATA.BP/SAM_ACC.csv
    SQL> exec input_table('T24_CACCOUNT');
    declare cursor c2 is select
    rownum||','||T24_WAIVE_LEDGER_FEE||','||T24_PASSBOOK||','||T24_OPENING_DATE||','
    ||T24_LIMK_TO_LIMIT||','||T24_CHARGE_ACCOUNT||','||T24_CHARGE_CCY||','||T24_INTE
    REST_CCY||','||T24_ALT_ACCT_IDA||','||T24_PREMIUM_TYPE||','||T24_PREMIUM_FREQ||'
    ,'||T24_JOINT_HOLDER||','||T24_RELATION_CODE||','||T24_JOINT_NOTES||','||T24_ALL
    OW_NETTING||','||T24_LEDG_RECO_WITH||','||T24_STMT_RECO_WITH||','||T24_OUR_EXT_A
    CCT_NO||','||T24_RECO_TOLERANCE||','||T24_AUTO_PAY_ACCT||','||T24_ORIG_CCY_PAYME
    NT||','||T24_AUTO_REC_CCY||','||T24_DISPO_OFFICER||','||T24_DISPO_EXEMPT||','||T
    24_ICA_DISTRIB_RATIO||','||T24_LIQUIDATION_MODE||','||T24_INCOME_TAX_CALC||','||
    T24_SINGLE_LIMIT||','||T24_CONTINGENT_INT||','||T24_CREDIT_CHECK||','||T24_AVAIL
    ABLE_BAL_UPD||','||T24_CONSOLIDATE_ENT||','||T24_MAX_SUB_ACCOUNT||','||T24_MASTE
    R_ACCOUNT||','||T24_FUND_ID||','||T24_ACCOUNT_NUMBER||','||T24_CUSTOMER||','||T2
    4_CATEGORY||','||T24_ACCOUNT_TITLE_1||','||T24_ACCOUNT_TITLE_2||','||T24_SHORT_T
    ITLE||','||T24_MNEMONIC||','||T24_POSITION_TYPE||','||T24_CURRENCY||','||T24_LIM
    IT_REF||','||T24_ACCOUNT_OFFICER||','||T24_OTHER_OFFICER||','||T24_POSTING_RESTR
    ICT||','||T24_RECONCILE_ACCT||','||T24_INTEREST_LIQU_ACCT||','||T24_INTEREST_COM
    P_ACCT||','||T24_INT_NO_BOOKING||','||T24_REFERAL_CODE SRC from T24_CACCOUNT; r2
    c2%rowtype; begin for r2 in c2 loop dbms_output.put_line(r2.SRC); end loop;
    end;
    1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222284001,2222222,6001,,,,,TR,USD,,,,,,,,
    2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222384001,2222223,6001,,,,,TR,USD,,,,,,,,
    3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222484001,2222224,6001,,,,,TR,USD,,,,,,,,
    4,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222584001,2222225,6001,,,,,TR,USD,,,,,,,,
    5,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222684001,2222226,6001,,,,,TR,USD,,,,,,,,
    6,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222284001,2222222,6001,,,,,TR,USD,,,,,,,,
    7,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222384001,2222223,6001,,,,,TR,USD,,,,,,,,
    8,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222484001,2222224,6001,,,,,TR,USD,,,,,,,,
    9,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222584001,2222225,6001,,,,,TR,USD,,,,,,,,
    10,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222684001,2222226,6001,,,,,TR,USD,,,,,,,
    11,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222284001,2222222,6001,,,,,TR,USD,,,,,,,
    12,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222384001,2222223,6001,,,,,TR,USD,,,,,,,
    13,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222484001,2222224,6001,,,,,TR,USD,,,,,,,
    14,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222584001,2222225,6001,,,,,TR,USD,,,,,,,
    15,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,222222684001,2222226,6001,,,,,TR,USD,,,,,,,
    here if we look at the select statement the previous one ,its starts from middle and
    picking up the records.i dont know y.and also its not writing the records in the path (spool)which i have given..can u pls check it out if possible.
    thanks ,.
    R.Ratheesh

  • Comparing two tables and picking the records

    I have two tables A and B.  I have to compare a column ID in both table A and table B  A.ID=B.ID  And based on the above comparison if the match is found I need to pick the records from table A and if no match then need to pick the records from table B  My problem is if I join then I will have table A and table B as one record and will be difficult to separate out.  Please let me know how this can be acheived.  Thnx.

    I have two tables A and B.  I have to compare a column ID in both table A and table B  A.ID=B.ID  And based on the above comparison if the match is found I need to pick the records from table A and if no match then need to pick the records from table B  My problem is if I join then I will have table A and table B as one record and will be difficult to separate out.  Please let me know how this can be acheived.  Thnx.

Maybe you are looking for

  • Change of the backend logical system server

    Hi all, Our client is changing the backend logical system's server which is of ECC 6.0 moving all the transports in production from ECC system to another. Can anyone explain what will be the impact to the SRM server? We have SRM 5.0( two clients one

  • More on unix script from pl/sql

    Hi All, There was this discussion on starting unix scripts from within a pl/sql stored procedure started on August 31. All comments were targeted towards an oracle 8X solution. Does anyone have a solution for 7.3.4? Somebody mentioned something about

  • Core Duo Temp Question

    I just got my replacement macbook from apple and so far it's working great. Something odd I noticed is that with any temperature monitor program I use (core duo temp is one of them) the temperature seems to be locked at whatever it was at startup. It

  • Firefox is crashing/stalling with Facebook games/chat - what's up?

    When using WordTwist (a Zynga app) on Facebook as well as Facebook chat - Firefox is stalling and crashing - any suggestions? I use a Mac G4

  • Missing Scene

    I have a movie with two scenes. When I open the fla to edit, I only see/access one scene. I cannot get to the second scene via teh Scene Window or any other means. Any ideas?