Selective excel table import/export

I need to run an SQL script that will selectively (select * from <TABLE> where <"TransactionRunDate" older than 6 months from SystemDate>) remove all rows from three table and simultaneously write them into excel sheets. Then, I need an SQL script that can restore the data from these Excel tables into the Oracle tables (on demand)
How can I do this without right clicking import/export on the GUI (SQLDeveloper), but with SQL script alone?
Edited by: user10403078 on Oct 7, 2008 11:32 PM

I would half agree with daniel and half not agree.
You can't but you can. As for whether you should is a different matter.
I say you can because it's possible to do something like you are looking for. You could even get it to write out Excel workbooks with worksheets using Microsofts office XML format and then use an ODBC connection to read the data back again into an Oracle database using Heterogeneous services, but it's complicated and not easily demonstrated with what little time I have.
However, an alternative is to write the data out to CSV files and then use External tables to read those CSV files back again. Example...
Firstly, here's my table with some data in it, some of which is more than 6 months old...
SQL> select * from table1;
        ID CREATED_DATE        TXT
         1 13/12/2007 09:31:08 Old Fred
         2 01/02/2008 09:31:08 Old Bob
         3 22/03/2008 09:31:08 Old Jim
         4 11/05/2008 09:31:08 Young Fred
         5 30/06/2008 09:31:08 Young Bob
         6 19/08/2008 09:31:08 Young Jim
         7 08/10/2008 09:31:08 New Me
7 rows selected.Now, I create a DELETE trigger on that table so if any rows are deleted this will fire. To allow for rows less than 6 months old to be deleted without being archived to file I put a check in the trigger too...
SQL> ed
Wrote file afiedt.buf
  1  create or replace trigger trg_del
  2  after delete on table1
  3  for each row
  4  declare
  5    v_dir  VARCHAR2(30) := 'TEST_DIR';
  6    v_file VARCHAR2(30) := 'table1_archive.csv';
  7    v_fh   UTL_FILE.FILE_TYPE;
  8  begin
  9    IF months_between(sysdate, :OLD.created_date) >= 6 THEN
10      -- Only archive a deleted row if it's greater than 6 months old
11      v_fh := UTL_FILE.FOPEN(v_dir, v_file, 'a', 32767);
12      UTL_FILE.PUT_LINE(v_fh, TO_CHAR(:OLD.ID,'fm9999')||','||TO_CHAR(:OLD.CREATED_DATE,'YYYYMMDDHH24MISS')||',"'||:OLD.TXT||'"');
13      UTL_FILE.FCLOSE(v_fh);
14    END IF;
15* end;
SQL> /
Trigger created.So now, I have a trigger that will write deleted rows of data out in CSV format to a file called table1_archive.csv.
Now I can create an external table that can read that CSV file...
SQL> ed
Wrote file afiedt.buf
  1  CREATE TABLE table1_archive (
  2         id            NUMBER,
  3         created_date  DATE,
  4         txt           VARCHAR(200)
  5         )
  6  ORGANIZATION EXTERNAL (
  7    TYPE oracle_loader
  8    DEFAULT DIRECTORY TEST_DIR
  9      ACCESS PARAMETERS (
10      RECORDS DELIMITED BY NEWLINE
11      BADFILE 'bad_%a_%p.bad'
12      LOGFILE 'log_%a_%p.log'
13      FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
14      MISSING FIELD VALUES ARE NULL
15      REJECT ROWS WITH ALL NULL FIELDS
16        (id
17        ,created_date date "yyyymmddhh24miss"
18        ,txt)
19      )
20      LOCATION ('table1_archive.csv')
21    )
22  PARALLEL
23  REJECT LIMIT 0
24* NOMONITORING
SQL> /
Table created.
{code}
And now we can prove it works...
Firstly, delete rows from the table that are 6 months or more old...
{code}
SQL> delete from table1
  2  where months_between(sysdate, created_date) >= 6;
3 rows deleted.
SQL> select * from table1;
        ID CREATED_DATE        TXT
         4 11/05/2008 09:31:08 Young Fred
         5 30/06/2008 09:31:08 Young Bob
         6 19/08/2008 09:31:08 Young Jim
         7 08/10/2008 09:31:08 New Me
{code}
So those rows have been deleted, now let's check they're in the archive CSV file...
{code}
SQL> select * from table1_archive;
        ID CREATED_DATE        TXT
         1 13/12/2007 09:31:08 Old Fred
         2 01/02/2008 09:31:08 Old Bob
         3 22/03/2008 09:31:08 Old Jim
SQL>
{code}
There they are, and that CSV file can also be read by Excel if required.
Let's just check that we don't archive rows that are deleted if they are less than 6 months old...
{code}
SQL> delete from table1 where id = 6;
1 row deleted.
SQL> select * from table1;
        ID CREATED_DATE        TXT
         4 11/05/2008 09:31:08 Young Fred
         5 30/06/2008 09:31:08 Young Bob
         7 08/10/2008 09:31:08 New Me
SQL> select * from table1_archive;
        ID CREATED_DATE        TXT
         1 13/12/2007 09:31:08 Old Fred
         2 01/02/2008 09:31:08 Old Bob
         3 22/03/2008 09:31:08 Old Jim
SQL>
{code}
So that row was deleted without being archived.  Just what I intended.

Similar Messages

  • Place EXCEL table

    Hi. I use this code to test excel table import in Indesign.
    The table is imported correctly but without any preferences.
    Any help?
    REM LOAD FILE FROM FILE
    file_indd= "C:\test.indd"
    REM from samples
    Function myGetBounds(myDocument, myPage)
      idRightHand = &H72677468
      idLeftHand = &H6C667468
      idSingleSided = &H75736578
      myPageWidth = myDocument.documentPreferences.pageWidth
      myPageHeight = myDocument.documentPreferences.pageHeight
      If myPage.Side = idLeftHand Then
        myX2 = myPage.marginPreferences.Left
        myX1 = myPage.marginPreferences.Right
      Else
        myX1 = myPage.marginPreferences.Left
        myX2 = myPage.marginPreferences.Right
      End If
      myX2 = myPageWidth - myX2
      myY1 = myPage.marginPreferences.Top
      myY2 = myPageHeight - myPage.marginPreferences.bottom
      myGetBounds = Array(myY1, myX1, myY2, myX2)
    End Function
    REM OPEN Indesign
    Set myInDesign = CreateObject("InDesign.Application.CS3")
    myInDesign.ScriptPreferences.UserInteractionLevel = &H654E7672
    myInDesign.ScriptPreferences.EnableRedraw = False              
    REM LOA Ddocument
    Set myDocument = myInDesign.Open( file_indd , true)
    REM Set myDocument = myInDesign.ActiveDocument
    Rem Sets the Excel import filter preferences.
    With myInDesign.ExcelImportPreferences
        Rem alignmentStyle property can be:
        idSpreadsheet = &H73707273
        idLeftAlign = &H6C656674
        idRightAlign = &H72676874
        idCenterAlign= &H63656E74
        REM
        AlignmentStyle = idSpreadsheet
        DecimalPlaces = 4
        PreserveGraphics = False
        REM Enter the range you want to import as "start cell:end cell".
        RangeName = "A1:B3"
        SheetIndex = 1
        SheetName = ""
        ShowHiddenCells = False
        REM tableFormatting property can be:
        idExcelFormattedTable = &H786C4654
        idExcelUnformattedTable = &H786C5554
        idExcelUnformattedTabbedText = &H78555454
        REM
        TableFormatting = idExcelFormattedTable
        UseTypographersQuotes = True
        ViewName = ""
    End With                                          
    REM Create a text frame.
    Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
    myTextFrame.geometricBounds = myGetBounds(myDocument, myDocument.Pages.Item(1))
    REM PLACE EXCEL FILE
    myTextFrame.Place("C:\test.xls")

    Can anybody try the scritp on windows machine (vbscript) to see if is a problem only with my Pc?
    Thanks

  • Excel Import/Export in RulesManager ?

    Hi ,
    We do have Excel import/Export feature at Designtime. Do we have same feature at runtime in RulesManager also ?
    Regards, Anil

    Hi Anil
    Currently Import/Export of Decision Table to Excel sheet is not available in CE 7.2. However, this is available from the 7.3 release.
    Regards
    Harsh

  • Howto import XML into Excel table ?

    Hi,
    I asked this before in the Excel forums but received the suggestion that I ask here instead.  The question precis : How to ungrey the "Append new data to existing XML lists" checkbox so I can select it when importing XML data into an Excel
    spreadsheet.
    I have a local server which provides data in XML form and need to import successive reloads of the XML page into successive lines in an Excel spreadsheet.  I found the Excel help page entitled "How to use XML in Excel 2003" at http://office.microsoft.com/en-gb/excel-help/how-to-use-xml-in-excel-2003-HA001101964.aspx?CTT=1&origin=EC001022986
    which was useful in so far as permitting me to import the data using the XML Source task pane and mapping the elements I need from the XML source to columns in the spreadsheet.
    In order to append successive lines from the XML source page, as I understand it from the link I quoted,  I need to change the XML Map properties to "Append new data to existing XML lists".  However this checkbox is greyed out in the
    XML Map properties dialog box so I can't select it.
    Any ideas how I can achieve my aims here ?
    Thanks in advance,
    Mike

    Hi Mike,
    Thank you for contacting Office IT Pro General Discussions Services. 
    From your description, I understand that you tried to import XML into Excel table. You selected “Use the XML Source
    task pane” when opening the XML file, then you tried to check the option in the
    Map Properties window: "Append new data to existing XML lists". 
    However, this option is grayed out. If there is any misunderstanding, please feel free to let me know.
    I have checked the issue on my side but could not reproduce this issue. I suggest download the sample XML file as suggested on the page and test the
    issue again:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=B4BD3283-AD0B-408D-9CE7-AB9C3537BBBB&displaylang=en
    If the problem does not occur with the sample XML file, this issue might occur as there are some problems with the XML you were using.
    If the problem also occurs in with the sample XML file, this issue might be related to some third-party software conflicts. I suggest checking this
    issue by starting Excel in the safe mode.
    Start the Office program in safe mode
    ==============
    1.      
    Click Start, point to All Programs, and then point to
    Microsoft Office.
    2.       
    Press and hold the CTRL key, and then click
    Microsoft Excel.
    If the problem does not occur in the safe mode, this issue might be related to some third-party add-ins in the Excel program, we can try to disable
    them. Normally, you could do the following to disable the conflict add-ins in your Excel program:
    Disable add-ins
    Click
    Tools > Options > 
    Add-in, click Go button in the Manage:
    Com-in Add.
    Check if there are any add-ins,
    clear the checkbox to disable them.
    Close the Office program and
    restart it.
    Add one check back each time to the list of Add-In,
    restart the Office program, and repeat the above procedure. Once the issue reappears again, we can determine which add-in causes this problem and then disable it.
    Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything
    I can do for you, please feel free to let me know.
    Best Regards,
    Sally Tang

  • Import & Export of Internal table

    Hello All,
    In my requirement I need to call the MB5B program RM07MLBD. I used the code like this.
    SUBMIT rm07mlbd AND RETURN
                WITH matnr   IN  so_matnr
                WITH werks   IN  so_werks
                WITH datum   IN  so_budat.
    Now from the RM07MLBD program I need the get the values of the table * g_t_totals_flat * to my zprogram.
    Is it possible to import & export the Internal table from one program to other.
    Regards,
    Anil.

    Hi,
    You can export the internal table ot memory id and can access the (Import) in the called program.
    Consider this small code from ABAPDOCU.
    DATA text1(10) TYPE c VALUE 'Exporting'.
    DATA: itab TYPE TABLE OF sbook,
          wa_itab LIKE LINE OF itab.
    DO 5 TIMES.
      wa_itab-bookid = 100 + sy-index.
      APPEND wa_itab TO itab.
    ENDDO.
    EXPORT text1
           text2 = 'Literal'
      TO MEMORY ID 'text'.
    EXPORT itab
      TO MEMORY ID 'table'.
    Regards
    Bikas

  • Export Excel Table in .txt File with space delimited text in UNICODE Format

    Hi all
    I've a big unsolved problem: I would like to convert an Excel table with some laboratory data in it (descriptions as text, numbers, variables with some GREEK LETTERS, ...). The output should be a formatted text with a clear structure. A very good solution is
    given by the converter in Excel "Save As" .prn File. All works fine, the formattation is perfect (it does not matter if some parts are cutted because are too long), but unfortunately the greek letters are converted into "?"!!!
    I've tried to convert my .xlsx File in .txt File with formatting Unicode and the greek letters are still there! But in this case the format is not good, the structure of a table is gone!
    Do you know how to save an Excel file in .prn but with Unicode formatting instead of ANSI or a .txt with space delimited text?
    Thanks a lot to everyone that can help me!
    M.L.C.

    This solution works in Excel/Access 2013.
    Link the Excel table into Access.
    In Access, right-click the linked table in the Navigation Pane, point your mouse cursor to "Export", and then choose "Text File" in the sub-menu.
    Name the file, and then under "Specify export options", check "Export data with formatting and layout".  Click "OK".
    Choose either Unicode or Unicode (UTF-8) encoding.  Click "OK".
    Click "Close" to complete the export operation.

  • ABAP for Super Dumps: Import- & Export-Parameter for a Table in a FM

    Hello ABAP Profs,
    sorry I am BW.
    <b>Import- & Export-Parameter for a Table in and out of an Function Modul.</b>
    I want to import a table into a Function Module, change it and export it again.
    How do I have to define the Import- and Export- Parameters in the FM ?
    The table looks looks this:
    DATA: zvpshub_tab TYPE SORTED TABLE OF /bic/pzvpshub WITH UNIQUE KEY
    /bic/zvpshub objvers /bic/zvpsoursy INITIAL SIZE 0.
    Thanks a lot
    Martin Sautter

    Hi Clemens,
    <u>in SE11</u> I defined a datatype of Type Structure: ZVPSHUB_ROW.
    <u>in SE11</u> I defiend a datatype of Type Tabletype: ZVPSHUB_TAB,
    bases on Rowtype ZVPSHUB_ROW.
    <u>in SE 80</u> I creates an FM with a CHANGEING Parameter referencing ZVPSHUB_TAB:
    FUNCTION ZVP_SHUB_TAB_LOAD.
    ""Lokale Schnittstelle:
    *"  CHANGING
    *"     VALUE(SHUB_TAB) TYPE  ZVPSHUB_TAB
    <u>in RSA1</u> in BW in the Startroutine of the Upload Rules in defined the table:
    DATA:shub_tab          TYPE zvpshub_tab.
    <u>in RSA1</u> in BW in the Startroutine of the Upload Rules in defined the table:
    DATA:shub_tab          TYPE zvpshub_tab.
    <u>in RSA1</u> in BW in the Startroutine i called the FM
    CALL FUNCTION 'ZVP_SHUB_TAB_LOAD'
        CHANGING
          shub_tab = shub_tab.
    and it works ..
    Thank You
    Martin Sautter

  • Leading zeros are not carried from the pivot table to exported Excel (9927815)

    Hello All -
    I am just wondering if there is a fix available for -- Leading zeros are not carried from the pivot table to exported Excel (9927815)
    can anybody suggest when it will be fixed and if there is any-workaround for this issue if there is no fix available.
    Thanks
    Ram

    Thanks Timo -
    Studio Edition Version 11.1.1.2.0
    About
    Oracle JDeveloper 11g Release 1 11.1.1.2.0
    Studio Edition Version 11.1.1.2.0
    Build JDEVADF_11.1.1.2.0_GENERIC_091029.2229.5536
    Copyright © 1997, 2009 Oracle and/or its affiliates. All rights reserved.
    IDE Version: 11.1.1.2.36.55.36
    Product ID: oracle.jdeveloper
    Product Version: 11.1.1.2.36.55.36
    I will check on support.oracle.com

  • VBA and RFC - How to deal with tables in export/import parameters

    Hi,
    maybe one of you can support me...
    I have a couple of vba modules reading and writing data to SAP by means of function modules. As usual, they use export and import parameters as well as tables (in the table section). They work very well.
    Now, I want to execute some newer function modules and they don't use tables in the table section (because they're obsolete nowadays), instead they expect the tables as export resp. import parameters. I tried it in a couple of ways, without any success.
    Has anybody tried this before? And if so, do you mind share some snippets?
    Best regards, Thomas

    Hello Thomas,
    I think we discussed the same problem here, but unfortunately without any result. Please, take a look at this post and let us know.
    Cheers
    Stefan

  • Another question about import/export to excel file?

    Hi, I need to know urgently if it's possible to import/export excel files from/to JSP with unpredicted number of fields each row. For example, row 1 in the excel file can have 5 columns of data, row 2 has 3 columns of data, etc...
    Does reading from excel file in JSP require that we know beforehand how many columns there are and what each column represent?

    go read http://jakarta.apache.org/poi !!!!!!
    No it doesnt. the POI api provide method to determine the number of cells in a row.

  • Import export internal table

    Hi.
    How can i make an import export of an internal table but with the sap memory.
    Thanks.
    Regards
    Miguel

    If the number of entries in table is less following logic could be used..
    Suppose wa_tab is the work area and lit_tab is the table that you need to import and export into lit_new.
    DATA : lv_count_char TYPE CHAR3,
                lv_field TYPE char6.
    DESCRIBE TBALE lit_tab LINES lv_lines.
    SET PARAMETER ID 'LINES' FIELD lv_lines.
    ---> Setting the value
    LOOP at lit_tab INTo wa_tab.
    MOVE sy-tabix TO lv_count_char.
    CONCATENATE 'FLD' lv_count_char INTO lv_field.
    SET PARAMETER ID lv_field FIELD wa_tab.
    ENDLOOP.
    ---> Rerieving the value
    GET PARAMETER ID 'LINES' FIELD lv_lines.
    DO.
    lv_count = lv_count + 1.
    MOVE lv_count TO lv_count_char.
    CONCATENATE 'FLD' lv_count_char INTO lv_field.
    GET PARAMETER ID lv_field FIELD wa_tab.
    APPEND wa_tab TO lit_new.
    IF lv_count GE lv_lines.
    EXIT.
    ENDIF.
    ENDDO.

  • Import/export internal tabl

    Hi,
    This is regarding import/export internal table to 2 different prog, somehow when i execute in prog ztest_hl7, it doesnt work. Please help.
    report ztest_hl7.
    TYPES:
    BEGIN OF tab_type,
    para TYPE string,
    dobj TYPE string,
    END OF tab_type.
    DATA:
    id TYPE c LENGTH 10 VALUE 'TEXTS',
    text1 TYPE string VALUE `IKE`,
    text2 TYPE string VALUE `TINA`,
    line TYPE tab_type,
    itab TYPE STANDARD TABLE OF tab_type.
    line-para = 'P1'.
    line-dobj = 'TEXT1'.
    APPEND line TO itab.
    line-para = 'P2'.
    line-dobj = 'TEXT2'.
    APPEND line TO itab.
    EXPORT itab TO MEMORY ID id.
    submit ztest_hl6 and return.
    report ztest_hl6.
    data : id TYPE c LENGTH 10 VALUE 'TEXTS'.
    TYPES:
    BEGIN OF tab_type,
    para TYPE string,
    dobj TYPE string,
    END OF tab_type.
    DATA: itab TYPE STANDARD TABLE OF tab_type,
         wa_itab type tab_type.
    IMPORT itab FROM MEMORY ID id.
    loop at itab into wa_itab.
    write:
    wa_itab-para,
    wa_itab-dobj.
    endloop.
    Edited by: Hui Leng Yeoh on Jun 26, 2008 11:25 AM

    Hi There are few syntax errors. Comment ur code and Paste this code and check. It is working fine.
    report ztest_hl7.
    TYPES:
    BEGIN OF tab_type,
    para TYPE string,
    dobj TYPE string,
    END OF tab_type.
    DATA:
    id(10) TYPE c VALUE 'TEXTS',
    text1 TYPE string, " VALUE `IKE`,
    text2 TYPE string, " VALUE `TINA`,
    line TYPE tab_type,
    itab TYPE STANDARD TABLE OF tab_type.
    text1 = 'IKE'.
    text2 = 'TINA'.
    line-para = 'P1'.
    line-dobj = 'TEXT1'.
    APPEND line TO itab.
    line-para = 'P2'.
    line-dobj = 'TEXT2'.
    APPEND line TO itab.
    EXPORT itab TO MEMORY ID id.
    SUBMIT z7569411 AND RETURN.
    data : id(10) TYPE c VALUE 'TEXTS'.
    TYPES:
    BEGIN OF tab_type,
    para TYPE string,
    dobj TYPE string,
    END OF tab_type.
    DATA: itab TYPE STANDARD TABLE OF tab_type,
    wa_itab type tab_type.
    IMPORT itab FROM MEMORY ID id.
    loop at itab into wa_itab.
    write:
    wa_itab-para,
    wa_itab-dobj.
    endloop.
    Thanks,
    vinod.

  • How to Import/Export database tables from one server to other in oracle8i

    Hello friend,
    Please can any one tell me how to import/export groups of database tables from one server with oracle to another using VB.net. It would be nice if some one can provide some code of it.
    I am a software developer and I am in middle of a large project development, in which I need to export a large oracle database from one server to another efficiently.
    Its very urgent so please someone help me.

    At command prompt (source db)
    set ORACLE_SID=db_name
    exp system/password@db_name full=y buffer=104857600 file=(c:\file1.dmp, c:\file2.dmp....) log=c:\exp.log filesize=2000M
    Then ftp the export dump files (in binary) to the other server or copy to target server over the network.
    At command prompt (target db)
    set ORACLE_SID=db_name
    imp system/password@db_name full=y ignore=y buffer=104857600 file=(c:\file1.dmp, c:\file2.dmp....) log=c:\imp.log filesize=2000M
    If the path names of the datafiles are going to be different in the target server (as compared to the source), then precreate the tablespaces before import. Set buffer value accordingly.
    Message was edited by:
    FeNiCrC_Neil

  • Problem import excel table with photos

    When I import excel table with photos, the photos don't appear

    Welcome to Project Siena!
    If you're seeing an 'x' instead of your photo in the data source it's possible that Project Siena can't access the directory.  Try saving your images in another folder such as C:\Users\Public\Pictures.
    Others have also reported that if the Library isn't set up correctly in Windows 8 that they've had issues.
    Here are some posts to look at while we wait for additional information from you:
    Importing local images via an Excel file
    Siena Gallery unable to load image
    Images in Public Pictures directories showing
    up as X in Img from URL
    (fyi - this last post's screenshot will look different than yours as it was from Beta 1.)
    Thor

  • Import data from few tables and export into the same tables on different db

    I want to import data from few tables and export into the same tables on different database. But on the target database, additional columns have been added
    to the same tables. how can i do the import?
    Its urgent can anyone please help me do this?
    Thanks.

    Hello Junior DBA,
    maybe try it with the "copy command".
    http://download.oracle.com/docs/cd/B14117_01/server.101/b12170/apb.htm
    Have a look at the section "Understanding COPY Command Syntax".
    Here is an example of a COPY command that copies only two columns from the source table, and copies only those rows in which the value of DEPARTMENT_ID is 30:Regards
    Stefan

Maybe you are looking for

  • Adobe abandons help. no follow up on case numbers

    just thought i'd enlighten new users/purchasers of the ps/lr photographers bundle of the creative cloud. new choice on the phone tree press two if you wish to cancel your membership. apparently they are overwhelmed or short handed or otherwise cluele

  • IS THERE A TOLL FREE NUMBER FOR TECH SUPPORT?

    I AM NOT ABLE TO GET THE ANSWERS THAT I NEED IN ORDER FOR MY IPOD TO FUNCTION AS I WOULD LIKE IT TOO. I WOULD LIKE TO SPEAK TO SOMEONE FROM APPLE. ANYONE KNOW OF A NUMBER WHERE THEY CAN BE REACHED?

  • Scaling and Resizing

    Hi, I use a ProgressIndicator in MigLayout (JavaFX version, see http://www.miglayout.com/). Now, if I scale the ProgressIndicator, its size does not change. In other words, MigPane still uses the non-scaled size to layout the components. Is this a la

  • Camera No Longer Saving Images

    Hey guys, ok so I have had my phone since the beginning of October and have had no issues. Since yesterday though my phone has stopped taking photos. It appears to capture the photo just fine and when I click view they are all there but appear to be

  • I can not update my Ipod Error 3194

    I can not update my Ipod Error 3194