How do I store a file as a column in a table?

Hi,
Lets say the table looks like this ...
SQL> desc myTable
NAME DATA
filename varchar2(100)
data long
would I have to write a stored procedure that does this?
procedure loadit( inFileName varchar(100) ) is
fh UTL_FILE.FILE_TYPE;
line long;
vData long;
begin
fh := UTL_FILE.FOPEN( inFileName );
while not UTL_FILE.EOF( FH ) loop
UTL_FILE.GET_LINE( fh, line );
vData := vData || line;
end loop;
UTL_FILE.FCLOSE(fh);
insert into myTable values( inFileName, vData );
commit;
end loadit;
For some reason I don't think that is going to work?
How is this done or is it even done?
Thanks

First off don't use LONG use CLOB or BLOB. Then you can use procedures in DBMS_LOB, if you set up your files as BFILES then use DBMS_LOB.LoadFromFile. This will also handle binary files.
As UTL_FILE only handles text or ASCII files, to get binary files in is harder. You could write a Java class to read files, place the Java in the database, and use that. I've written one, and I see others in different places on the NET.
Good Luck,
Eric Kamradt
PS. Could someone please give an attempt at answering my forms question posted on this forum.

Similar Messages

  • How to Upload a PDF file into BLOB column in a table using Forms 9i

    Can anyone tell me how to upload a PDF file from client system using File dialog window and store its content in BLOB column in a table. The file to be uploaded will be in client side.

    Hi,
    please, search a bit on the forum before do a question:
    Just searching by "upload blob pdf" ...
    How to batch upload PDF files into database BLOB
    Regards,
    Jose.

  • How to Upload a PDF file into BLOB column in a table using Forms 6i

    Can anyone tell me how to upload a PDF file from client and store its content in BLOB column in a table. The file will be genered using reports and win be stored in db.The file to be uploaded will be in client side.
    Thank´s.

    If you are using version 9 or 10 use webutil.... Look in webutil.pll.
    Use either one these two fuctions...
    FUNCTION Client_To_DB( clientFile       in VARCHAR2,
                             tableName        in VARCHAR2,
                             columnName       in VARCHAR2,
                             whereClause      in VARCHAR2,
                             asynchronous     in BOOLEAN default FALSE,
                             callbackTrigger  in VARCHAR2 default NULL) return BOOLEAN;
      FUNCTION Client_To_DB_With_Progress
                         (   clientFile       in VARCHAR2,
                             tableName        in VARCHAR2,
                             columnName       in VARCHAR2,
                             whereClause      in VARCHAR2,
                             progressTitle    in VARCHAR2,
                             progressSubTitle in VARCHAR2,
                             asynchronous     in BOOLEAN default FALSE,
                             callbackTrigger  in VARCHAR2 default NULL) return BOOLEAN;

  • How to read/write .CSV file into CLOB column in a table of Oracle 10g

    I have a requirement which is nothing but a table has two column
    create table emp_data (empid number, report clob)
    Here REPORT column is CLOB data type which used to load the data from the .csv file.
    The requirement here is
    1) How to load data from .CSV file into CLOB column along with empid using DBMS_lob utility
    2) How to read report columns which should return all the columns present in the .CSV file (dynamically because every csv file may have different number of columns) along with the primariy key empid).
    eg: empid report_field1 report_field2
    1 x y
    Any help would be appreciated.

    If I understand you right, you want each row in your table to contain an emp_id and the complete text of a multi-record .csv file.
    It's not clear how you relate emp_id to the appropriate file to be read. Is the emp_id stored in the csv file?
    To read the file, you can use functions from [UTL_FILE|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#BABGGEDF] (as long as the file is in a directory accessible to the Oracle server):
    declare
        lt_report_clob CLOB;
        l_max_line_length integer := 1024;   -- set as high as the longest line in your file
        l_infile UTL_FILE.file_type;
        l_buffer varchar2(1024);
        l_emp_id report_table.emp_id%type := 123; -- not clear where emp_id comes from
        l_filename varchar2(200) := 'my_file_name.csv';   -- get this from somewhere
    begin
       -- open the file; we assume an Oracle directory has already been created
        l_infile := utl_file.fopen('CSV_DIRECTORY', l_filename, 'r', l_max_line_length);
        -- initialise the empty clob
        dbms_lob.createtemporary(lt_report_clob, TRUE, DBMS_LOB.session);
        loop
          begin
             utl_file.get_line(l_infile, l_buffer);
             dbms_lob.append(lt_report_clob, l_buffer);
          exception
             when no_data_found then
                 exit;
          end;
        end loop;
        insert into report_table (emp_id, report)
        values (l_emp_id, lt_report_clob);
        -- free the temporary lob
        dbms_lob.freetemporary(lt_report_clob);
       -- close the file
       UTL_FILE.fclose(l_infile);
    end;This simple line-by-line approach is easy to understand, and gives you an opportunity (if you want) to take each line in the file and transform it (for example, you could transform it into a nested table, or into XML). However it can be rather slow if there are many records in the csv file - the lob_append operation is not particularly efficient. I was able to improve the efficiency by caching the lines in a VARCHAR2 up to a maximum cache size, and only then appending to the LOB - see [three posts on my blog|http://preferisco.blogspot.com/search/label/lob].
    There is at least one other possibility:
    - you could use [DBMS_LOB.loadclobfromfile|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978]. I've not tried this before myself, but I think the procedure is described [here in the 9i docs|http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl12bfl.htm#879711]. This is likely to be faster than UTL_FILE (because it is all happening in the underlying DBMS_LOB package, possibly in a native way).
    That's all for now. I haven't yet answered your question on how to report data back out of the CLOB. I would like to know how you associate employees with files; what happens if there is > 1 file per employee, etc.
    HTH
    Regards Nigel
    Edited by: nthomas on Mar 2, 2009 11:22 AM - don't forget to fclose the file...

  • How to print/store in file the ref cursor in pl/sql block ?

    How to print/store in file the ref cursor in pl/sql block ?.

    How to print/store in file the ref cursor in pl/sql block ?.You question is quite confusing?
    So, i'm providing link in this manner.
    For RefCursor,
    http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
    http://www.oracle.com/technology/oramag/code/tips2003/042003.html
    For UTL_FILE,
    http://www.morganslibrary.org/reference/utl_file.html
    Regards.
    Satyaki De.
    Updated with new morgan library link.
    Edited by: Satyaki_De on Feb 24, 2010 9:03 PM

  • How can we modify the maximum no. of columns in pivot table ?

    hi all,
    How can we modify the maximum no. of columns in pivot table ?
    do i need to change the nqconfig.ini or instanceconfig file or else?
    thnx..

    A little search on the forum :
    In the instanceconfig.xml add a <PivotView> element under <ServerInstance> if one does
    not exist already.
    Within the <PivotView> element add an entry that looks like:
    <MaxCells>nnnnnn</MaxCells>
    where nnnnnn is your desired limit for the maximum total number of cells allowed
    in a pivot.
    Warning: an excessively large number will cause more memory consumption and
    slower browser performance.The details here :
    Oracle BI EE (10.1.3.2): Maximum total number of cells in Pivot Table excee

  • How to find index name with primarykey and column on a table?

    Hi,
    how to find index name with primarykey and column on a table?
    please help me.
    Thankyou.

      1  select ac.table_name, ac.index_name, aic.column_name
      2  from user_constraints ac, user_ind_columns aic
      3  where ac.constraint_type = 'P'
      4   and  ac.index_name = aic.index_name
      5* order by 1,2,3
    SQL> /
    TABLE_NAME                 INDEX_NAME                COLUMN_NAME
    ACTION_TABLE                 SYS_C0011033                NESTED_TABLE_ID
    ACTION_TABLE                 SYS_C0011033                SYS_NC_ARRAY_INDEX$
    CATEGORIES_TAB                 SYS_C0011038                CATEGORY_ID
    CUSTOMERS                 CUSTOMERS_PK                CUSTOMER_ID
    INVENTORIES                 INVENTORY_IX                PRODUCT_ID
    INVENTORIES                 INVENTORY_IX                WAREHOUSE_ID
    LINEITEM_TABLE                 SYS_C0011034                NESTED_TABLE_ID
    LINEITEM_TABLE                 SYS_C0011034                SYS_NC_ARRAY_INDEX$
    ORDERS                      ORDER_PK                 ORDER_ID
    ORDER_ITEMS                 ORDER_ITEMS_PK                LINE_ITEM_ID
    ORDER_ITEMS                 ORDER_ITEMS_PK                ORDER_ID
    PRODUCT_DESCRIPTIONS            PRD_DESC_PK                LANGUAGE_ID
    PRODUCT_DESCRIPTIONS            PRD_DESC_PK                PRODUCT_ID
    PRODUCT_INFORMATION            PRODUCT_INFORMATION_PK           PRODUCT_ID
    PROMOTIONS                 PROMO_ID_PK                PROMO_ID
    WAREHOUSES                 WAREHOUSES_PK                WAREHOUSE_ID
    16 rows selected.

  • Macbook Pro hard disk full, how do i store Movie files externally

    I have just freed some space, as I was unable to add any new files or Apps.
    How can i store my movies elsewhere? i am not bothered about a back up copy, just another storage area. I use them and play via PS3.
    I think i have used about 250gb on my Internal HD.
    So I bought a 2TB Buffalo Ext hard drive but cant make the Mac talk to it.
    Jocka

    Are these movies in your iTunes library?  If so, you can move the iTunes library to an external volume in the Finder and use iTunes -> Preferences -> Advanced to change the location in iTunes.  Also, note that if they are movies purchased from the iTunes Store, you only get one download...  so you'll want to keep them backed up, or if something happens to them, you'll have no choice other than to repurchase them (or not have them anymore)!
    If they're not part of your iTunes library, just copy them over to the external drive and delete them from the external.

  • How do I store mp3 files on my IPOD but leave uncompressed files in iTunes?

    I always buy uncompressed files and I want to keep them uncompressed in iTunes so I always have a copy of the best fidelity on my computer (for burning CD's). However I only want to store compressed files (MP3 or whatever other compression option is available) on my iPOD (or at least I want to be able to choose the format for my iPOD). I couldn't find a way to do this without changing the format of what is on my hard drive. Any ideas?
    Thanks

    I get duplicates when I convert my 320 kbps mp3 files to 128 kbps AAC files for my Nano. I'm not sure if I set something in my preferences to make sure the original file stays intact. Why don't you try converting one song (that you can reimport if necessary) to make sure that you get duplicates too. Just to be safe. If you don't get a duplicate, post back and I try to figure out how I have my iTunes set up to duplicate converted songs rather than replace them.

  • How can i store jpeg file in iCloud?

    I want to upload jpeg file in iCloud, so that I could insert it to my document later with Pages. but can't find how can i store this type of file in icloud....

    iCloud isn't really meant for that purpose, more for syncing across devices. Try something like dropbox.

  • How can I store iPhoto files on an external hard drive rather than on the iMac drive

    How can I store my iPhoto library on an external hard drive rather than the iMac drive to make my computer faster?

    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • How I can store Image file in a database

    Can any one how i can stored image file in a database and then by using same database how i can show in HTML page...(in a browser)

    This is not something that can be answered easily. There is quite alot of code involved....
    To get started I suggest you read up on the built-in package 'DBMS_LOB' from Oracle . Most of what you need you should find there.
    regards Dave.

  • How to save the pdf file or word doc into sap table

    Hi Expertu2019s
       I have a pfd file in my presentation server .Now I want to save the pdf file into sap table using module pool program. Whenever i need, I want to open that file from the table and show it in the Screen. Please any one tell me how I can save the file. What is the table name, guide me.
    Regards,
    S.Nehru.

    Hi,
    Try the following code
    FORM gui_upload.
      DATA: lv_filetype(10) TYPE c,
            lv_gui_sep TYPE c,
            lv_file_name TYPE string.
      lv_filetype = 'PDF'.
      lv_file_name = <name of ur file>.
    DATA: tb_file_data TYPE TABLE OF text4096.
    * FM call to upload file
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = lv_file_name
          filetype                = lv_filetype
          has_field_separator     = lv_gui_sep
        TABLES
          data_tab                = tb_file_data
        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.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "gui_upload
    I dont think you can save the data into sap tables in PDF format.
    With the above code you can save data into an internal table.
    Regards,
    Manish

  • How to send the PDF file to FAX will the nast table updates

    Hi all,
    How to send the PDF file to FAX. Will the nast table updates ( which fields updates ).
    Need is once fax is send for that delivery, again it should not fax again. Will the nast table helps to check the sent fax.
    Please give me sutable suggessions....

    Have you checked Forums » Community Discussions » Code Snippets 
    I believe there were some examples on converting/sending PDF.
    Or check FM 'SO_DOCUMENT_SEND_API1' and documentation for it.

  • How to map single input value to Two columns of Database table using format file of Bulk Copy Process

    Hi All,
    Am using OPENROWSET to load the file data into table, here the problem is i need to map same input value to two different columns of table, As format file doesn't allow the duplicate numbers am unable to insert same value to two columns, please help me to
    find a solution for this. 
    i can use only OPENROWSET because i need to insert some default values also which come based on file. only the problem is how to map same input value to two different columns of table. please give me the suggestions.
    Thanks,
    Sudhakar

    From what you say:
       INSERT tbl(col1, col2)
          SELECT col1, col1
          FROM   OPENROWSET(....)
    But I guess it is more difficult. You need to give more details. What sort of data source do you have? What does your query look like? The target table?
    Erland Sommarskog, SQL Server MVP, [email protected]
    Hi Erland,
    Thanks for your response
    my source file is text file with | symbol separate for ex:
    1002|eTab |V101|eTablet|V100|Logic|LT-7|Laptops|SCM
    Database table have columns like
    column1,column2,column3...etc, now i need to insert same value from input file into two columns for ex:
    the eTab value from text file has to be insert into column2 and column3 of
    table
    we cannot change format file like below one
    for the above situation how can we insert eTab into column2 and column3
    Thanks,
    Sudhakar.

Maybe you are looking for