SQL 2008 how to compare & identify data among 2 tables with same structure ?

Hello is there a TSQL way of comparing row by row for example comparing DateTimeStamp field in 2 separate tables with same structure in identifying if it's data was changed (If Table1.DateField > Table2.DateField THEN UPDATE it's entire row to match it's
corresponding Table1 row.) ?
Probably thinking would need a cursor to loop through or are there other better ways via TSQL ?
Thanks in advance.

Hi,
I am assuming you have a PRIMARY KEY field or a UNIQUE field in both tables, which you should!
You can do this using "UPDATE with INNER JOIN". (SQL Server – Update Table with INNER JOIN)
Working example:
USE [TestDatabase]
GO
/* Create Temp Tables */
CREATE TABLE [dbo].[Table1]
[ID] INT
,[Name] VARCHAR(10)
,[ModifyDate] DATETIME
CREATE TABLE [dbo].[Table2]
[ID] INT
,[Name] VARCHAR(10)
,[ModifyDate] DATETIME
GO
INSERT INTO [dbo].[Table1] ([ID], [Name], [ModifyDate]) VALUES (1, 'Vishal', GETDATE())
INSERT INTO [dbo].[Table2] ([ID], [Name], [ModifyDate]) VALUES (1, 'Gajjar', GETDATE() + 1)
GO
SELECT [ID], [Name], [ModifyDate] FROM [dbo].[Table1]
SELECT [ID], [Name], [ModifyDate] FROM [dbo].[Table2]
GO
UPDATE T1
SET T1.[Name] = T2.[Name]
FROM [dbo].[Table1] T1
INNER JOIN [dbo].[Table2] T2 ON T1.[ID] = T2.[ID] /* Join on Key field */
WHERE T2.[ModifyDate] > T1.[ModifyDate] /* Update criteria */
GO
/* CleanUp - Drop Tables
DROP TABLE [dbo].[Table1], [dbo].[Table2]
This Updates Table1 with latest values from Table2, You need to change the UPDATE statement for your scenario.
- Vishal
SqlAndMe.com

Similar Messages

  • How can I load data into table with SQL*LOADER

    how can I load data into table with SQL*LOADER
    when column data length more than 255 bytes?
    when column exceed 255 ,data can not be insert into table by SQL*LOADER
    CREATE TABLE A (
    A VARCHAR2 ( 10 ) ,
    B VARCHAR2 ( 10 ) ,
    C VARCHAR2 ( 10 ) ,
    E VARCHAR2 ( 2000 ) );
    control file:
    load data
    append into table A
    fields terminated by X'09'
    (A , B , C , E )
    SQL*LOADER command:
    sqlldr test/test control=A_ctl.txt data=A.xls log=b.log
    datafile:
    column E is more than 255bytes
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)

    Check this out.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1006961

  • How to create an dynamic internal table with the structure of a ddic table

    Hi all,
    I want to fill ddic-tables (which I already created) in my abap dictionary with data out of CSV-files (which are located on the CRM-Server).  The ddic tables have different amount of fields.
    I started with creating a table which contains the name of the tables and the path to the matching CSV-file.
    At the beginning I'm filling an internal table with part of this data (the name of the ddic-tables) - after that I am looping at this internal table.
    LOOP AT lt_struc ASSIGNING <lfs_struc>.
         LOOP AT lv_itab1 INTO lv_wa1 WHERE ztab_name = <lfs_struc>.
         lv_feld = lv_wa1-zdat_name.
        ENDLOOP.
        CONCATENATE 'C:\-tmp\Exportierte Tabellen\' lv_feld INTO lv_pfad.
        Do.
        OPEN DATASET lv_pfad FOR INPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
        READ DATASET lv_pfad INTO lv_rec.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        enddo.
        REPLACE ALL OCCURRENCES OF '"' IN lv_rec WITH ''.
        SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
        INSERT into (<lfs_struc>) values lr_str_value.
        CLOSE DATASET lv_pfad.
    endloop.
    This is not the whole code, but it's working until
    SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
    I want to split all the data of lv_rec into an internal table which has the structure of the current ddic-table, but I didn't find out how to do give the internal table the structure of the ddic-table. In the code I used an internal tyble type string but I should be the structure of the matching tabel.
    If I try to create an internal table by using a fiel symbol, I am told, that the data types are not matching.
    Has anyone an idea?

    Hi Mayari,
    though you were successfull with
    METHOD cl_alv_table_create=>create_dynamic_table
    I must warn you not to use it. The reason is that the number of tables created is limited, the method uses GENERATE SUBROUTINE statement and this triggers an unwanted database commit.
    If you know the DDIC structure, it is (starting with ECC6.0) much easier:
    field-symbols:
      <table> type standard table.
    data:
      lr_data type ref to data.
    Create data lr_data type table of (<DDIC structure>).
    assign lr_data->* to <table>.
    The split code can be simplified gaining speed loosing complexity not loosing functionality.
    field-symbols:<fs_s> type any.
    field-symbols:<fs_t> type any.
    SPLIT lv_rec AT ';' INTO table it_string.
    loop at it_string assigning <fs_s>.
      assign component sy-tabix of wa_string to <fs_t>.
    if sy-subrc = 0.
      <fs_t> = <fs_s>.
    endif.
    at last.
      append <fs_itwa3> to <ft_itab3>.
    endat.
    endloop.
    Though it may work as Keshav.T suggested, there is no need to do that way.     
    Regards,
    Clemens

  • Bug: showing data in tables with same name, 2 different databases

    Hi,
    two connections, to databases "a" & "b". Both logged into the same schema, "s".
    If you select table "t" in db "a" and then select the same table in db "b", the tab is not refreshed - you have to either select a different object first, or explicitly hit refresh.
    regards,
    William

    I can reproduce this consistently on 9.2.0.1.
    You need to have connections to the same schema in two different databases and the schemas must have the same table.
    1 Open connection in schema 1
    2 Select the table in the Tables node
    3 Select the Data tab
    4 Open connection to schema 2
    5 Select the table in the Tables node (without going to any other tabs or objects)
    What should happen is the details of the second table should occupy the main display tab and the data tab should be refreshed to show the data of the new table.
    What actually happens is the main display tab apparently switches to the table in the new connection as shown by the tooltip (table@connection_name), but the data in the data tab stays the same. Refresh doesn't seem to work, only switching to a different object and back again.
    The columns tab does seem to refresh properly.

  • How to update the data base table with data

    i have two ztables, one is zfm_kfz and other one is zfm_kmvrg
    zfm_kfz is maintained by using table maintenance generator as well as alv grid control for list display.
    zfm_kfz the field r like this KFZR, GERAET, KOSTENTRAEGER, BEZEICHNUNG, TUVDATUMMMYYYY, ASUDATUMMMYYYY, KMSTAND, HISTO AND REIFEN.
    PROBLEM: all the data in grid control r updated except KMSTAND
    fields in zfm_kmvrg are kostentraeger, kfznr and kmstand i m creating table control for this screen here what ever enter the last km stand is updated in the list.for one kfznr many kostentraegers and kmstand, the last km stand is updated here , go through this code plz hepl me
    CONTROLS tabctrl TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF tabctrl-cols,
          lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF zfm_kmvrg,
          fs_itab LIKE LINE OF itab,
          fl_change TYPE c,
          fl_error  TYPE c.
    *TABLES fs_itab.
    LOOP AT tabctrl-cols INTO cols.
      cols-screen-input = '0'.
      MODIFY tabctrl-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    *SELECT * FROM spfli INTO TABLE itab.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_101'.
      DESCRIBE TABLE itab LINES lines.
      tabctrl-lines = lines.
    ENDMODULE.                    "status_0100 OUTPUT
    MODULE cancel INPUT
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.                    "cancel INPUT
    MODULE read_table_control INPUT
    MODULE read_table_control INPUT.
      MODIFY itab FROM fs_itab INDEX tabctrl-current_line.
    ENDMODULE.                    "read_table_control INPUT
    MODULE user_command_0100 INPUT
    MODULE user_command_0100 INPUT.
      DATA:
        lw_index TYPE i.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'ADD'.
          LOOP AT tabctrl-cols INTO cols.
            cols-screen-input = '1'.
            MODIFY tabctrl-cols FROM cols INDEX sy-tabix.
          ENDLOOP.
          CLEAR fs_itab.
          APPEND fs_itab TO itab.
        WHEN 'SAVE'.
          IF NOT itab[] IS INITIAL.
            LOOP AT itab[] into FS_ITAB.
              lw_index = sy-tabix.
              IF NOT fs_itab IS INITIAL.
                MODIFY ZFM_KMVRG FROM fs_itab.
                IF sy-subrc EQ 0.
                  UPDATE ZFM_KFZ set kmstand = fs_itab-kmstand
                                        WHERE kfznr = fs_itab-kfznr.
                ELSE.
                  fl_error = 'X'.
                  WRITE:/ 'The record number', lw_index,
                          'has not been updated'.
                ENDIF.
              ENDIF.
            ENDLOOP.
          ELSE.
            MESSAGE s000(0) WITH 'No data is present to update'.
          ENDIF.
      ENDCASE.
      IF fl_error = 'X'.
        LEAVE TO LIST-PROCESSING.
      ELSE.
        MESSAGE s000(0) WITH
              'All the records have been updated successfully'.
      ENDIF.
    ENDMODULE.                    "user_command_0100 INPUT
    IN SE51
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0100.
      LOOP AT ITAB INTO fs_itab WITH CONTROL tabctrl.
      ENDLOOP.
    PROCESS AFTER INPUT.
      MODULE CANCEL AT EXIT-COMMAND.
      LOOP AT ITAB.
        module read_table_control.
      ENDLOOP.
      module user_command_0100.
    i m trying many times i m not getting proper output, plz help me on this

    Hi,
    I am hereby givng the similar sample code.Check this with your requirement.
    In the flow logic of the screen 9000, write the following code.
    PROCESS BEFORE OUTPUT.
      MODULE set_status.
      MODULE get_t_ctrl_lines.
      LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.
    * Dynamic screen modifications
        MODULE set_screen_fields.
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT i_makt.
        FIELD i_makt-pick MODULE check.
        FIELD i_makt-zmatnr MODULE zmatnr .
      ENDLOOP.
      MODULE user_command_9000.
    In the program, write the following code.
    PROGRAM SAPMZTC MESSAGE-ID zz.
    * Tables Declaration
    TABLES: zzz_makt.
    * Internal table Declaration
    DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.
    * Table control Declaration
    CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.
    * Variable Declaration
    DATA : flg,           "Flag to set the change mode
           ln TYPE i.     "No. of records
    *&      Module  get_T_CTRL_lines  OUTPUT
    *  Populating data
    MODULE get_t_ctrl_lines OUTPUT.
      SELECT zmatnr zmaktx
             INTO CORRESPONDING FIELDS OF TABLE i_makt
             FROM zzz_makt.
      DESCRIBE TABLE i_makt LINES ln.
    * To make the vertical scroll bar to come on runtime
      t_ctrl-lines = ln + 100.
    ENDMODULE.                 " get_T_CTRL_lines  OUTPUT
    *&      Module  USER_COMMAND_9000  INPUT
    * Triggering event according to the user command
    MODULE user_command_9000 INPUT.
      DATA :lv_fcode LIKE sy-ucomm,    "Function Code
            lv_answer(1) type c.       "Storing the answer
      lv_fcode = sy-ucomm.
      CASE lv_fcode.
        WHEN 'CHANGE'.
    * Setting the flag to make the table control in editable mode[excluding
    * primary key].
          flg = 'Y'.
        WHEN 'DELETE'.
    * Setting the flag to make the table control in editable mode after
    * deleting the selected line
          flg = 'Y'.
    * Confirmation of delete
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
             TITLEBAR       = 'Confirm'
             text_question  = 'Are you sure to delete from database?'
             TEXT_BUTTON_1  = 'Yes'(001)
             TEXT_BUTTON_2  = 'No'(002)
            IMPORTING
             ANSWER         =  lv_answer.
          if lv_answer eq '1'.
    * Updating the database table from the internal table
            UPDATE zzz_makt FROM TABLE i_makt.
    * Deleting the selected row from the internal table
            DELETE i_makt WHERE pick = 'X'.
    * Deleting the selected row from the database table
            DELETE FROM zzz_makt WHERE pick = 'X'.
            MESSAGE s005 WITH 'Deleted Successfully'.
          ENDIF.
        WHEN 'SAVE'.
    * Inserting new record or updating existing record in database table
    * from the internal table
          MODIFY zzz_makt FROM TABLE i_makt.
          MESSAGE s005 WITH 'Saved Successfully'.
        WHEN 'BACK'.
          SET SCREEN '0'.
        WHEN 'EXIT' OR 'CANCEL'.
    * Leaving the program
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPUT
    *&      Module  set_screen_fields  OUTPUT
    * Setting the screen fields
    MODULE set_screen_fields OUTPUT.
      LOOP AT SCREEN.
        IF flg IS INITIAL.
          screen-input = 0.
        ELSEIF ( flg EQ 'Y' ).
          IF ( ( screen-name = 'I_MAKT-ZMAKTX'
                 OR screen-name = 'I_MAKT-CHECK1' )
                AND t_ctrl-current_line LE ln ) .
    * Making the screen fields as editable
            screen-input = 1.
          ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )
                     AND t_ctrl-current_line LE ln ).
    * Making the screen field as uneditable
            screen-input = 0.
          ENDIF.
        ENDIF.
    * Modifying the screen after making changes
        MODIFY SCREEN.
      ENDLOOP.
    ENDMODULE.                 " set_screen_fields  OUTPUT
    *&      Module  zmatnr  INPUT
    * Appending records to the internal table
    MODULE zmatnr INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
      IF t_ctrl-current_line GT ln.
        READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.
        IF sy-subrc NE 0.
    * Inserting record if it does not exist in database
          APPEND i_makt.
        ELSE.
         MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " zmatnr  INPUT
    *&      Module  set_status  OUTPUT
    * Setting the GUI status
    MODULE set_status OUTPUT.
      SET PF-STATUS 'ZSTATUS'.
      SET TITLEBAR  'ZTITLE'.
    ENDMODULE.                 " set_status  OUTPUT
    *&      Module  CHECK  INPUT
    * Modify the internal table using the current line in table control
    MODULE check INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
    ENDMODULE.                 " CHECK  INPUT

  • How to make copies of internal table with unknown structure?

    Dis is the detailed description of a problem i have and i
    tried all i can to solve it without satisfied results.
    I want to copy an internal table of a type defined in the
    ABAP program itself, not dictionary. I have a function
    that is supposed to accept the internal table as a
    parameter of type 'any table'. The function should create
    the new internal table using the field catalog of the
    passed 'any table' and then create a new internal table
    using "create_dynamic_table" and return the DATA pointer.
    If anyone knows how it is done pls help me out.
    I would like to get the field catalog of the following
    internal table automatically by using some sap function..
    TYPES:
    BEGIN OF MYTYPE,
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTYPE.
    DATA:
    IT_TABLE TYPE TABLE OF MYTABLE INITIAL SIZE 0.
    DATA:
    COPY_OF_IT_TABLE TYPE REF TO DATA.
    SELECT NAME AGE INTO TABLE IT_TABLE FROM S0MEZTABLE.
    PERFORM CREATECOPY USING IT_TABLE CHANGING COPY_OF_IT_TABLE.
    FORM CREATECOPY
      USING
        IT_TABLE <b>TYPE ANY TABLE</b>
      CHANGING
        COPY_OF_IT_TABLE TYPE REF TO DATA.
    <i>[ Here i would like to create a copy the passed
    internal table and return a reference to it. I donot want
    to refer to the same table passed. I guess the use of
    function CREATE_DYNAMIC_TABLE in the CL_ALV_TABLE_CREATE
    clss is required. ]</i>
    ENDFORM.

    Ravi,
    If all you want to do is to copy this into another table, why can't do something like this.
    TYPES:
    BEGIN OF MYTYPE,
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTYPE.
    DATA:
    IT_TABLE TYPE TABLE OF MYTABLE INITIAL SIZE 0.
    DATA: COPY_OF_IT_TABLE TYPE REF TO DATA.
    SELECT NAME AGE INTO TABLE IT_TABLE FROM S0MEZTABLE.
    FIELD-SYMBOLS : <FT_COPY_TABLE> TYPE ANY TABLE.
    Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE
    Exporting
    IT_FIELDCATALOG = T_FIELDCAT
    Importing
    EP_TABLE = COPY_OF_IT_TABLE
    ASSIGN COPY_OF_IT_TABLE->* TO <FT_COPY_TABLE>
    However, this is provided you already have a field catalog. Now in this case we have not created a field catalog. So, for that
    data : BEGIN OF MYTABLE OCCURS 0 WITH HEADER LINE
      NAME TYPE SOMEZTABLE-NAME,
      AGE TYPE SOMEZTABLE-AGE,
    END OF MYTABLE.
    Now, create the field catalog.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_BUFFER_ACTIVE              =
      I_STRUCTURE_NAME             =
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_BYPASSING_BUFFER           =
        I_INTERNAL_TABNAME           = 'MYTABLE'
      CHANGING
        CT_FIELDCAT                  = T_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE       = 1
      PROGRAM_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.
    This should create the field catalog.
    Regards,
    Ravi

  • How to Compare two Dates in java

    How to Compare two Date Field after getting the values from jTextField1.getText() and jTextField2.getText().

    Date d1=DateFormat.getDateInstance().parse(yourstring1);
    same for d2
    d1.compareTo(d2);
    could be that i misrememberd the exact naems of some functions or mixed up something in the equence of d1=

  • How to compare two dates that should not exceed morethan 3 years

    hi all,
    can you please tell me how to compare two dates( basically dates are string type)
    that should not exceed more than 3 years? in JAVASCRIPT
    Thanks in Advance.

    This is not a JavaScript forum.
    [*Google* JavaScript Forum|http://www.google.co.uk/search?q=JavaScript+Forum&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a]
    Good luck.

  • How to compare two dates to know which one is greater than oher?

    how to compare two dates to know which one is greater than oher?
    Please search before asking basic questions.
    Edited by: Rob Burbank on Mar 27, 2009 9:26 AM

    Hi,
    If thse to date fields are of same type u can directly compare like this.
    regards,
    Bharat.

  • How to retrieve multiple data from table and represent it in jsp page

    Hi
    The below JavaScript code is used to add row in the table when I want to add multiple row data into table for single entry no field.
      <html>  function addRow()
                i++;
                var newRow = document.all("tblGrid").insertRow();
                var oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='srno"+i+"' type='text' id='srno"+i+"' size=10>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='itmcd"+i+"' type='text' id='itmcd"+i+"' size='10'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='itmnm"+i+"' type='text' id='itmnm"+i+"' size='15'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='indentqty"+i+"' type='text' id='indentqty"+i+"' size='10'>";
                oCell = newRow.insertCell();
                    oCell.innerHTML = "<input name='uom"+i+"' type='text' id='uom"+i+"' size='10'><input type='hidden' name='mcode"+i+"'id='mcode"+i+"'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='packqty"+i+"' type='text' id='packqty"+i+"' size='10'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='packuom"+i+"' type='text' id='packuom"+i+"' size='10'><input type='hidden' name='pack"+i+"' id='pack"+i+"'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='rate"+i+"' type='text' id='rate"+i+"' size='10'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='dor"+i+"' type='text' id='dor"+i+"' size='0' onClick='"+putdate(this.name)+"'>";           
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='bccode"+i+"' type='text' id='bccode"+i+"' size='10'></td><input type='hidden' name='bcc"+i+"' id='bcc"+i+"'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='cccode"+i+"' type='text' id='cccode"+i+"' size='10'></td><input type='hidden' name='ccc"+i+"' id='ccc"+i+"'>";
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input name='remark2"+i+"' type='text' id='remark2"+i+"' size='20'>";           
                oCell = newRow.insertCell();
                oCell.innerHTML = "<input type='button' value='Delete' onclick='removeRow(this);' />";
               // oCell = newRow.insertCell();
               // oCell.innerHTML = "<input type='button' value='Clear' onclick='clearRow(this);' />";
            }<html>  Then this data are send to the next Servlet for adding into two table.
    My header portion data are added into one table which added only one row in table. while footer section data are added into the no of rows in another table dependent on No. of
    Rows added into jsp page.
    Here is an code for that logic.
    <html>
    ArrayList<String> mucode = new ArrayList<String>();
                                ArrayList<Integer> serials = new ArrayList<Integer>();
                                ArrayList<Integer> apxrate = new ArrayList<Integer>();
                                ArrayList<Integer> srname = new ArrayList<Integer>();
                                ArrayList<String> itcode = new ArrayList<String>();
                                ArrayList<String> itname = new ArrayList<String>();
                                ArrayList<Integer> iqnty = new ArrayList<Integer>();
                                ArrayList<String> iuom = new ArrayList<String>();
                                ArrayList<Integer> pqnty = new ArrayList<Integer>();
                                ArrayList<String> puom1 = new ArrayList<String>();
                               ArrayList<Integer> arate = new ArrayList<Integer>();
                                ArrayList<String> rdate = new ArrayList<String>();
                                ArrayList<String> bcs = new ArrayList<String>();
                                ArrayList<String> ccs = new ArrayList<String>();
                                ArrayList<String> remarkss = new ArrayList<String>();
                                //ArrayList<Integer> qtyrecs = new ArrayList<Integer>();
                                //ArrayList<String> dors = new ArrayList<String>();
                                //ArrayList<String> remarks = new ArrayList<String>();
                     String entryn = request.getParameter("entryno");       
                        String rows = request.getParameter("rows");
                        out.println(rows);  
                        //String Entryno = request.getParameter("entryno");
                       // out.println(Entryno);
                      int entryno = 0,reqqty = 0,srno = 0,deprequest = 0,rowcount = 0;
                                if(!Entryno.equals("")){
                                        entryno = Integer.valueOf(Entryno);
                                if(!rows.equals("")){
                                        rowcount = Integer.valueOf(rows);
                               for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("srno"+i)!=null){
                                                serials.add(Integer.valueOf(request.getParameter("srno"+i).trim()));
                                                out.println(serials.size());
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("srno"+i)!=null){
                                                srname.add(Integer.valueOf(request.getParameter("srno"+i).trim()));
                                out.println(srname.get(0));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("itmcd"+i)!=null){
                                                itcode.add(request.getParameter("itmcd"+i).trim());
                                        } //out.println(itcode.get(i));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("itmnm"+i)!=null){
                                                itname.add(request.getParameter("itmnm"+i).trim());
                                        }//out.println(itname.get(i));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("indentqty"+i)!=null){
                                                iqnty.add(Integer.valueOf(request.getParameter("indentqty"+i).trim()));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("uom"+i)!=null){
                                                iuom.add(request.getParameter("uom"+i).trim());
                                        }//out.println(iuom.get(i));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("mcode"+i)!=null){
                                                mucode.add(request.getParameter("mcode"+i).trim());
                               for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("packqty"+i).equals("")){
                                          pqnty.add(0);
                                        }else
                                            pqnty.add(Integer.valueOf(request.getParameter("packqty"+i).trim()));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("pack"+i)!=null){
                                                puom1.add(request.getParameter("pack"+i).trim());
                                       }else
                                        puom1.add("");
                               for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("rate"+i).equals("")){                                     
                                            arate.add(0);
                                        }else
                                        arate.add(Integer.valueOf(request.getParameter("rate"+i).trim()));   
                     /* for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("rate"+i)!=null){
                                                arate.add(Integer.valueOf(request.getParameter("rate"+i).trim()));
                              for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("dor"+i)!=null){
                                                try{
                                                        rdate.add(dashdate.format(slashdate.parse(request.getParameter("dor"+i).trim())));
                                                }catch(ParseException p){p.printStackTrace();}
                                        }else
                                           { rdate.add("");}
                                   for(int i=1;i<=rowcount;i++){
                                 if(request.getParameter("bcc"+i)!=null){
                                                bcs.add(request.getParameter("bcc"+i).trim());
                                        }out.println(bcs.get(0));
                                for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("ccc"+i)!=null){
                                                ccs.add(request.getParameter("ccc"+i).trim());
                                        }out.println(ccs.get(0));
                                for(int i=1;i<=rowcount;i++){
                                    out.println("remark2");
                                        if(request.getParameter("remark2"+i)!=null){
                                                remarkss.add(request.getParameter("remark2"+i).trim());
                                        }out.println(remarkss.get(0));
                        ArrayList<String> Idate = new ArrayList<String>();
                        for(int i=1;i<=rowcount;i++){
                                        if(request.getParameter("dateindent"+i)!=null){
                                                try{
                                                        Idate.add(dashdate.format(dashdate.parse(request.getParameter("dateindent"+i).trim())));
                                                }catch(ParseException p){p.printStackTrace();}
                    String Rdate = dashdate.format(new java.util.Date());
                     String tdate = dashdate.format(new java.util.Date());    
                     // String Indentdate = dashdate.format(new java.util.Date());
                   //  String ApprovedT1 = dashdate.format(new java.util.Date());
                   //  String ApprovedT2 = dashdate.format(new java.util.Date());
                       // String ApprovedT1=" ";
                        //String ApprovedT2="";*/
                    String ApprovedT1= dashdate.format(new java.util.Date());
                   out.println (ApprovedT1);
                      String ApprovedT2=dashdate.format(new java.util.Date());
                       out.println(ApprovedT2);
                    String Indentdate=(dashdate.format(slashdate.parse(request.getParameter("dateindent").trim())));
                       out.println(Indentdate);
                        String Cocode ="BML001";  
                        out.println(Cocode);
                        String Deptcode = request.getParameter("dept1");
                        out.println(Deptcode);
                        String Empcode = request.getParameter("emp");
                        out.println(Empcode);
                        String Refno =request.getParameter("rtype"); 
                         out.println(Refno);
                        String Divcode = request.getParameter("todiv1");
                        out.println(Divcode);
                        String Usercode = "CIRIUS";    
                         String Whcode = request.getParameter("stor");
                        out.println(Whcode);
                        // String Itemgroupcode = request.getParameter("");
                         String Itemgroupcode ="120000";
                         out.println(Itemgroupcode);
                        String Supplytypecode = request.getParameter("stype");
                        out.println(Supplytypecode);
                        String Delcode = request.getParameter("deliverycode");
                        out.println(Delcode);
                        String Itemclass="WS";
                        out.println(Itemclass);
                        // String Itemclass = request.getParameter("iclass");
                       // out.println(Itemclass);
                        String unitcode = request.getParameter("uni");
                        out.println(unitcode);
                         String Todivcode = request.getParameter("todiv1");
                        out.println(Todivcode);
                        String Appxrate = request.getParameter("rate");
                        out.println(Appxrate);
                        String Srno = request.getParameter("srno");
                        out.println(Srno);                
                    /*    String Indqty = request.getParameter("indentqty");
                      out.println(Indqty);*/
                  String Itemcode = request.getParameter("itmcd");
                       out.println(Itemcode);
                       String Othersp = request.getParameter("remark1");
                        out.println(Othersp);
                        String Reqdt = request.getParameter("dor");
                        out.println(Reqdt);
                        String Munitcode = request.getParameter("mcode");
                        out.println(Munitcode);
                        String Packqty = request.getParameter("packqty");
                        out.println(Packqty);               
                        String Packuom = request.getParameter("pack");
                        out.println(Packuom);
                        String Remark2 = request.getParameter("remark2");
                        out.println(Remark2);
                        String BC = request.getParameter("bcc");
                        out.println(BC);
                        String CC = request.getParameter("ccc");
                        out.println(CC);
                        try{
                            st=connection.createStatement();
                            connection.setAutoCommit(false);
                            String sql="INSERT INTO PTXNINDHDR(COCODE,DEPTCODE,EMPCODE,APPROVEDT1,APPROVEDT2,INDDT,ENTRYNO,REFNO,REMARKS,DIVCODE,USERCODE,WHCODE,ITEMGROUPCODE,SUPTYPECODE,DELCODE,UNITCODE,TODIVCODE,ITEMCLASS)VALUES('"+Cocode+"','"+Deptcode+"','"+Empcode+"','"+ApprovedT1+"','"+ApprovedT2+"','"+Indentdate+"',"+Entryno+",'"+Refno+"','"+Othersp+"','"+Divcode+"','"+Usercode+"','"+Whcode+"','"+Itemgroupcode+"','"+Supplytypecode+"','"+Delcode+"','"+unitcode+"','"+Todivcode+"','"+Itemclass+"')";
                            out.println(sql);
                            st.addBatch(sql);
                            for(int i=0;i<serials.size();i++){
                                out.println("Inside the Statement");
                                String query3="test query for u";
                                out.println(query3);
                               String queryx="Insert into PTXNINDDTL(APXRATE,ENTRYNO,BRKNO,INDQTY,ITEMCODE,OTHERSPFCS,MUNITCODE,PACKQTY,PACKUOM,REMARKS,DIMSUBGRPCODE,DIMCODE,REQDT)VALUES("+arate.get(i)+","+entryno+","+srname.get(i)+","+iqnty.get(i)+","+itcode.get(i)+",'"+Othersp+"','"+mucode.get(i)+"',"+pqnty.get(i)+",'"+puom1.get(i)+"','"+remarkss.get(i)+"','"+bcs.get(i)+"','"+ccs.get(i)+"','"+rdate.get(i)+"')";
                               out.println(queryx);
                                st.addBatch(queryx);
                           int[] result=st.executeBatch();
                           connection.commit();
                           for(int k=0;k<result.length;k++)
                           out.println("rows updated by "+(k+1)+"insert sta:"+result[k]+"");
                        catch(BatchUpdateException bue)
                        out.println("error1;"+bue+"");
                        catch(SQLException sql)
                        out.println("error2;"+sql+"");
                        catch(Exception l)
                        out.println("error3;"+l+"");
    </html>
       Now I looking for to retrieve this footer section data available in multiple rows from footer table and present it in jsp page .
    I am finding difficulties in how to show this multiple row data for dynamic no of rows .i.e. variable no. of rows.
    I have able to show the data in Header portions of page in this ways
    here i am adding the part of code which shows the data from header part of table i.e from Header table
      <html>
    <h2 align="center"><b>Indent Preparation</b></h2>
        <div align="left">
            <table width="849" border="0" cellspacing="3" cellpadding="3" align="center">
                <tr>
                    <td ><div align="left"><b>Indent No.</b></div></td>
                    <td ><label>
                            <input name="indentno" type="text" id="indentno" size="15" value="" /><input type="hidden" name="no" id="no">
                    </label></td>
                    <td ><div align="center"><strong>Indent Date</strong></div></td>
                    <td ><label>
                            <div align="center">
                                <input name="dateindent" type="text" id="dateindent"value="<%=date1%>"/><input type="hidden" name="no" id="no">
                            </div>
                    </label></td>
                    <td> </td>
                    <td><div align="right"><strong>Entry No.</strong></div></td>
                     <%if(oper!=null && oper.equals("view") && hdrcode!=null && hdrdetails!=null){%>
            <td><input type="text" value="<%=hdrcode.get(3)%>" size="10"></td>
    <%}else{%>
                   <td><input type="text" name="entryno" id="entryno" value="<%=entryNo%>"/></td>
                             <%}%>
                            <div align="right"></div>
                </tr>
                <tr>
                    <td><b>Division</b></td>
                    <%if(oper!=null && oper.equals("view") && hdrcode!=null && hdrdetails!=null){%>
    <td><input type="text" value="<%=hdrdetails.get(9)%>" size="20"</td>
    <td><input type="hidden" name="div1" id="div1" value='<%=hdrcode.get(10)%>'></td>
    <%}else{%>
                   <td><input type="text" name="div" id="div" /></td>
                   <td><input type="hidden" name="div1" id="div1" /> </td>
              <%}%>
                    <td> </td>
                    <td> </td>
                    <td><div align="right"><strong>Unit</strong></div></td>
                   <%if(oper!=null && oper.equals("view") && hdrcode!=null && hdrdetails!=null){%>
    <td><input type="text" value="<%=hdrdetails.get(14)%>" size="20"</td>
    <td><input type="hidden" name="uni" id="uni" value='<%=hdrcode.get(12)%>'></td>
    <%}else{%>
                   <td><input type="text" name="unit" id="unit" /></td>
                   <td><input type="hidden" name="uni" id="uni" /> </td>
              <%}%>
                </tr>
                <tr>
    </html>
      Any suggestion on any above works is highly appreciated.
    Thanks and regards
    harshal

    Too much code. It's also not well intented nor formatted. I don't see a question either or it got lost in that heap of unformatted code.
    I will only answer the question in the thread's subject:
    How to retrieve multiple data from table and represent it in jsp pageTo retrieve, make use of HttpServletRequest#getParameterValues() and/or #getParameter().
    To display, make use of JSTL's c:forEach.

  • How can i export the data to excel which has 2 tables with same number of columns & column names?

    Hi everyone, again landed up with a problem.
    After trying a lot to do it myself, finally decided to post here..
    I have created a form in form builder 6i, in which on clicking a button the data gets exported to excel sheet.
    It is working fine with a single table. The problem now is that i am unable to do the same with 2 tables.
    Because both the tables have same number of columns & column names.
    Below are 2 tables with column names:
    Table-1 (MONTHLY_PART_1)
    Table-2 (MONTHLY_PART_2)
    SL_NO
    SL_NO
    COMP
    COMP
    DUE_DATE
    DUE_DATE
    U-1
    U-1
    U-2
    U-2
    U-4
    U-4
    U-20
    U-20
    U-25
    U-25
    Since both the tables have same column names, I'm getting the following error :
    Error 402 at line 103, column 4
      alias required in SELECT list of cursor to avoid duplicate column names.
    So How can i export the data to excel which has 2 tables with same number of columns & column names?
    Should i paste the code? Should i post this query in 'SQL and PL/SQL' Forum?
    Help me with this please.
    Thank You.

    You'll have to *alias* your columns, not prefix it with the table names:
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id, b.id, a.val1, b.val1, a.val2, b.val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
      for rData in cData loop
    ERROR at line 18:
    ORA-06550: line 18, column 3:
    PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
    ORA-06550: line 18, column 3:
    PL/SQL: Statement ignored
    $[CHE_TEST@asterix1_impl] r
      1  declare
      2    cursor cData is
      3      with data as (
      4        select 1 id, 'test1' val1, 'a' val2 from dual
      5        union all
      6        select 1 id, '1test' val1, 'b' val2 from dual
      7        union all
      8        select 2 id, 'test2' val1, 'a' val2 from dual
      9        union all
    10        select 2 id, '2test' val1, 'b' val2 from dual
    11      )
    12      select a.id a_id, b.id b_id, a.val1 a_val1, b.val1 b_val1, a.val2 a_val2, b.val2 b_val2
    13      from data a, data b
    14      where a.id = b.id
    15      and a.val2 = 'a'
    16      and b.val2 = 'b';
    17  begin
    18    for rData in cData loop
    19      null;
    20    end loop;
    21* end;
    PL/SQL procedure successfully completed.
    cheers

  • How do you delete records from table with data in a select option

    how do you delete records from table with relevant to data in a select option..how to write coding

    Hi,
    Try
    if not s_select_option [ ] is initial.
    delete * from table
    where field in s_select_option.
    endif.
    commit work.
    Be careful though. If select option is emty, you will delete the entire table.
    Regards,
    Arek

  • Create data base table with EXEC SQL

    Hello,
    I nead to create o data base table with EXEC SQL in an Abap program.
    My code is :
    TRY.
       EXEC SQL.
          CREATE table zt_hello ( mandt char(4) NOT NULL,
                                  kunnr char(10) NOT NULL,
                                  PRIMARY KEY (mandt, kunnr) )
        ENDEXEC.
      CATCH cx_sy_native_sql_error INTO exc_ref.
        error_text = exc_ref->get_text( ).
    ENDTRY.
    IF sy-subrc = 0.
      COMMIT WORK.
    ENDIF.
    But it still not working.
    Can you help me please.
    Thanks.
    Edited by: widad soubhi on Jul 14, 2010 5:26 PM

    Please refer this code
    REPORT z_struct_create .
    DATA: my_row(500) TYPE c,
    my_file_1 LIKE my_row OCCURS 0 WITH HEADER LINE.
    DATA: dd02v TYPE dd02v.
    DATA: my_file_tab1 LIKE dd03p OCCURS 0 WITH HEADER LINE.
    SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text
    NO INTERVALS.
    PARAMETERS:
    name TYPE ddobjname,
    testo TYPE text40,
    file_1 LIKE rlgrap-filename.
    SELECTION-SCREEN SKIP.
    SELECTION-SCREEN END OF BLOCK blk.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR file_1.
    PERFORM file_selection USING file_1.
    INITIALIZATION.
    text = text-001.
    START-OF-SELECTION.
    IF file_1 IS INITIAL.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 001.
    EXIT.
    ENDIF.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = file_1
    filetype = 'ASC'
    TABLES
    data_tab = my_file_1.
    IF sy-subrc 0.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 002.
    EXIT.
    ENDIF.
    LOOP AT my_file_1.
    IF sy-tabix > 1.
    CLEAR my_file_tab1.
    SPLIT my_file_1 AT ';' INTO
    my_file_tab1-fieldname
    my_file_tab1-datatype
    my_file_tab1-leng
    my_file_tab1-decimals
    my_file_tab1-ddtext
    my_file_tab1-inttype = 'C'.
    my_file_tab1-INTLEN = my_file_tab1-leng.
    my_file_tab1-tabname = name.
    my_file_tab1-position = sy-tabix - 1.
    my_file_tab1-ddlanguage = sy-langu.
    my_file_tab1-OUTPUTLEN = my_file_tab1-leng.
    APPEND my_file_tab1.
    ENDIF.
    ENDLOOP.
    dd02v-tabname = name.
    dd02v-ddlanguage = sy-langu.
    dd02v-tabclass = 'INTTAB'.
    dd02v-DDTEXT = testo.
    dd02v-MASTERLANG = sy-langu.
    IF NOT my_file_tab1[] IS INITIAL.
    CALL FUNCTION 'DDIF_TABL_PUT'
    EXPORTING
    name = name
    dd02v_wa = dd02v
    TABLES
    dd03p_tab = my_file_tab1
    EXCEPTIONS
    tabl_not_found = 1
    name_inconsistent = 2
    tabl_inconsistent = 3
    put_failure = 4
    put_refused = 5
    OTHERS = 6
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ELSE.
    MESSAGE ID 'Z0017_BDI' TYPE 'I' NUMBER 003.
    EXIT.
    ENDIF.
    *& Form file_selection
    -->P_FILE_1 text
    FORM file_selection USING p_file.
    CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
    def_filename = ''
    def_path = 'c:\'
    mask = ',.,..'
    mode = '0'
    title = 'Selezione file'
    IMPORTING
    filename = p_file
    RC = RCODE
    EXCEPTIONS
    inv_winsys = 1
    no_batch = 2
    selection_cancel = 3
    selection_error = 4
    OTHERS = 5.
    ENDFORM. " file_selection
    File Template:
    Fieldname;Data Type;Lentgh;Dec.;Descr.
    FIELD1;CHAR;000020;000000;my field 1
    FIELD2;CHAR;000008;000000;my field 2
    FIELD3;CHAR;000007;000000;my field 3
    FIELD4;CHAR;000006;000000;my field 4

  • SSIS 2012 is intermittently failing with below "Invalid date format" while importing data from a source table into a Destination table with same exact schema.

    We migrated Packages from SSIS 2008 to 2012. The Package is working fine in all the environments except in one of our environment.
    SSIS 2012 is intermittently failing with below error while importing data from a source table into a Destination table with same exact schema.
    Error: 2014-01-28 15:52:05.19
       Code: 0x80004005
       Source: xxxxxxxx SSIS.Pipeline
       Description: Unspecified error
    End Error
    Error: 2014-01-28 15:52:05.19
       Code: 0xC0202009
       Source: Process xxxxxx Load TableName [48]
       Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
    An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Invalid date format".
    End Error
    Error: 2014-01-28 15:52:05.19
       Code: 0xC020901C
       Source: Process xxxxxxxx Load TableName [48]
       Description: There was an error with Load TableName.Inputs[OLE DB Destination Input].Columns[Updated] on Load TableName.Inputs[OLE DB Destination Input]. The column status returned was: "Conversion failed because the data value overflowed
    the specified type.".
    End Error
    But when we reorder the column in "Updated" in Destination table, the package is importing data successfully.
    This looks like bug to me, Any suggestion?

    Hi Mohideen,
    Based on my research, the issue might be related to one of the following factors:
    Memory pressure. Check there is a memory challenge when the issue occurs. In addition, if the package runs in 32-bit runtime on the specific server, use the 64-bit runtime instead.
    A known issue with SQL Native Client. As a workaround, use .NET data provider instead of SNAC.
    Hope this helps.
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • How to encrypt column of some table with the single method ?

    How to encrypt column of some table with the single method ?

    How to encrypt column of some table with the single
    method ?How to encrypt column of some table with the single
    method ?
    using dbms_crypto package
    Assumption: TE is a user in oracle 10g
    we have a table need encrypt a column, this column SYSDBA can not look at, it's credit card number.
    tha table is
    SQL> desc TE.temp_sales
    Name Null? Type
    CUST_CREDIT_ID NOT NULL NUMBER
    CARD_TYPE VARCHAR2(10)
    CARD_NUMBER NUMBER
    EXPIRY_DATE DATE
    CUST_ID NUMBER
    1. grant execute on dbms_crypto to te;
    2. Create a table with a encrypted columns
    SQL> CREATE TABLE te.customer_credit_info(
    2 cust_credit_id number
    3      CONSTRAINT pk_te_cust_cred PRIMARY KEY
    4      USING INDEX TABLESPACE indx
    5      enable validate,
    6 card_type varchar2(10)
    7      constraint te_cust_cred_type_chk check ( upper(card_type) in ('DINERS','AMEX','VISA','MC') ),
    8 card_number blob,
    9 expiry_date date,
    10 cust_id number
    11      constraint fk_te_cust_credit_to_cust references te.customer(cust_id) deferrable
    12 )
    13 storage (initial 50k next 50k pctincrease 0 minextents 1 maxextents 50)
    14 tablespace userdata_Lm;
    Table created.
    SQL> CREATE SEQUENCE te.customers_cred_info_id
    2 START WITH 1
    3 INCREMENT BY 1
    4 NOCACHE
    5 NOCYCLE;
    Sequence created.
    Note: Credit card number is blob data type. It will be encrypted.
    3. Loading data encrypt the credit card number
    truncate table TE.customer_credit_info;
    DECLARE
    input_string VARCHAR2(16) := '';
    raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    key_string VARCHAR2(8) := 'AsDf!2#4';
    raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(key_string,'AL32UTF8','US7ASCII'));
    encrypted_raw RAW(2048);
    encrypted_string VARCHAR2(2048);
    BEGIN
    for cred_record in (select upper(CREDIT_CARD) as CREDIT_CARD,
    CREDIT_CARD_EXP_DATE,
    to_char(CREDIT_CARD_NUMBER) as CREDIT_CARD_NUMBER,
    CUST_ID
    from TE.temp_sales) loop
    dbms_output.put_line('type:' || cred_record.credit_card || 'exp_date:' || cred_record.CREDIT_CARD_EXP_DATE);
    dbms_output.put_line('number:' || cred_record.CREDIT_CARD_NUMBER);
    input_string := cred_record.CREDIT_CARD_NUMBER;
    raw_input := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    dbms_output.put_line('> Input String: ' || CONVERT(UTL_RAW.CAST_TO_VARCHAR2(raw_input),'US7ASCII','AL32UTF8'));
    encrypted_raw := dbms_crypto.Encrypt(
    src => raw_input,
    typ => DBMS_CRYPTO.DES_CBC_PKCS5,
    key => raw_key);
    encrypted_string := rawtohex(UTL_RAW.CAST_TO_RAW(encrypted_raw)) ;
    dbms_output.put_line('> Encrypted hex value : ' || encrypted_string );
    insert into TE.customer_credit_info values
    (TE.customers_cred_info_id.nextval,
    cred_record.credit_card,
    encrypted_raw,
    cred_record.CREDIT_CARD_EXP_DATE,
    cred_record.CUST_ID);
    end loop;
    commit;
    end;
    4. Check credit card number script
    DECLARE
    input_string VARCHAR2(16) := '';
    raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    key_string VARCHAR2(8) := 'AsDf!2#4';
    raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(key_string,'AL32UTF8','US7ASCII'));
    encrypted_raw RAW(2048);
    encrypted_string VARCHAR2(2048);
    decrypted_raw RAW(2048);
    decrypted_string VARCHAR2(2048);
    cursor cursor_cust_cred is select CUST_CREDIT_ID, CARD_TYPE, CARD_NUMBER, EXPIRY_DATE, CUST_ID
    from TE.customer_credit_info order by CUST_CREDIT_ID;
    v_id customer_credit_info.CUST_CREDIT_ID%type;
    v_type customer_credit_info.CARD_TYPE%type;
    v_EXPIRY_DATE customer_credit_info.EXPIRY_DATE%type;
    v_CUST_ID customer_credit_info.CUST_ID%type;
    BEGIN
    dbms_output.put_line('ID Type Number Expiry_date cust_id');
    dbms_output.put_line('-----------------------------------------------------');
    open cursor_cust_cred;
    loop
         fetch cursor_cust_cred into v_id, v_type, encrypted_raw, v_expiry_date, v_cust_id;
    exit when cursor_cust_cred%notfound;
    decrypted_raw := dbms_crypto.Decrypt(
    src => encrypted_raw,
    typ => DBMS_CRYPTO.DES_CBC_PKCS5,
    key => raw_key);
    decrypted_string := CONVERT(UTL_RAW.CAST_TO_VARCHAR2(decrypted_raw),'US7ASCII','AL32UTF8');
    dbms_output.put_line(V_ID ||' ' ||
    V_TYPE ||' ' ||
    decrypted_string || ' ' ||
    v_EXPIRY_DATE || ' ' ||
    v_CUST_ID);
    end loop;
    close cursor_cust_cred;
    commit;
    end;
    /

Maybe you are looking for