Size of BLOB

Hello, I need to know the size of a BLOB type column . I use the function dbms_lob.getlength but it return a null. If I use this function to a field CLOB there works ok, the function return a value.
I am working in a Oracle Database 11g in RAC.
Any suggestions?
Thanks.

SELECT CaseOr, if you're hung up on that whole brevity thing use NVL() instead...
SQL> select file_name, dbms_lob.getlength(file_text) from t1blob
  2  /
FILE_NAME                      DBMS_LOB.GETLENGTH(FILE_TEXT)
test.csv                                                  64
not_a_file
empty_file                                                 0
SQL> select file_name, nvl(dbms_lob.getlength(file_text), -1) from t1blob
  2  /
FILE_NAME                      NVL(DBMS_LOB.GETLENGTH(FILE_TEXT),-1)
test.csv                                                          64
not_a_file                                                        -1
empty_file                                                         0
SQL> Note: I used -1 just to show that the value was populated by the NVL() call; in real life you should substitute 0.
Cheers, APC
blog: http://radiofreetooting.blogspot.com

Similar Messages

  • I want to reduse size of BLOB and display in jsp

    Please help me ,and if is possible than send me code for resize and display BLOB image injsp page

    Resizing: check the Java2D API. Tutorial.
    Displaying: create a servlet which writes the InputStream from the ResultSet to the OutputStream of the HttpServletResponse. Then call that servlet along an unique parameter in the <img> tag. Example.
    Resizing is a fairly expensive task, have you considered resizing it before saving in database? Then you need to do it only once.

  • Oracle Lite 10.3.0: how to find out the consumed size of a BLOB column

    Hi,
    we are developing an app that utilizes an Oracle Lite database and so far I have just been unable to find a reasonable way to determine the size of stored binary data.
    All the "usual" ways we aware of from "main" Oracle just don't seem to work with OLIte (ie SELECT dbms_lob.getlength(file_data) from APPS.CSL_LOBS) so how does one find out the size of blob objects?
    Thanks in advance

    Assuming BLOBs are not stored in-line:
    SQL> desc pm.print_media
    Name                                      Null?    Type
    PRODUCT_ID                                NOT NULL NUMBER(6)
    AD_ID                                     NOT NULL NUMBER(6)
    AD_COMPOSITE                                       BLOB
    AD_SOURCETEXT                                      CLOB
    AD_FINALTEXT                                       CLOB
    AD_FLTEXTN                                         NCLOB
    AD_TEXTDOCS_NTAB                                   PM.TEXTDOC_TAB
    AD_PHOTO                                           BLOB
    AD_GRAPHIC                                         BINARY FILE LOB
    AD_HEADER                                          PM.ADHEADER_TYP
    SQL> select  segment_name,
      2          index_name
      3    from  dba_lobs
      4    where owner = 'PM'
      5    and table_name = 'PRINT_MEDIA'
      6    and column_name = 'AD_COMPOSITE'
      7  /
    SEGMENT_NAME                   INDEX_NAME
    SYS_LOB0000051988C00003$$      SYS_IL0000051988C00003$$
    SQL> select  sum(bytes)
      2    from  dba_segments
      3    where owner = 'PM'
      4      and segment_name in (
      5                           'SYS_LOB0000051988C00003$$',
      6                           'SYS_IL0000051988C00003$$'
      7                          )
      8  /
    SUM(BYTES)
        262144
    SQL> SY.

  • How to modify the blob size, or how to set the size?

    i want to know how to modify the blob size, or how to set the size?
    what's the default size of blob?
    Thanks in advance.

    Blob datatype can contain binary data with a maximum size of 4 GB.
    when you enter 10kb file, the database will only use 10kb to store the file (depending on block size etc)
    if you want to modify the blob size, you may do like this:
    SQL> create materialized view t_mv refresh fast on commit
    2 as select id, dbms_lob.getlength(x) len from t;
    Materialized view created.
    SQL> alter table t_mv add constraint t_mv_chk check (len < 100);
    Table altered.

  • BLOB Size in portal

    Hi
    I have a portal form contains a blob field.
    Sometimes It returns error during uploading the file:
    Error: An unexpected error occurred: ORA-01401: inserted value too large for column (WWV-16016)
    I know the maximum size of blob is about 4G and my file is about 100K
    Any suggestion about that?
    Thanks
    Shahram
    null

    Which version of portal are you using

  • Toplink with mysql: problem with blob size

    I'm using toplink with a mysql database. I want to store some data in a blob.
    In mysql there exist different sizes of blobs (in my case I need a mediumblob).
    But if I create the scheme for the database with jpa/toplink it alway creates only a column with type blob.
    I can explicitly tell the database to use a mediumblob by this:
    @Column("MEDIUMBLOB")
    But by doing this I limit my program to mysql of course, as this data type is not known to other databases.
    Does anybody know a more elegant solution to setting the blob size?
    for example with hibernate it can be done this way:
    @Column(length=666666)

    Looks like you are using JPA, and in JPA you would set the columnDefinition to the type that you want, e.g.
    @Lob
    @Column(name="BLOBCOL", columnDefinition="MEDIUMBLOB")
    byte[] myByteData;
    As you mentioned, this does introduce a dependency on the database. However, you can always either put the Column metadata in XML, or override it with something else later in XML.
    The length attribute was intended and specified for use with Strings but I guess there is no reason why it couldn't be used for BLOBs as well (please enter an enhancement request, or submit the code to add the feature to EclipseLink). Be aware, though, that doing so at this stage is going to be introducing a dependency on the provider to support a non-spec defined feature.

  • How to increase BLOB size ?? (default is only 4000)

    hi how can i increase Size of blob data type?? , because default size is 4000, but i dont know where can i change it . I try console and also SQL Developer but there is no possibility choose size of Blob data type. thanks mato

    Subject: Oracle 10G Large Object (LOB) Data Type Changes
    Doc ID: Note:263389.1 Type: BULLETIN
    Last Revision Date: 06-MAY-2004 Status: PUBLISHED
    Large Object (LOB) Data Type Changes
    ====================================
    Prior to Oracle10G, the maximum size of the LOB data types (BLOB, CLOB and NCLOB)
    was 4GB.
    Oracle10g has increased the size of LOBs substantially. The new maximum size of LOBs
    is [(4GB -1) X (DB_BLOCK_SIZE)]. Currently the database block size allows ranges
    from 2KB to 32KB, hence the LOB size limit ranges from 8TB to 128TB.
    These larger LOBs can be used with all APIs in the DBMS_LOB PL/SQL package.
    Message was edited by:
    LC

  • Select query taking 30 sec to fetch data from table containing BLOB column.

    Hi Friends,<o:p></o:p>
    Please help me...<o:p></o:p>
    I have 15 columns in a table, in that 2 columns containing blob (images).<o:p></o:p>
    More than 22 lakhs records are in a table.<o:p></o:p>
    While i am try to fetch data from this table it nearly takes 25~30 sec to execute that query.<o:p></o:p>
    When i deleted the two columns containing blob and i tried its executing fast .<o:p></o:p>
    I should not change the table schema.<o:p></o:p>
    Views also i created and indexes also there in a table.<o:p></o:p>
    How can i improve the query execution speed?.<o:p></o:p>

    And how large is the size of BLOB data in your table? If it's several giga bytes, then the time is simply required to read the amount of data from disk and to transfer it to the Client.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Need  URGENT help with BLOB!!!!

    Hi,
    I am using a certain java server that has the capability of persisting objects to permanent storage (Oracle 8.1.5.0 in my case).
    The server automatically creates all necessary tables, and some of them have columns of BLOB datatypes in them.
    Then server retrieves a row of data and attempts to figure out how big is the size of the single BLOB record.
    All these queries are in xml configuration files and the server's java code uses them to access the database. I can not modify the datatypes during table creation without modifying actual server code, which I don't want to do for obvious reasons. I can't use stored procedures to figure out the size of the BLOB either for the same reason.
    Now here is the problem:
    Some of the logic of the code depends on queries that are supposed to return the size of BLOB data. Queries look like this:
    SELECT DATALENGTH(col_a)
    FROM table_A
    WHERE col_b = 'something'
    and of course col_a is in table_A and its datatype is BLOB (The sql above works on MS SQL).
    IS THERE AN EQUIVALENT OF datalength() IN ORACLE?
    I have unsuccessfully tried LENGTH(blob), which throws ORA-00932 inconsistent datatypes error. Also tried octet-length(), BLOB SIZE() with same results (different error: ORA-00923 FROM keyword not found where expected).
    Any ideas?
    Your help is greatly appreciated,
    Gugo M

    Thank you so much!
    Looks very simple (probably is for a dba).
    Thanks again.
    Gugo

  • BLOB Insertion Problem

    We are inserting a BLOB in our table. If the size of BLOB is greater than 5KB, it's not being inserted. Smaller BLOBs are being entered successfully. Is ther some default parameter which need to be set.

    AFAIK there is no such initialization parameter.
    How do you insert BLOB ? Which is the host language ?
    Which use case described in http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96591/adl10pst.htm#125074 is the closest to the one you are using ?

  • Upload to BLOB

    How can you do an upload into a blob using ADF/JSP/Struts? I've seen the demo for OrdDoc but would rather have the blob as it would be easier to move between instances over a db link (cannot do with object type).
    Thoughts/tips/code?
    I can provide what does NOT work...

    Here is the code I am using (Error message first):
    Target URL -- http://10.141.146.47:8988/UploadedFiles-ViewController-context-root/uploadDocument.do
    06/12/19 07:49:45 Oracle Application Server Containers for J2EE 10g (10.1.2.0.2) initialized
    Dec 19, 2006 7:49:45 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    Dec 19, 2006 7:49:45 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
    Dec 19, 2006 7:49:45 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='uploadedfiles.view.ApplicationResources', returnNull=true
    06/12/19 07:49:48 *** UploadDocumentAction.findForward() ***
    Dec 19, 2006 7:49:48 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    Dec 19, 2006 7:49:48 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    Dec 19, 2006 7:49:48 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
    Dec 19, 2006 7:49:48 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    Dec 19, 2006 7:49:48 AM org.apache.struts.util.PropertyMessageResources <init>
    INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true
    06/12/19 07:49:55 *** UploadDummyBlobAction.onUpload - START ***
    06/12/19 07:49:55 myrow.getId() = null
    06/12/19 07:49:56 myrow.getFilename() = null
    06/12/19 07:49:56 java.lang.NullPointerException
    06/12/19 07:49:56 at uploadedfiles.view.UploadDocumentAction.onUpload(UploadDocumentAction.java:82)
    06/12/19 07:49:56 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    06/12/19 07:49:56 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    06/12/19 07:49:56 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    06/12/19 07:49:56 at java.lang.reflect.Method.invoke(Method.java:324)
    06/12/19 07:49:56 at oracle.adf.controller.lifecycle.PageLifecycle.handleEvent(PageLifecycle.java:544)
    06/12/19 07:49:56 at oracle.adf.controller.struts.actions.StrutsPageLifecycle.handleEvent(StrutsPageLifecycle.java:252)
    06/12/19 07:49:56 at oracle.adf.controller.lifecycle.PageLifecycle.processComponentEvents(PageLifecycle.java:477)
    06/12/19 07:49:56 at oracle.adf.controller.struts.actions.DataAction.processComponentEvents(DataAction.java:235)
    06/12/19 07:49:56 at oracle.adf.controller.struts.actions.DataAction.processComponentEvents(DataAction.java:430)
    06/12/19 07:49:56 at oracle.adf.controller.lifecycle.PageLifecycle.handleLifecycle(PageLifecycle.java:126)
    06/12/19 07:49:56 at oracle.adf.controller.struts.actions.DataAction.handleLifecycle(DataAction.java:222)
    06/12/19 07:49:56 at oracle.adf.controller.struts.actions.DataAction.execute(DataAction.java:153)
    06/12/19 07:49:56 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    06/12/19 07:49:56 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    06/12/19 07:49:56 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    06/12/19 07:49:56 at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    06/12/19 07:49:56 at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    06/12/19 07:49:56 at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    06/12/19 07:49:56 at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    06/12/19 07:49:56 at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
    06/12/19 07:49:56 at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
    06/12/19 07:49:56 at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:239)
    06/12/19 07:49:56 at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:659)
    06/12/19 07:49:56 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330)
    06/12/19 07:49:56 at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830)
    06/12/19 07:49:56 *** UploadDocumentAction.findForward() ***
    06/12/19 07:49:56 UploadDocumentAction.findForward()- event : Upload
    06/12/19 07:49:56 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:285)
    06/12/19 07:49:56 at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:126)
    06/12/19 07:49:56 at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    06/12/19 07:49:56 at java.lang.Thread.run(Thread.java:534)
    public class UploadDocumentAction extends DataForwardAction {
    protected void processUpdateModel(DataActionContext actionContext) {
    super.processUpdateModel(actionContext);
    // Create a blank record in the model and set it as the current row
    BindingContext bc = actionContext.getBindingContext();
    DCDataControl dc = bc.findDataControl("UploadedFilesServiceDataControl");
    UploadedFilesService service = (UploadedFilesService)dc.getDataProvider();
    service.insertRowIntoUploadedFilesView();
    * public void onUpload( DataActionContext ctx )
    * This handles uploading a file into a blob domain by use of a
    * transient view attribute (TempOrdDoc) and then getting the uploaded
    * file (which is passivated to the oc4j's ordpas folder) and then placing
    * this via input/output stream calls into a BlobDomain to place into the
    * view object's row.
    * Processing Steps:
    * 1. Get access to the current row of the iterator and cast it to an
    * exposed client interface. This allows easier placement of the
    * values into the record.
    * 2. Get access to the TempOrdDoc and retrieve the file source content.
    * this appears to contain the ORD IM passivated blob,ie:
    * C:\jdev1012\jdev\system10.1.2.0.0.1811\oc4j-config\ordpas\ord10858pas
    * 3. Create input stream to this object and output stream to the view
    * object's blob, then read/write the data.
    * 4. Set the view object columns: Content Type, Size, and Blob. Note that
    * we have to get the description from the request to set it.
    * 5. Get access to the application module, then commit the transaction.
    * @param ctx
    public void onUpload( DataActionContext ctx ) {
    System.out.println("*** UploadDocumentAction.onUpload - START ***");
    HttpServletRequest request = ctx.getHttpServletRequest();
    try {
    DCBindingContainer bc = ctx.getBindingContainer();
    DCIteratorBinding iter = bc.findIteratorBinding("UploadedFilesView1Iterator");
    Row r = iter.getCurrentRow();
    UploadedFilesViewRowClient myrow = (UploadedFilesViewRowClient) r;
    System.out.println("myrow.getId() = " + myrow.getId());
    System.out.println("myrow.getFilename() = " + myrow.getFilename());
    OrdDocDomain doc = myrow.getTempOrdDocDomain();
    OrdContentSource ocontent = doc.getContentSource();
    OrdFileSource fSource = (OrdFileSource) ocontent;
    System.out.println( "fSource.getContentLength()=" + fSource.getContentLength());
    System.out.println( "fSource.getFileName()=" + fSource.getFileName() );
    System.out.println( "fSource.getMimeType()=" + fSource.getMimeType() );
    InputStream istream = fSource.getInputStream();
    BlobDomain blob = myrow.getContent();
    int bufsize;
    if ( blob == null ) {
    blob = new BlobDomain();
    bufsize = 32767;
    } else {
    bufsize = blob.getBufferSize();
    r.lock(); // required for a blob update.
    OutputStream out = blob.getBinaryOutputStream();
    int length = 0;
    byte buf[] = new byte[bufsize];
    while ((istream != null) && ((length = istream.read(buf)) != -1)) {
    out.write(buf, 0, length);
    System.out.println("read " + length + " bytes from in, writing to out");
    istream.close();
    out.flush();
    out.close();
    myrow.setContent( blob );
    BindingContext bctx = ctx.getBindingContext();
    DCDataControl dc = bctx.findDataControl("UploadedFilesServiceDataControl");
    UploadedFilesService service = (UploadedFilesService)dc.getDataProvider();
    service.saveRowUploadedFilesView();
    catch ( Exception ex )
    // required by fSource.getInputStream();
    ex.printStackTrace();
    } // onUpload
    protected void findForward(DataActionContext actionContext) throws Exception {
    System.out.println("*** UploadDocumentAction.findForward() ***");
    // Try to catch errors instead of the default error handler.
    try {
    List events = actionContext.getEvents();
    if (events != null && events.size() > 0) {
    ListIterator li = events.listIterator();
    while (li.hasNext()) {
    System.out.println("UploadDocumentAction.findForward()- event : " + li.next().toString());
    } catch (Exception e) {
    System.out.println(e.getMessage() );
    e.printStackTrace(System.out);
    super.findForward(actionContext);
    /* UploadedFilesViewRowClient.java */
    public class UploadedFilesViewRowClient extends RowImpl
    * This is the default constructor (do not remove)
    public UploadedFilesViewRowClient() {}
    public oracle.jbo.domain.Number getId() {
    return (oracle.jbo.domain.Number)getAttribute("Id");
    public void setId(oracle.jbo.domain.Number value) {
    setAttribute("Id", value);
    public String getFilename() {
    return (String)getAttribute("Filename");
    public void setFilename(String value) {
    setAttribute("Filename", value);
    public oracle.jbo.domain.BlobDomain getContent() {
    return (oracle.jbo.domain.BlobDomain)getAttribute("Content");
    public void setContent(oracle.jbo.domain.BlobDomain value) {
    setAttribute("Content", value);
    public oracle.jbo.domain.Date getDateCreated() {
    return (oracle.jbo.domain.Date)getAttribute("DateCreated");
    public void setDateCreated(oracle.jbo.domain.Date value) {
    setAttribute("DateCreated", value);
    public oracle.ord.im.OrdDocDomain getTempOrdDocDomain() {
    return (oracle.ord.im.OrdDocDomain)getAttribute("TempOrdDocDomain");
    public void setTempOrdDocDomain(oracle.ord.im.OrdDocDomain value) {
    setAttribute("TempOrdDocDomain", value);
    /* UploadedFilesServiceImpl.java */
    public void insertRowIntoUploadedFilesView() {
    //vo is your view object
    ViewObject vo = getUploadedFilesView1();
    Row aRow = vo.createRow();
    aRow.setNewRowState(Row.STATUS_INITIALIZED);
    /* Do these get populated automatically? Yes! since setup in entity as historical */
    vo.insertRow(aRow);
    vo.setCurrentRow(aRow);
    // getTransaction().commit();
    public void saveRowUploadedFilesView() {
    //vo is your view object
    ViewObject vo = getUploadedFilesView1();
    getTransaction().commit();
    ...

  • Export BLOB into Files

    Hi, I want to export BLOB data into normal files in the OS. The Database is not in my local server. I can only connect through the TNS. Would you please give me some suggestions? Thanks a lot!

    declare
    l_output utl_file.file_type;
    l_amt number default 32000;
    l_offset number default 1;
    l_length number default nvl(dbms_lob.getlength(p_blob),0); -- l_length = size of blob
    begin
    l_output := utl_file.fopen(p_dir, p_file, 'w', 32760);
    if utl_file.is_open(l_output) then
    while ( l_offset < l_length ) loop
    utl_file.put(l_output,
    UTL_RAW.CAST_TO_VARCHAR2(dbms_lob.substr(p_blob,l_amt,l_offset)));
    utl_file.fflush(l_output);
    l_offset := l_offset + l_amt;
    end loop;
    utl_file.new_line(l_output);
    utl_file.fclose(l_output);
    end if;
    end;

  • Basic doubt on BLOB/CLOB

    In Oracle 10g, the max size for BLOB/CLOB is mentioned as 4GB.
    If i store a binary file of size 2MB in a BLOB field, will it block the whole 4GB (4096MB) space for this. Or as like Varchar only the actual file size is used and leave the remaining 4094 MB as free.
    Please clarify.

    Could not resist it... here's a docu link to info about new LOB handling.

  • How to reduce size of AW Space?

    Hi,
    I want to reduce size of AW Space. It means size of BLOB in tablespace.
    1) My AW Space have 60 GB
    2) I have deleted all of variables data
    but AW Space (used space of tablespace) is still 60 GB.
    Is it possible to reduce its size.
    Thanks Vasek.

    Its probably retaining the space used by the largest variable that you had.
    Try the following trick:
    Do the following:
    AW attach rwx
    make a trivial change such as make a change to a scalar variable you’ve created
    e.g.
    define my_var variable int
    my_var = 1
    Update
    Commit;
    my_var=2
    Update
    commit;
    If this is 10g you don't need to do the last 3 steps (ie the second change).

  • Encounter ORA-01002 when calling OCIStmtFetch2 to fetch blob data

    Oracle Version:Release 10.2.0.1.0
    Description:
    We use these two functions to fetch the content of blob field dynamically in batch mode:
    OCIDefineByPos(OCI_DYNAMIC_FETCH)
    OCIDefineDynamic(callbackfun->cbf_get_data)
    We allocate fixed memory to fetch data in order to using compact memory.
    If the size of blob to be fetched is larger than the allocated memory size, the fetch can not be done in one call, which need to be interrupted.
    Those records would remain in cache and can only be fetched until calling OCIStmtFetch2 next time.
    The callback function:cbf_get_data, achieves this by returning OCI_ROWCBK_DONE, which marks current fetch interrupted.
    It would not return OCI_CONTINUE, because OCI_CONTINUE can not interrupt current fetch procedure in time.
    We made a sample code test, and found this logic only works when fetching small rows (nearly 800 rows). Exceptions occurred when fetching more rows(>=1000 rows).
    For example, among these 2 cases,
    1.(OCIStmtFetch2(m_stmthp,m_errhp,(ub4)800,OCI_FETCH_NEXT,(sb4)OCI_FETCH_RELATIVE,OCI_DEFAULT)
    2.(OCIStmtFetch2(m_stmthp,m_errhp,(ub4)1000,OCI_FETCH_NEXT,(sb4)OCI_FETCH_RELATIVE,OCI_DEFAULT)
    only the 1st one work, but the 2nd.
    After function cbf_get_data returns OCI_ROWCBK_DONE, calling OCIStmtFetch2 did not enter into callback function cbf_get_data.
    And OCIErrorGet showed such error:
    ORA-01002: fetch out of sequence
    the total number of result set is about 100,000.
    We tried to set PREFETCH to a larger value in this way::
    OCIAttrSet(m_stmthp,OCI_HTYPE_STMT,(dvoid *)&rnum,0,OCI_ATTR_PREFETCH_ROWS,m_errhp);
    rtn=OCIAttrSet((dvoid *)m_stmthp, (ub4) OCI_HTYPE_STMT,(dvoid *)&preFetch, (ub4)sizeof(preFetch), OCI_ATTR_PREFETCH_MEMORY,m_errhp);
    but it did not help.
    Waiting for you guidance.
    Thanks in advance!
    -Andy
    Edited by: Andy Tong on 2010-10-22 上午12:29

    Here is our testing Code:
    #include "oci.h"
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #pragma comment(lib,"oci.lib")
    char buf1[5000];
    char buf2[5000];
    long datalen=5000;
    ub4 outpos=1;
    ub4 outpos2=2;
    int sum=0;
    int sum2=0;
    OCIError *m_errhp;
    OCIStmt *m_stmthp;
    char      LOBBuf[8006];
    long      LOBLen=8006;
    long     gindpp=0;
    ub2     grcpp=0;
    #define MAX_ROW_NUM 56338
    /* Fetch callback to specify buffers. */
    sb4 cbf_get_data(     dvoid*          ctxp,
                             OCIDefine*     dfnhp,
                             ub4               iter,
                             dvoid**          bufpp,
                             ub4**          alenpp,
                             ub1*          piecep,
                             dvoid**          indpp,
                             ub2**          rcpp)
         if(iter==0)
              sum=0;
         else if(iter>=858) //857 exception
              //LOBBuf,LOBLen
              //     sum+=LOBLen;
              //     if(sum>1057552-100*1024)
              sum=0;
              bufpp=(dvoid)0;
              alenpp=(ub4)0;
              *piecep = (ub1)OCI_ONE_PIECE;
              indpp = (dvoid ) 0;
              rcpp     = (ub2 ) 0;
              return(OCI_ROWCBK_DONE);     
         LOBLen=8006;
         bufpp=(dvoid)LOBBuf;
         alenpp=(ub4)&LOBLen;
         *piecep = (ub1)OCI_ONE_PIECE;
         indpp = (dvoid )&gindpp;
         rcpp     = (ub2 )&grcpp;
         return(OCI_CONTINUE);     
    BOOL CTest_ociApp::InitInstance()
         OCIEnv *          m_envhp;
         OCIServer *          m_srvhp;
         OCISvcCtx *          m_svchp;
         sword               rtn;
         char               sqlState[256];
         int               nativeErr;
         char               errTxt[256];
         unsigned long          bufLen=256;
         OCIDefine hDefine =  (OCIDefine ) 0;
         OCIDefine hDefine1 = (OCIDefine ) 0;
         OCIDefine hDefine2 = (OCIDefine ) 0;
         OCIDefine hDefine3 = (OCIDefine ) 0;
         OCIDefine hDefine4 = (OCIDefine ) 0;
         int i;
         OCILobLocator** lob_array;
         char username[255];
         char password[30];
         char dbname[30];
         char szSqlStr[255];
         ub4 preFetch= 10*1024*16;
         strcpy(username,"dlg25w");
         strcpy(password,"sa");
         strcpy(dbname,"WIN10G");
         OCIEnvCreate(&m_envhp, OCI_DEFAULT | OCI_OBJECT, 0, 0, 0, 0, 0, 0);
         OCIHandleAlloc( (dvoid *)m_envhp, (dvoid **)&m_errhp,OCI_HTYPE_ERROR,(size_t) 0, (dvoid **) 0);
         OCIHandleAlloc( (dvoid *)m_envhp, (dvoid **)&m_srvhp,OCI_HTYPE_SERVER,(size_t) 0, (dvoid **) 0);
         OCIHandleAlloc( (dvoid *)m_envhp, (dvoid **)&m_svchp,OCI_HTYPE_SVCCTX,(size_t) 0, (dvoid **) 0);
         OCIHandleAlloc( (dvoid *)m_envhp, (dvoid **)&m_stmthp,OCI_HTYPE_STMT,(size_t) 0, (dvoid **)0);
         OCIServerAttach(m_srvhp, m_errhp,(text *)dbname, strlen(dbname),(ub4) OCI_DEFAULT);
         OCILogon(m_envhp,m_errhp,&m_svchp,(text *)username,strlen(username),(text *)password,strlen(password),(text *)dbname,strlen(dbname));
         ub4     rnum=0;
         unsigned int len=0;
         //rtn=OCIAttrGet(m_envhp,OCI_HTYPE_ENV,(dvoid *)&rnum,&len,OCI_ATTR_CACHE_MAX_SIZE,m_errhp);
         OCIErrorGet((dvoid *) m_errhp,(ub4)1,(OraText *)sqlState,&nativeErr,(unsigned char*)errTxt,bufLen,(ub4) OCI_HTYPE_ERROR);
         len=4;
         rnum=83886080;
         rtn=OCIAttrSet(m_envhp,OCI_HTYPE_ENV,(dvoid *)&rnum,len,OCI_ATTR_CACHE_OPT_SIZE,m_errhp);
         rtn=OCIAttrGet(m_envhp,OCI_HTYPE_ENV,(dvoid *)&rnum,&len,OCI_ATTR_CACHE_OPT_SIZE,m_errhp);
         OCIErrorGet((dvoid *) m_errhp,(ub4)1,(OraText *)sqlState,&nativeErr,(unsigned char*)errTxt,bufLen,(ub4) OCI_HTYPE_ERROR);
         rnum=2000;
         sprintf( szSqlStr,"%s", "SELECT DATA FROM MF4");
         OCIStmtPrepare(m_stmthp, m_errhp, (text*)szSqlStr, (ub4)strlen(szSqlStr),(ub4) OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
    OCIAttrSet(m_stmthp,OCI_HTYPE_STMT,(dvoid *)&rnum,0,OCI_ATTR_PREFETCH_ROWS,m_errhp);
         /* initialize array of locators */
         OCIDefineByPos(m_stmthp, &hDefine2, m_errhp, (ub4)1,(dvoid *)0,(sb4)8006,SQLT_BIN,(dvoid *)0, (ub2 *)0, (ub2 *)0,(ub4) OCI_DYNAMIC_FETCH);//OCI_DYNAMIC_FETCH
         OCIDefineDynamic(hDefine2, m_errhp, (dvoid *)&outpos,(OCICallbackDefine)cbf_get_data);
         OCIStmtExecute(m_svchp, m_stmthp, m_errhp,(ub4)0, (ub4) 0,(const OCISnapshot*) 0,
              (OCISnapshot*)0,(ub4)OCI_DEFAULT);//OCI_STMT_SCROLLABLE_READONLY
         rtn=OCIAttrSet((dvoid *)m_stmthp, (ub4) OCI_HTYPE_STMT,(dvoid *)&preFetch, (ub4)sizeof(preFetch), OCI_ATTR_PREFETCH_MEMORY,m_errhp);
         while(1)
              rtn=OCIStmtFetch2(m_stmthp,m_errhp,(ub4)1000,OCI_FETCH_NEXT,(sb4)OCI_FETCH_RELATIVE,OCI_DEFAULT);
              OCIErrorGet((dvoid *) m_errhp,(ub4)1,(OraText *)sqlState,&nativeErr,(unsigned char*)errTxt,bufLen,(ub4) OCI_HTYPE_ERROR);
              if(rtn==OCI_NO_DATA)
                   break;
              else
         t0=GetTickCount()-t0;
         t0=0;
         OCIAttrGet((CONST void *)m_stmthp,OCI_HTYPE_STMT,(void *)&rows_fetched,(ub4 *)sizeof(rows_fetched),OCI_ATTR_ROW_COUNT ,m_errhp);
         printf("\n Total number of records:%d",rows_fetched);
         OCILogoff( m_svchp, m_errhp );
         OCIServerDetach( m_srvhp, m_errhp, OCI_DEFAULT );
         OCIHandleFree((dvoid *) m_stmthp, OCI_HTYPE_STMT);
         OCIHandleFree((dvoid *) m_svchp, OCI_HTYPE_SVCCTX);
         OCIHandleFree((dvoid *) m_srvhp, OCI_HTYPE_SERVER);
         OCIHandleFree((dvoid *) m_errhp, OCI_HTYPE_ERROR);
         getchar();
         return FALSE;
    }

Maybe you are looking for