Excel to Blob

Hi,
I have an Oracle Forms Application that generates an Excel file, and I need do transform the Excel file generated in a blob type. I generate the Excel file with Ole2 package, with the following code:
OLE2.INVOKE(WORKBOOK,'SaveAs',FILENAME);
How can I save the Excel file generated in a blob variable?
Thanks,
Murilo

if you are using webutil have a look at...
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 is
...or...
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 is
And after looking at your code it appears that you are not using webutil. So, here is how to load a blob from a bfile and many other blob manipulations..
http://download-east.oracle.com/docs/cd/B14117_01/appdev.101/b10796/adlob_da.htm

Similar Messages

  • Need help!: How to covert Excel into BLOB and pass into procedure?

    Hi,
    I am writing a program in which I am uploading file from front-end and passing that file into Oracle procedure in BLOB format.
    Can someone help me ,that **how to convert Excel sheet into BLOB and then how we can pass that BLOB object to procedure in oracle*.
    Any help will greatly appreciated.
    Thanks

    Guys,
    I am able to convert FormFile into byutes using getFileData();
    But when I am tryint oconvert into BLOB,it is dhoowing me the error.
    Please find the complete details below.
    I am trying to Upload one file using FormFile of Struts and I need to pass that Form File into one procedure having BLOB as aIn parameter. SO I need to convert that file into BLOB object
    The code that I am trying is :
    try{
    BLOB blob= BLOB.getEmptyBLOB();
    System.out.println("before");
    blob.setBytes(theFile.getFileData());
    System.out.println("after");
    cs.setBlob(3, blob);
    }catch(Exception e){System.out.println("in the BLOB "+e);}
    After running the code,I am getting the following error
    java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at oracle.jdbc.driver.DatumBinder.bind(OraclePreparedStatement.java:15839)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2865)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2150)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3279)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3389)
    at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4222)
    at dms.bo.impl.LoadManagement.UploadMetadataDAOImpl$1.doInCallableStatement(UploadMetadataDAOImpl.java:38)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:953)
    at dms.bo.impl.LoadManagement.UploadMetadataDAOImpl.getBlobString(UploadMetadataDAOImpl.java:28)
    at dms.web.action.LoadManagement.UploadMetadataAction.perform(UploadMetadataAction.java:33)
    at dms.web.action.common.BaseAction.execute(BaseAction.java:17)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619
    So with

  • Forms, Excel and Blob

    Hi,
    I'm developing a web application in forms6i that must generate an excel file and then stored it in a blob field. I've gotten to generate the excel file with ole2 package but the ora-305500 error is raised when I deploy it to application server, if I install the excel application on the application server, will it work fine?
    Supposing it works, the file was generated correctly on the application server, how can I transform this file that is located on the application server in a blob variable and store it into database that is located in another machine?
    I'm trying to find a solution to avoid a utilization of webutil, because I didn't find a webutil for forms6i.
    Please, can anyone help me?
    Thanks!

    Thanks for your quickly answer Rejesh Alex,
    Then I'll can generate the excel file on application server, but I won't show it to client, ok? I decided to not show de excel file to client, I want to generate it and store it into database blob field, is it possible? Considering that the application server and database server are different machines. I tried to use BFILENAME function to do this, but it expects a parameter that is a directory created in database server, but I need to load a file created in application server.

  • Opening Excel Files from DB (blob column)

    My project has implemented a WEBUTIL solution to attach files into the database, view the files stored in the database (in a BLOB column), and remove the files stored in the database.
    Everything has been running smoothly. We are in final testing and have found a couple of interesting scenarios ...
    When a user tries to view an Microsoft Excel 2007 file from our application, the Excel file displays properly (as long as Microsoft Excel isn't already open - outside of our Oracle application). Once the Excel file is viewed, the system will not allow the user back to our application until after the Excel file is closed (we use the start /wait myExcelFile.xls ... command). This works perfectly for us.
    The two scenarios we encounter occur when
    1.) The user has Microsoft Excel open outside of our application and tries to open an Excel file from within our application, or
    2.) The user has the file already open (either from within our application or outside of our application) and then tries to open the file from within our application.
    Let me explain a little further because the above two scenarios are interrelated.
    When a user has Microsoft Excel open (outside of our application), and then clicks the button to open the Excel file, the system will open the file as another window (within Excel). The system will allow the user to navigate back to our application (where as, if Excel is not open outside of our application, the system will not allow the user to navigate back to our application). Once the user navigates back to our application (while the file is still open), the user can click the button to view the file again. At this point, the user is displayed a WUT-105 error message (I assume b/c the system is trying to open a file that is already open).
    I assume the two solutions are the following:
    a.) Do not allow a user to open a file that is already open (not sure how to check this from within Forms ?)
    b.) Do not allow a user to open an Excel file when another EXCEL process is already running (this will avoid allowing the user to naviagate back to our application)
    I don't know if there is a better solution.
    Do you experts have any recommendations?
    We are using Oracle Application Server 10g R2 (10.1.2.0.2), Oracle Database 10g R2 (10.2), and Oracle Developer 10g (10.1.2.0.2)
    I hope this all makes sense.
    Thanks,
    Mike
    Edited by: user639843 on Oct 20, 2008 2:15 PM
    Edited by: user639843 on Oct 20, 2008 2:20 PM

    Thank you, Thank you, Thank you!!!!
    I believe that will work (adding a sequence number to the end of the filename)!
    We do not allow a user to update the file, only view. If a user wants to make a change, they need to remove the existing file (from the database), create a new file (outside of our application), and attach the file in our application (into the database). All updates occur outside of our application - we are not a document authoring system, just a document storage system.
    Once again, many thanks on the solution!
    Mike

  • CANNOT DISPLAY A WORD/EXCEL DOC IN BLOB FIELD INTO A PDF REPORT

    We created a report that should display several kinds of documents at one time.
    These documents are stored in BLOB columns in database. We had no problem to
    display txt, gif or jpeg, but we could not display doc, xls, pdf or html
    documents.
    In this report we set three different fields in which display different kinds
    of documents depending on mimetype. The first field has FileFormat property set
    to 'Text' in order to display 'text/plain' and 'text/html' mimetype documents.
    The second field has it set to 'Image', which allow to display 'image/bmp',
    'image/gif', 'image/x-png', 'image/pjpeg' mimetypes. The third field has this
    property set to 'OLE2', and here is where we would like to display other
    mimetype documents as 'application/msword', 'application/vnd.ms-excel',
    'application/pdf'.
    We run the report on the web using:
    http://<server>:<port>/dev60cgi/rwcgi60
    ?server=<report_server>
    &report=<rdf_name>
    &destype=localfile
    &desname=<report_name.pdf>
    &userid=<user>/<password>@orcl9i
    &desformat=pdf
    <6meters>
    I have already read a lot of notes in Metalink but I could not find any
    solution. Is there any way to display a Word/Excel document from database in a
    report?
    We tried to convert Word/Excel docs to html format, but when we tried to
    display an HTML document in the report, we found that Oracle Reports displays
    the source code instead of the HTML format document. So, this did not work.
    What can we do?
    We also read somewhere that a possible solution would be to convert Word/Excel
    documents to a common format like GIF, JEPD or PDF. If processed as gif or jped
    the file could be displayed in the report. If processed as pdf the document
    could be linked in the report.
    I tried to display a PDF in the report but a blank box is displayed. How can I
    do this too?
    Any solutions?

    Hi,
    I have the same problem. I need to show up a BLOB, word file(.doc), in a custom report. I made a simple query, extracting file_date( the column having the blog (.doc) file) from the database, in the report and placed it on a layout by assigning it to a field "F_1". I addressed the file format as OLE2.
    But when I run the Report in APPS, it shows up an error "REP-1814: Report cannot be formatted. Object 'horizontally and vertically' can never fit within 'F_1'.". I also played with the layout by changing its size but the response had no change.
    I am using Reports6i and the output format of the report is PDF. Is there a way to resolve the issue? Please share the solution if you have any for this.

  • Opening an Excel file saved as a BLOB in the DB

    I have a table where I am storing excel content generated by another application that I want OBIEE users to be able to access via a Dashboard. Is there a method for opening the BLOB from a Dashboard?

    OBIEE doesn't support BLOBs so I don't think you will to use OBIEE for this. Having said that you could develop a small Web App using the language of your choice (Java/.Net/etc) where you can pass a URL and this Web App will connect to the DB to get the BLOB and offer it as a downloadable file. An OBIEE dashboard is quite capable of generating dynamic URL links which could include your Excel file ID which should allow the custom web App to fetch the BLOB. For the users it will look almost like OBIEE is giving them the file. Hope it helps.

  • Export table rows to Excel and save to BLOB field

    Hi all,
    I try to find out how export data from table to Excel file format and save the result to BLOB field in some other table.
    I know how to download report from Page by submit, but I need to process data and instead of returning result to user as Excel file - save it in BLOB.
    Also I found implementation on JAVA for the issue but actually I wanna study out - Is it possible to resolve this issue by PL/SQL and APEX API methods?
    So, any ideas :) ??
    Thanks,

    It is not very difficult.
    Here is the function I use to get a CSV file from a query :
    PROCEDURE get_query_result_as_csv_file(
         in_query    IN VARCHAR2,
         in_filename IN VARCHAR2)
    IS
         l_blob BLOB;
         l_raw     RAW(32767);
         l_cursor INTEGER;
         l_cursor_status INTEGER;
         l_col_count      NUMBER;
         l_col_val VARCHAR2(32767);
         l_desc_tbl sys.dbms_sql.desc_tab2;
    BEGIN
         -- create temporary BLOB
         dbms_lob.createtemporary(l_blob, FALSE);
         -- open BLOB
         dbms_lob.open(l_blob, dbms_lob.lob_readwrite);
         -- open cursor (and get cursor id)
         l_cursor := dbms_sql.open_cursor;
         -- parse query
         dbms_sql.parse(l_cursor,  in_query, dbms_sql.native);
         -- get number of columns and description
         dbms_sql.describe_columns2(l_cursor, l_col_count, l_desc_tbl);
         -- define report columns
         FOR i IN 1 .. l_col_count LOOP
              dbms_sql.define_column(l_cursor, i, l_col_val, 32767);
         END LOOP;
         -- write column headings to CSV file
         FOR i IN 1 .. l_col_count LOOP
              l_col_val := l_desc_tbl(i).col_name;
              IF i = l_col_count THEN
                   l_col_val := '"' || l_col_val || '"' || chr(10);
              ELSE
                   l_col_val := '"' || l_col_val || '",';
              END IF;
              l_raw := utl_raw.cast_to_raw(l_col_val);
              dbms_lob.writeappend(l_blob, utl_raw.length(l_raw), l_raw);
         END LOOP;
         -- execute the query
         l_cursor_status := dbms_sql.execute(l_cursor);
         -- write result set to CSV file
         LOOP
              EXIT WHEN dbms_sql.fetch_rows(l_cursor) <= 0 OR dbms_sql.last_row_count > 1000;
              FOR i IN 1 .. l_col_count LOOP
                   dbms_sql.column_value(l_cursor, i, l_col_val);
                   IF i = l_col_count THEN
                        l_col_val := '"' || l_col_val || '"' || chr(10);
                   ELSE
                        l_col_val := '"' || l_col_val || '",';
                   END IF;
                   l_raw := utl_raw.cast_to_raw(l_col_val);
                   dbms_lob.writeappend(l_blob, utl_raw.length(l_raw), l_raw);
              END LOOP;
         END LOOP;
         -- close cursor and BLOB
         dbms_sql.close_cursor(l_cursor);
         dbms_lob.close(l_blob);
         -- set http headers
         owa_util.mime_header('application/octet', FALSE);
         htp.p('content-length: ' || dbms_lob.getlength(l_blob));
         htp.p('content-disposition: attachment;filename="' || in_filename || '.csv"');
         owa_util.http_header_close;
         -- download the file
         wpg_docload.download_file(l_blob);
    END;If you need to get the query dynamically from your report, you can try to get the source from the apex_application_page_regions table :
    SELECT region_source
    FROM apex_application_page_regions
    WHERE application_id = 111 -- replace with your application id
    AND static_id = 'static_id_of_your_report'Then instead of using wpg_docload.download_file, simply insert the BLOB into your table.
    Good luck.
    Yann.

  • Reg : Exporting BLOB data to EXCEL

    Hi ,
    I have a requirement of exporting BLOB data to EXCEL.
    I tried it but i ma facing issue.
    Can anyone suggest me how to do it.
    Thanks & Regards :
    Pramila Padam

    HI Timo ,
    You are the only one helping to our team.
    We are trying according to the link provided by you.
    We will do and tell you.
    Thanks & Regards :
    Pramila Padam

  • Edit the Excel file which i have uploaded in my blob domain.

    Hi,
    Am using jdeveloper 11.1.1.6.0.,
    I have dragged and dropped my VO as af:form in which uploadFile is a blobdomain.
    This is the code which i have used for upload and download my excel document.
    public void uploadFileValueChangeEvent(ValueChangeEvent valueChangeEvent) throws IOException,
    SQLException {
    // Add event code here...
    // The event give access to an Uploade dFile which contains data about the file and its content
    UploadedFile file = (UploadedFile)valueChangeEvent.getNewValue();
    // Get the original file name
    String fileName = file.getFilename();
    long filesize = file.getLength();
    long fkb = filesize/1024;
    // get the mime type
    String contentType = file.getContentType();
    //ContentTypes.get(fileName);
    // get the current roew from the ImagesView2Iterator via the binding
    DCBindingContainer lBindingContainer =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding lBinding =
    lBindingContainer.findIteratorBinding("XFilesView1Iterator");
    Row newRow = lBinding.getCurrentRow();
    // set the file name
    newRow.setAttribute("FileName", fileName);
    // create the BlobDomain and set it into the row
    newRow.setAttribute("FileContent", createBlobDomain(file));
    // set the mime type
    newRow.setAttribute("FileType", contentType);
    newRow.setAttribute("FileSize", fkb);
    private BlobDomain createBlobDomain(UploadedFile file)
    throws IOException, SQLException {
    // init the internal variables
    InputStream in = null;
    BlobDomain blobDomain = null;
    OutputStream out = null;
    try
    // Get the input stream representing the data from the client
    in = file.getInputStream();
    // create the BlobDomain datatype to store the data in the db
    blobDomain = new BlobDomain();
    // get the outputStream for hte BlobDomain
    out = blobDomain.getBinaryOutputStream();
    // copy the input stream into the output stream
    * IOUtils is a class from the Apache Commons IO Package (http://www.apache.org/)
    * Here version 2.0.1 is used
    * please download it directly from http://projects.apache.org/projects/commons_io.html
    IOUtils.copy(in, out);
    catch (IOException e)
    e.printStackTrace();
    catch (SQLException e)
    e.fillInStackTrace();
    // return the filled BlobDomain
    return blobDomain;
    public void Download(FacesContext facesContext,
    OutputStream outputStream) {
    // Add event code here...
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    // get an ADF attributevalue from the ADF page definitions
    AttributeBinding attr = (AttributeBinding) bindings.getControlBinding("FileContent");
    if (attr == null)
    return;
    // the value is a BlobDomain data type
    BlobDomain blob = (BlobDomain) attr.getInputValue();
    try
    {   // copy hte data from the BlobDomain to the output stream
    IOUtils.copy(blob.getInputStream(), outputStream);
    // cloase the blob to release the recources
    blob.closeInputStream();
    // flush the outout stream
    outputStream.flush();
    catch (IOException e)
    // handle errors
    e.printStackTrace();
    FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), "");
    FacesContext.getCurrentInstance().addMessage(null, msg);
    My Scenario :
    I need to edit the uploaded file and save it back to the same location.
    How can i achieve this?

    By edit you mean changes the cells of the excel file?
    For  this you have to download the file to the client, let him make the changes and upload it again.
    You may want to look into Desktop integration
    Or if you want to change it in java you can use POI to change the file. However you first have to get it out of the blog, change it and put it back into the blob.
    Timo

  • Modifying and saving a Excel file by the use of Blob-Stream Method?

    Hi everyone...
    I'm trying to change and modify a Excel file which is received as Blob variable from database.
    I wrote a PL/SQL Procedure which get the Excel file and convert it to blob; after that send it as the parameter of a Java source called TestPrintExcel
    CREATE OR REPLACE DIRECTORY VMI_TEST_DIR AS '/afc/opt/dba/test_utl_dir';
    GRANT READ, WRITE ON DIRECTORY SYS.VMI_TEST_DIR TO SYSTEM;
    declare 
       bfi  bfile := bfilename('VMI_TEST_DIR','TestFzglist.xls');
       bin  blob;
       cout clob;  
    begin
       dbms_lob.open(bfi);
       dbms_lob.createtemporary(bin, true);
       dbms_lob.loadfromfile(bin, bfi, dbms_lob.getlength(bfi));
       dbms_lob.close(bfi);
       dbms_lob.createtemporary(cout, true);
       dbms_java.set_output(100000);
       TestPrintExcel(bin);
       dbms_output.put_line('done!');
    end;With the following Java procedure I can read the content of the Excel file and write it to database perfectly. But the question is, how can i save the excel file with the same way, if i would change or insert any cell? I mean with the same way that to save as blob stream. Because i get permission error when i use another methods like FileOutputStream, FileInputStream etc. That's way i want to resolve this problem with the blob-stream method. Can anybody tell me how i can do that or what a method i have to use?
    Thanks.
    create or replace and compile java source named xltest as
      import org.apache.poi.ss.usermodel.WorkbookFactory;
      import org.apache.poi.ss.usermodel.Workbook;
      import org.apache.poi.ss.usermodel.Sheet;
      import org.apache.poi.ss.usermodel.Row;
      import org.apache.poi.ss.usermodel.Cell;
      import org.apache.poi.ss.util.CellReference;
      import org.apache.poi.ss.usermodel.DataFormatter;
      import org.apache.poi.ss.usermodel.FormulaEvaluator;
      import java.util.*;
      import java.sql.*;
      import oracle.sql.*;
      import oracle.jdbc.driver.*;
      public class XLTEST {
        public static void printx( oracle.sql.BLOB xblin ) throws SQLException {                       
          Connection Conn = null;
          try {
            Conn = DriverManager.getConnection( "jdbc:default:connection:" );
            Workbook wb = WorkbookFactory.create( xblin.getBinaryStream() ); // "/afc/opt/dba/test_utl_dir/TstFzglist.xls"
            for ( int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++ ) {  //NumberOfSheets
              String TableName = new String();       
              switch( sheetNum )
                case 0:
                  TableName = "freeimportxls_s1"; break;           
                case 1:
                  TableName = "FreeImportXLS_S2"; break;
                case 2:
                  TableName = "FreeImportXLS_S3"; break;
                default:
                  break;                  
              Sheet sheet1 = wb.getSheetAt(sheetNum);         
              java.util.Iterator<Row> ri = sheet1.rowIterator();                 
              while ( ri.hasNext() ) {
                Row row = ri.next();
                java.util.Iterator<Cell> ci = row.cellIterator();                       
                while ( ci.hasNext() ) {
                  Cell cell = ci.next();
                  CellReference cellRef = new CellReference( row.getRowNum(), cell.getColumnIndex() );                         
                  switch( cell.getCellType() ) {
                  case Cell.CELL_TYPE_STRING:                            
                    Values   += "'" + cell.getRichStringCellValue().getString() + "'";               
                    break;
                  case Cell.CELL_TYPE_NUMERIC:
                    Values   += "'" + cell.getNumericCellValue() + "'";
                    break;
                  case Cell.CELL_TYPE_BOOLEAN:
                    Values   += "'" + cell.getBooleanCellValue() + "'";
                    break;
                  case Cell.CELL_TYPE_FORMULA:
                    Values   += "'" + cell.getCellFormula() + "'";
                    break;
                  default:
                    Values   += "''";               
                  int Counter1 = cell.getColumnIndex() + 1;
                  int Counter2 = row.getLastCellNum();
                  if ( Counter1==Counter2 ) {
                    Values   += ")";                          
                  else {
                    Values   += "," ;
                } System.out.println ( Values );               
                if ( ( sheetNum >= 0 ) && ( sheetNum <=2 ) ) {
                   String sqlUpdate = "INSERT INTO " + TableName + " VALUES " + Values;
                   PreparedStatement pstmt = Conn.prepareStatement( sqlUpdate );                                          
                   pstmt.executeUpdate();           
                   pstmt.close();              
            } Conn.close();
          } catch ( java.sql.SQLException e ) {       
            System.err.println( e.getMessage() );
            e.printStackTrace( System.err );
            Conn.close();}        
      };

    Hi,
    Because i get permission error when i use another methods like FileOutputStream, FileInputStream etc.Permission errors are generally resolved by granting the proper privilege via DBMS_JAVA.grant_permission procedure.
    Have you already tried that?
    http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chten.htm#BABHDBCJ

  • Upload data from excel into database through pl/sql

    Hi All,
    I have excel which contains data lets say employee details,
    I have one upload button ,which is used to upload excel and then i want to map the cell of excel to the database column and through plsql code i want to upload the excel data into database.
    In short ,i want to upload the data from excel into database using plsql code,
    or suggest me any other way to do this.(except the data load method present in apex)
    Thanks,
    Jitendra

    if you use APEX 4 you can define you own table
    the code below is for APEX 3
    PROCEDURE pro_carga_planilla_prosp( p_archivo VARCHAR2) IS
    v_blob_data BLOB;
    v_blob_len NUMBER;
    v_position NUMBER;
    v_raw_chunk RAW(10000);
    v_char CHAR(1);
    c_chunk_len number := 1;
    v_line VARCHAR2 (32767) := NULL;
    v_data_array wwv_flow_global.vc_arr2;
    v_rows number;
    v_sr_no number := 1;
    v_ok boolean := true;
    v_local_ok BOOLEAN := TRUE;
    v_reg_ok NUMBER := 0;
    v_reg_ko NUMBER := 0;
    v_localidad_id NUMBER;
    v_departamento_id NUMBER;
    v_cargo_id NUMBER;
    v_prospecto_id NUMBER;
    v_asesor_id NUMBER;
    V_REG prospectos%rowtype;
    BEGIN
    -- Read data from wwv_flow_files</span>
    select blob_content into v_blob_data
    from wwv_flow_files
    where name= p_archivo;
    v_blob_len := dbms_lob.getlength(v_blob_data);
    v_position := 1;
    -- Read and convert binary to char</span>
    WHILE ( v_position <= v_blob_len ) LOOP
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
    v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
    v_line := v_line || v_char;
    -- pro_log('linea '||v_line);
    v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved </span>
    IF v_char = CHR(10) THEN
    -- Convert comma to : to use wwv_flow_utilities </span>
    v_line := replace(REPLACE (v_line, ',', ':'), ';',':');
    v_line := replace(replace(v_line, chr(10)),chr(13));
    if substr(v_line,1,1)= ':' then
    v_line := '0'||v_line;
    end if;
    if instr(v_line,':',1,21) = 0 then
    if instr(v_line,':',1,20) = 0 then
    v_line:=v_line||':';
    end if;
    v_line:=v_line||':';
    end if;
    -- pro_log(v_line);
    -- Convert each column separated by : into array of data </span>
    v_data_array := wwv_flow_utilities.string_to_table (v_line);
    -- Insert data into target table </span>
    IF v_data_array(1) IS NOT NULL AND
    v_sr_no <> 1 THEN
    V_REG.NOMBRE:=ltrim(rtrim(v_data_array(2)));
    V_REG.RAZON_SOCIAL:=v_data_array(3);
    V_REG.DIRECCION := v_data_array(4)||' '||v_data_array(5);
    -- PRO_LOG('PROSP 1 ' ||v_sr_no);
    v_localidad_id := pack_empresas.get_localidad(v_data_array(6));
    -- PRO_LOG('PROSP 1.1 '||v_sr_no);
    V_REG.LOCALIDAD_ID:=v_localidad_id;
    -- PRO_LOG('PROSP 1.2 '||v_sr_no);
    V_REG.CODIGO_POSTAL:=LTRIM(RTRIM(v_data_array(7)) );
    -- PRO_LOG('PROSP 1.3 '||v_sr_no);
    -- PRO_LOG('PROSP 1.1 '||v_sr_no);
    v_departamento_id := pack_empresas.get_departamento(v_data_array(8));
    -- PRO_LOG('PROSP 1.4 '||v_sr_no);
    V_REG.DEPARTAMENTO_ID:=v_departamento_id;
    -- PRO_LOG('PROSP 1.5 '||v_sr_no);
    V_REG.TELEFONO:=v_data_array(9);
    --PRO_LOG('PROSP 1.6 '||v_sr_no);
    V_REG.TELEFONO2:=v_data_array(10);
    -- PRO_LOG('PROSP 1.7 '||v_sr_no);
    V_REG.RUBRO:=v_data_array(11);
    -- PRO_LOG('PROSP 1.8 '||v_sr_no);
    V_REG.RUC:=ltrim(rtrim(v_data_array(12)));
    -- PRO_LOG('PROSP 1.9 '||v_sr_no);
    -- pro_log(v_data_array(1));
    -- pro_log(v_data_array(2));
    V_REG.CANTIDAD_EMPLEADOS:=RTRIM(LTRIM(v_data_array(13)));
    -- PRO_LOG('PROSP 1.10 '||v_sr_no);
    -- pro_log(v_data_array(14));
    V_REG.CANTIDAD_BENEFICIARIOS:=RTRIM(LTRIM(v_data_array(14)));
    --PRO_LOG('PROSP 1.11 '||v_sr_no);
    V_REG.MAIL:=v_data_array(19);
    -- pro_log(V_REG.MAIL);
    -- PRO_LOG('PROSP 1.12 '||v_sr_no);
    -- v_data_array(20):= replace(replace(v_data_array(20),chr(10)),chr(13));
    if not v_data_array.exists(20) then
    -- pro_log('existe');
    -- pro_log(ltrim(rtrim(replace(replace(v_data_array(20),chr(10)),chr(13)))));
    V_REG.Proveedor:= ltrim(rtrim(replace(replace(v_data_array(20),chr(10)),chr(13))));
    else
    v_data_array(20):=null;
    end if;
    -- V_REG.PROVEEDOR:=v_data_array(20);
    -- PRO_LOG('PROSP 1.13 '||v_sr_no);
    if not v_data_array.exists(21) then
    V_REG.OBSERVACIONES:=v_data_array(21);
    else
    v_data_array(21):=null;
    end if;
    -- PRO_LOG('PROSP 1.14 '||v_sr_no);
    -- PRO_LOG('PROSP 1.2 '||v_sr_no);
    insert into prospectos (nombre,razon_social, direccion,localidad_id,codigo_postal,
    departamento_id, telefono, telefono2, rubro,ruc,cantidad_empleados,
    cantidad_beneficiarios,mail,proveedor,observaciones)
    values (nvl(ltrim(rtrim(v_data_array(2))),v_data_array(3)), v_data_array(3),
    v_data_array(4)||' '||v_data_array(5),
    v_localidad_id, LTRIM(RTRIM(v_data_array(7))),v_departamento_id, v_data_array(9),
    v_data_array(10),v_data_array(11), ltrim(rtrim(v_data_array(12))), RTRIM(LTRIM(v_data_array(13))),
    RTRIM(LTRIM(v_data_array(14))),v_data_array(19),v_data_array(20), v_data_array(21))
    returning prospecto_id INTO v_prospecto_id;
    -- PRO_LOG('PROSP 2');
    v_cargo_id := pack_empresas.get_cargo(v_data_array(17));
    -- PRO_LOG('PROSP 3');
    insert into prospecto_contactos (prospecto_id,nombre,apellido,cargo_id,
    telefono,mail)
    values (v_prospecto_id, nvl(v_data_array(15),'S/N'), nvl(v_data_array(16),'S/A'),
    v_cargo_id, v_data_array(18), v_data_array(19));
    -- PRO_LOG('PROSP 4');
    v_asesor_id := pack_empresas.get_asesor(v_data_array(1));
    -- PRO_LOG('PROSP 5');
    insert into asignaciones (prospecto_id,asesor_id,fecha_asignacion)
    values (v_prospecto_id, v_asesor_id, trunc(sysdate));
    -- PRO_LOG('PROSP 6');
    END IF;
    -- Clear out
    v_line := NULL;
    v_sr_no := v_sr_no + 1;
    END IF;
    END LOOP;
    delete wwv_flow_files
    where name= p_archivo;
    END pro_carga_planilla_prosp;
    function hex_to_decimal
    --this function is based on one by Connor McDonald
    --http://www.jlcomp.demon.co.uk/faq/base_convert.html
    ( p_hex_str in varchar2 ) return number
    is
    v_dec number;
    v_hex varchar2(16) := '0123456789ABCDEF';
    begin
    v_dec := 0;
    for indx in 1 .. length(p_hex_str)
    loop
    v_dec := v_dec * 16 + instr(v_hex,upper(substr(p_hex_str,indx,1)))-1;
    end loop;
    return v_dec;
    end hex_to_decimal;

  • Associative Array and Blob

    I’m currently working on a system that allows the users to upload an Excel spreadsheet (.xls) in the system. The upload page is a PL/SQL cartridge. Then I’ve written a Java servlet (using Oracle Clean Content) to convert the XLS into a CSV and store it back in the database. (it is stored in the “uploaded_files” table as a blob). I’m trying to create another procedure to read the contents of the blob and display a preview of the data on the screen (using an html table (will be done using cartridge)). After the preview, the user can choose to submit the data into the database into the “detail_records” table or simply discard everything.
    I've been trying to use an associative array to grab all the data from the blob but I’m getting confused about how to implement it in my situation.
    Can someone provide any examples of this nature?
    Any help is greatly appreciated.

    I decided to create a "record" type with all the columns from my excel spreadsheet. Then I will create a table type of records
    I am doing something like this:
    declare
    type s_record is record
                            (l_name varchar2(100),
                             f_code varchar2(4) ,
                             l_code varchar2(6),
                             d_date varchar2(5),
                             d_type varchar2(5),
                             price number,
                             volume number,
                             tax number,
                             amount_paid number
    type s_data_tab is table of s_record index by binary_integer;
    v_s_data s_data_tab;
    v_indx binary_integer :=0;
    begin
    end; I am getting confused about parsing an entire row of values separated by commas into a row in the temporary table created above.
    I know I need a loop, but from what I understand, the way to populate data needs to be something like this, for example:
    for v_indx in 0..data_size loop
       v_s_data(v_indx).l_name:= 'Company A';
       v_s_data(v_indx).f_code := '2700';
    end loop; But I'm not sure how this approach should be used to parse an entire row at once.
    Any help appreciated.

  • Downloading excel file from FTP Server to Application Server

    Hi,
    I have to get data from an excel file available on FTP server into an Internal table.Can I use FTP_SERVER_TO_R3 to do so.
    Please let me know if there are any function modules available to do this.
    Thanks,
    Prasuna.

    Dear Gayatri,
    You can get the file from FTP to internal table...
    I am sending you the code with inline comments ....Hope this will be helpful to you.
    Data: lv_key           TYPE i VALUE 26101957.
    Data: lv_password(30)  TYPE c.
      i_rfc_destination = 'SAPFTP'.
      lv_length = STRLEN( i_password ).
    CALL FUNCTION 'HTTP_SCRAMBLE'
        EXPORTING
          SOURCE      = i_password "give ftp server pwd
          sourcelen   = lv_length
          key         = lv_key
        IMPORTING
          destination = lv_password.
      CALL FUNCTION 'FTP_CONNECT'
        EXPORTING
          user            = i_user "give ftp user name
          password        = lv_password
          host            = i_host
          rfc_destination = i_rfc_destination
        IMPORTING
          handle          = lv_ftp_handle
        EXCEPTIONS
          not_connected   = 1
          OTHERS          = 2.
        CONCATENATE 'cd' i_folder_path INTO lv_cmd SEPARATED BY space.
    *i_folder path is the path in ftp server where file is  stored
        CALL FUNCTION 'FTP_COMMAND'
          EXPORTING
            handle        = lv_ftp_handle
            command       = lv_cmd
          TABLES
            data          = result
          EXCEPTIONS
            command_error = 1
            tcpip_error   = 2.
         lv_blob_length = 392.
         TRANSLATE i_filename TO LOWER CASE.
          CALL FUNCTION 'FTP_SERVER_TO_R3'
            EXPORTING
              handle      = lv_ftp_handle
              fname       = i_filename          "give required file name
            IMPORTING
              blob_length = lv_blob_length
            TABLES
              blob        = lt_dummy.
    Regards
    Sajid

  • How to show pdf or word icons for a BLOB column in a report?

    Hi,
    I am getting interested for the blob columns, I have created some columns for storing some pdf drawings and pictures for specific items in a table, it is ok to show a text like 'download' or any other text in the report by setting the following blob attribute:
    DOWNLOAD:TICKET_DETAILS:ATTACHMENT:TICKET_DETAILS_ID::MIME_TYPE:FILE_NAME:::inline:Download
    but instead of texts, I would like to show a small pdf image for my Blob file, or a word image or Excel image, according to the different file type.
    how to do that?
    and instead of inline or attachment this two options, I would like when the user click the image of the file, the browser will show the image in a new window, or a new browser tab.
    I tried the inline option for my file at Google Chrome, but when it showed the pdf file within the browser, I cannot get back to my app by clicking the 'backward' icon at the browser menu, it will stuck there and I have to close the broswer and then login to the app again, instead of simply returning back to the previous page within the app.
    Please help me out.
    Thanks
    Peter Yawei . Zhang

    Please try using a query like below for your report.
    SELECT ticket_details_id,
    CASE
       WHEN NVL(dbms_lob.getlength(attachment),0) = 0 THEN NULL
       ELSE
          CASE
             WHEN mime_type LIKE 'image%'
                THEN '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="/i/image_icon.gif" /></a>'
             WHEN mime_type = 'application/pdf'
                THEN '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="#IMAGE_PREFIX#menu/pdf_32.gif" /></a>'
             WHEN mime_type like '%ms-excel%'
                THEN '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="/i/excel_icon.gif" /></a>'
             WHEN mime_type like '%msword%'
                THEN '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="/i/word_icon.gif" /></a>'
             WHEN mime_type like '%ms-powerpoint%'
                THEN '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="/i/powerpoint_icon.gif" /></a>'
             ELSE '<a href="'||apex_util.get_blob_file_src('P101_ATTACHMENT',ticket_details_id)||'" target="_blank"><img src="/i/office_icon.gif" /></a>'
          END
    END attachment
    FROM ticket_details
    WHERE ticket_details_id = :P102_TICKET_DETAILS_IDPlease note that I am using APEX_UTIL.GET_BLOB_FILE_SRC function to download the BLOB files. The first parameter of this function in my example query is P101_ATTACHMENT, which refers to page item of type "File Browse" on page 101, which is a DML form on table TICKET_DETAILS. Replace it with the appropriate page number. Please refer to "Working With BLOBs Procedurally" section of this APEX 3.2 documentation for more: [url http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/advnc.htm#sthref2199]http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/advnc.htm#sthref2199
    Also I have the gif images representing various MIME types on my file server. For e.g., /i/excel_icon.gif. You can use #WORKSPACE_IMAGES# if you want to.

  • Saving report in excel format

    I need to save a report directly to excel format. The user does not want to open a delimited file in excel. After a lot of trials I got excel.prt file which supposedly saves the report in excel format directly from the PRINT TO FILE option.
    But I am still getting the option to save the file as text only, not in excel.
    Required help urgently as the report is important to the client

    We run reports using utl_http and then save the output as a blob. After that, we print the blob but before hand, we do this:
    owa_util.mime_header('application/vnd.ms-excel', false);
    htp.p('content-disposition: filename='||v_rec.filename||'.xls');
    owa_util.http_header_close;
    This sets the filename correctly and forces the browser to use Excel to handle the file.

Maybe you are looking for