Can't fetch clob and long in one select/query

I created a nightmare table containing numerous binary data types to test an application I was working on, and believe I have found an undocumented bug in Oracle's JDBC drivers that is preventing me from loading a CLOB and a LONG in a single SQL select statement. I can load the CLOB successfully, but attempting to call ResultSet.get...() for the LONG column always results in
java.sql.SQLException: Stream has already been closed
even when processing the columns in the order of the SELECT statement.
I have demonstrated this behaviour with version 9.2.0.3 of Oracle's JDBC drivers, running against Oracle 9.2.0.2.0.
The following Java example contains SQL code to create and populate a table containing a collection of nasty binary columns, and then Java code that demonstrates the problem.
I would really appreciate any workarounds that allow me to pull this data out of a single query.
import java.sql.*;
This class was developed to verify that you can't have a CLOB and a LONG column in the
same SQL select statement, and extract both values. Calling get...() for the LONG column
always causes 'java.sql.SQLException: Stream has already been closed'.
CREATE TABLE BINARY_COLS_TEST
PK INTEGER PRIMARY KEY NOT NULL,
CLOB_COL CLOB,
BLOB_COL BLOB,
RAW_COL RAW(100),
LONG_COL LONG
INSERT INTO BINARY_COLS_TEST (
PK,
CLOB_COL,
BLOB_COL,
RAW_COL,
LONG_COL
) VALUES (
1,
'-- clob value --',
HEXTORAW('01020304050607'),
HEXTORAW('01020304050607'),
'-- long value --'
public class JdbcLongTest
public static void main(String argv[])
throws Exception
Driver driver = (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
DriverManager.registerDriver(driver);
Connection connection = DriverManager.getConnection(argv[0], argv[1], argv[2]);
Statement stmt = connection.createStatement();
ResultSet results = null;
try
String query = "SELECT pk, clob_col, blob_col, raw_col, long_col FROM binary_cols_test";
results = stmt.executeQuery(query);
while (results.next())
int pk = results.getInt(1);
System.out.println("Loaded int");
Clob clob = results.getClob(2);
// It doesn't work if you just close the ascii stream.
// clob.getAsciiStream().close();
String clobString = clob.getSubString(1, (int)clob.length());
System.out.println("Loaded CLOB");
// Streaming not strictly necessary for short values.
// Blob blob = results.getBlob(3);
byte blobData[] = results.getBytes(3);
System.out.println("Loaded BLOB");
byte rawData[] = results.getBytes(4);
System.out.println("Loaded RAW");
byte longData[] = results.getBytes(5);
System.out.println("Loaded LONG");
catch (SQLException e)
e.printStackTrace();
results.close();
stmt.close();
connection.close();
} // public class JdbcLongTest

The problem is that LONGs are not buffered but are read from the wire in the order defined. The problem is the same as
rs = stmt.executeQuery("select myLong, myNumber from tab");
while (rs.next()) {
int n = rs.getInt(2);
String s = rs.getString(1);
The above will fail for the same reason. When the statement is executed the LONG is not read immediately. It is buffered in the server waiting to be read. When getInt is called the driver reads the bytes of the LONG and throws them away so that it can get to the NUMBER and read it. Then when getString is called the LONG value is gone so you get an exception.
Similar problem here. When the query is executed the CLOB and BLOB locators are read from the wire, but the LONG is buffered in the server waiting to be read. When Clob.getString is called, it has to talk to the server to get the value of the CLOB, so it reads the LONG bytes from the wire and throws them away. That clears the connection so that it can ask the server for the CLOB bytes. When the code reads the LONG value, those bytes are gone so you get an exception.
This is a long standing restriction on using LONG and LONG RAW values and is a result of the network protocol. It is one of the reasons that Oracle deprecates LONGs and recommends using BLOBs and CLOBs instead.
Douglas

Similar Messages

  • Can I sync podcasts and ITunesU. from one computer to another that both have the same acount.

    Can I sync podcasts and ITunesU. from one computer to another that both have the same account.

    No.  Time Machine won't get your boot camp partition back.  There are excellent utilities that move entire hard drive contents among hard drives such as SuperDuper! and CCC, but as far as I know they don't work with boot camp partition.  My suggestion: reinstall Mac OSX on your new Mac (you don't want to hold Option key to start it everytime anyway), partition it with boot camp exactly (or similarly) as you did to your previous Mac (install the same operating system, which should be one of the Microsoft Windows I assume).  Use Migration Assistant as kaz-k suggested to move all the stuff on the Mac partition of your previous Mac.  Reboot both your Macs from the boot camp partition - I assume they are all on Windows platform.  Now you have two computers on Windows platform.  Use Norton Ghost or similar tools to migrate all the stuff from your old machine to your new machine.  Hope this helps.  Backup all your data before such operation.  Good luck.

  • Can I move music and movies from one icloud account to another icloud account?

    Can I move music and movies from one icloud account to another of my icloud accounts?

    No.  Purchased music, movies and other iTunes media is permanently tied to the Apple ID used to purchase it and can't be transferred to another ID.  (Your purchases are stored in iTunes in the Cloud under the Apple ID used to purchase them.)

  • I have 2 icloud accounts, can I merge them and just keep one?

    I have 2 icloud accounts, can I merge them and just keep one?

    The simple answer is no
    But some info can be saved and merged.
    When your signed into one account, sign out and save the data you can, to the device.
    Sign into the other account and merge the info.
    Best of Luck

  • I am getting dump error while running one report in one select query

    Hi,
    While running a report program, I am getting a dump error in one select query. So could you please correct the select query so that I can't face the dump error.
    SELECT vbeln parvw kunnr INTO CORRESPONDING FIELDS OF TABLE l_t_vbpa
      FROM vbpa
      FOR ALL ENTRIES IN l_t_backorder_item
      WHERE vbeln = l_t_backorder_item-vbeln AND
      ( ( parvw = c_we AND kunnr IN rng_shipto ) OR  ( parvw = c_ag AND
      kunnr IN rng_soldto ) ) .
    <removed by moderator>
    Best Regards,
    BDP
    Edited by: Thomas Zloch on Apr 30, 2010 12:31 PM

    Hi Bansidhar,
    It would be helpful if you could tell what type of dump it is.
    If it is a timeout you should check whether l_t_backorder_item is empty - in this case ALL document numbers are selected. f you get the timeout with a populated table consider converting the l_t_backorder_item table into one ore more ranges tables - the select with ranges tables is way quicker than 'for all entries'. But take care the ranges table has not to many entries - the SAP SQL converter puts this into one huge SQL statement and this might become too big to be handled by the database (depends on the actual underlying database).
    I would also consider splitting the SELECT into two (2nd one with 'appending into table') to make the code easier to understand It also helps the database system determining a strategy for the select.
    Regards,
    Gerd Rother

  • What can i do for removing SINGLE in this select query??

    What can i do for removing SINGLE in this select query given below and also NOT USE 'ENDSELECT'??
    I have defined g_t_zv7_cachemapping as following ::
    DATA : BEGIN OF g_t_zv7_cachemapping OCCURS 0,
             kostl LIKE zv7_cachemapping-kostl,
             END OF g_t_zv7_cachemapping.
    SELECT SINGLE kostl FROM zv7_cachemapping INTO g_t_zv7_cachemapping
               WHERE  auart = g_t_vbak-auart.
            IF sy-subrc = 0 .
            ENDIF.

    Shashank,
    DATA : BEGIN OF g_t_zv7_cachemapping OCCURS 0,
    AUART LIKE zv7_cachemapping-AUART,
    kostl LIKE zv7_cachemapping-kostl,
    END OF g_t_zv7_cachemapping.
    If not g_t_vbak[] is initial.
    SELECT auart kostl
      FROM zv7_cachemapping INTO table g_t_zv7
    for all entries in g_t_vbak
    WHERE auart = g_t_vbak-auart.
    Endif.
    sort : g_t_zv7 by auart , 
              g_t_vbak by auart.
    loop at g_t_vbak.
      READ TABLE g_t_zv7 WITH KEY AUART = g_t_vbak-AUART
                                        BINARY SEARCH.
       IF sy-subrc eq 0.
       ENDIF.
    endloop.
    Pls. reward if useful

  • Can we handle exceptions for the expressions in select query?

    Hi all,
    Can we handle exceptions for the expressions in select query.
    I created a view, there I am extracting a substring from a character data and expected that as a number.
    For example consider the following query.
    SQL> select to_number( substr('r01',2,2) ) from dual;
    TO_NUMBER(SUBSTR('R01',2,2))
    1
    Here we got the value as "1".
    Consider the following query.
    SQL> select to_number( substr('rr1',2,2) ) from dual;
    select to_number( substr('rr1',2,2) ) from dual
    ORA-01722: invalid number
    For this I got error. Because the substr returns "r1" which is expected to be as number. So it returns "Invalid number".
    So, without using procedures or functions can we handle these type of exceptions?
    I am using Oracle 10 G.
    Thanks in advance.
    Thank you,
    Regards,
    Gowtham Sen.

    SQL> select decode(ltrim(rtrim(translate(substr('r21', 2, 2), '0123456789', ' ' ), ' '), ' '), null, (substr('r21', 2, 2)), null) from dual;
    DE
    21
    SQL> ed a
    SQL> select decode(ltrim(rtrim(translate(substr('rr1', 2, 2), '0123456789', ' ' ), ' '), ' '), null, (substr('rr1', 2, 2)), null) from dual;
    D
    -

  • Joining two tables having no common fields using one select query

    Hi Experts,
    How to join two tables which are NOT having any field in common using only one select query?
    Your help will be appreciated.
    Thank you.

    Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
    If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
    Regards,
    Raymond

  • I upgraded from iPhone 3GS to iPhone 6.  Everything converted fine until I deleted an app in error.  When I downloaded it from iTunes, my account is no longer recognized by the app's host servers.  Can I go back and re-sync one app from my old phone?

    I upgraded from iPhone 3GS to iPhone 6.  Everything converted fine.  Yesterday I deleted an app in error.  When I downloaded the software it from iTunes ( did this many times on the old 3GS), my account is no longer recognized by the app's host servers (Playtika), even though it did after the initial conversion.  Can I go back and re-sync just one app from my old phone?  

    Try deleting what is called the iPod Photo Cache. 
    http://support.apple.com/kb/TS1314

  • CLOB and LONG datatypes

    I have a problem with needing to display fields in a report that are stored in the database as CLOB.
    The report isn't too complicated, and can be put together using folders in Admin.
    There is a table in the database that stores text from reports. Each report is identified by its case id, and then there may be a number of reports for each case (let's say 1-5 for the purposes of this explaination). There will then be three sections of text in each report, identifed in the database by section numbers.
    The fields needed are the case number (case_id), the report number (report_no), the section number (sect_no) and the section text (sect_text)
    All of the fields are numeric, except sect_text, which is a CLOB datatype.
    There are two queries, one to select the case id, min report number and first section of text and the other to select the case id, max report number and last section of text. The aim being a report that shows the start of the first report and the end of the last one.
    So, that's the background. All of the queries to select the data work fine in sqlplus. However they can't be displayed in Disco because it brings in CLOB fields as LONG, and can't group them (which it has to do for the MAX and MIN)
    I'd rather not set the whole thing up as a view on the DB, as I'd prefer to have the flexibiility of editing it in discoverer
    Any tips?

    Hi
    I do have a tip. Please take a look at this thread that I was involved in a couple of years ago:
    CLOB show up as item
    And here is another one that might help:
    Possible for Discoverer to display BLOB type documents stored in database?
    Best wishes
    Michael

  • Mapping CLOB and Long in xml schema

    Hi,
    I am creating an xml schema to map some user defined database objects. For example, for a column which is defined as VARCHAR2 in the database, I have the following xsd type mapping.
    <xsd:element name="Currency" type="xsd:string" />
    If the oracle column is CLOB or Long(Oracle datatype), could you please tell me how I can map it in the xml schema? I do not want to use Oracle SQL type like:
    xdb:SQLType="CLOB" since I need a generic type mapping to CLOB. Would xsd:string still hold good for CLOB as well as Long(Oracle datatype) ?
    Please help.
    Thanks,
    Vadi.

    The problem is that LONGs are not buffered but are read from the wire in the order defined. The problem is the same as
    rs = stmt.executeQuery("select myLong, myNumber from tab");
    while (rs.next()) {
    int n = rs.getInt(2);
    String s = rs.getString(1);
    The above will fail for the same reason. When the statement is executed the LONG is not read immediately. It is buffered in the server waiting to be read. When getInt is called the driver reads the bytes of the LONG and throws them away so that it can get to the NUMBER and read it. Then when getString is called the LONG value is gone so you get an exception.
    Similar problem here. When the query is executed the CLOB and BLOB locators are read from the wire, but the LONG is buffered in the server waiting to be read. When Clob.getString is called, it has to talk to the server to get the value of the CLOB, so it reads the LONG bytes from the wire and throws them away. That clears the connection so that it can ask the server for the CLOB bytes. When the code reads the LONG value, those bytes are gone so you get an exception.
    This is a long standing restriction on using LONG and LONG RAW values and is a result of the network protocol. It is one of the reasons that Oracle deprecates LONGs and recommends using BLOBs and CLOBs instead.
    Douglas

  • New owner here.  How can I select specific pages of a document found on line and print just those pages.  What I see is the ability to select only 1 page at a time and print that one selected page only.   Thanks much.

    New owner here.  I see that in printing I can select one page and print same.  How do I select numerous pages from a document and print only those selected pages? I would not think that I can only select one page at a time.  Thanks much

    Just change the range as illustrated below.  If you don't see that, click the Show Details button.

  • Display short, medium, and long text in a query

    Hi all, we have a requirement to display the short, medium, and long text of an info-object in our queries.  Currently, it seems that you can only select one text lenght at a time but not all three of them together.  Aside from creating texts as attributes, is there a way to display all of the texts of an info-object?
    For example, we have internal orders with 3 texts.  When we run the query, we need to see the order number, then the short text, medium text, and long text.  Is this possible?
    thanks
    Kory Squire

    yeah you are right, we can get all the texts as attributes. Other than that you can only get any one of them.

  • Internal table with same variable and one select query

    Hi,
    I am a new bee here with may be a silly question.
    I have a internal table as below.
    DATA: BEGIN OF IT_ORDERDETAILS OCCURS 0,
            VBELN LIKE VBAK-VBELN,        "Order number
            BSTNK LIKE VBAK-BSTNK,        "customer PO
            ERDAT LIKE VBAK-ERDAT,        " Order created date
            MATNR LIKE VBAP-MATNR,        "Sales order line item
            KWMENG LIKE VBAP-KWMENG,      "Quantity
            D_VBELN like likp-vbeln,      " delivery no
            POSNR like lips-posnr,        " delivery item
            KUNNR LIKE LIKP-KUNNR,        "ship quantity
      END OF IT_ORDERDETAILS.
    Where VBELN field is in VBAK and LIKP table.
    VBELN in VBAK table = order #
    VBELN in LIKP table is = Delivery #
    I want to use join to fetch data in single select query.
    Below is the select query
    SELECT VBAK~VBELN
            VBAK~BSTNK
            VBAK~ERDAT
            VBAP~MATNR
            VBAP~KWMENG
            likp~vbeln
            lips~posnr
            LIPS~VGBEL
          INTO (IT_ORDERDETAILSvbak, IT_ORDERDETAILSbstnk,     IT_ORDERDETAILSerdat, IT_ORDERDETAILSmatnr, IT_ORDERDETAILSkwmeng, IT_ORDERDETAILSd_vbeln,IT_ORDERDETAILSposnr, IT_ORDERDETAILSkunnr)
    FROM VBAK left outer JOIN VBAP ON ( VBAKVBELN = VBAPVBELN )
    left outer JOIN LIPS ON ( VBAKVBELN = LIPSVGBEL )
      join LIKP on ( LIPSVBELN = LIKPVBELN )
    WHERE VBAK~ERDAT IN CR_DATE.
    I am getting error in the query.
    Please suggest.
    Thanks,
    Rajesh

    Hi rajesh.nayakbola,
    although this is not quite the right place for this, let me give you some notes:
    1. Code should be
    formatted as code
    by markin it with mouse and use above &lt;&gt; button.
    2. Internal tables shoult not be declared using OCCURS clause - this is last century style
    3. Internal tables do not need and should not have a header line, they should use TYPES for declaration
    4. Data should not be declared using LIKE: If they refer to dictionary TYPES, use TYPE. LIKE is only mandatory for data objects declared in your program, i.e. DATA IT_some_ORDERDETAILS like IT_ORDERDETAILS.
    5. If you get an error here, never write "I am getting error" but copy and paste the error message fully.
    - The fields in brackets in  the INTO clause never have ~ character, there is no IT_ORDERDETAILS~vbak, only IT_ORDERDETAILS-vbeln
    It could be something like this:
    TYPES:
      BEGIN OF TY_ORDERDETAILS,
      VBELN TYPE VBAK-VBELN, "Order number
      BSTNK TYPE VBAK-BSTNK, "customer PO
      ERDAT TYPE VBAK-ERDAT, " Order created date
      MATNR TYPE VBAP-MATNR, "Sales order line item
      KWMENG TYPE VBAP-KWMENG, "Quantity
      D_VBELN TYPE likp-vbeln, " delivery no
      POSNR TYPE lips-posnr, " delivery item
      KUNNR TYPE LIKP-KUNNR, "ship quantity
    END OF TY_ORDERDETAILS.
    DATA:
      IT_ORDERDETAILS TYPE TABLE OF TY_ORDERDETAILS.
    SELECT VBAK~VBELN
      VBAK~BSTNK
      VBAK~ERDAT
      VBAP~MATNR
      VBAP~KWMENG 
      likp~vbeln AS D_VBELN
      lips~posnr
      LIKP~KUNNR
    INTO CORRSPONDING FIELDS OF TABLE IT_ORDERDETAILS
    FROM VBAK left outer JOIN VBAP ON ( VBAK~VBELN = VBAP~VBELN )
      left outer JOIN LIPS ON ( VBAK~VBELN = LIPS~VGBEL )
      join LIKP on ( LIPS~VBELN = LIKP~VBELN )
    WHERE VBAK~ERDAT IN CR_DATE.
    Regards,
    Clemens

  • Can columns be more than 1000 in a select query (oracle 11 g)

    I am getting this error: "ORA-01792: maximum number of columns in a table or view is 1000"
    I have a dynamic query where number of column can increase according to the user input.
    They can expect more than 1000 columns. Is it possible to fetch more than 1000 rows in a query?
    I appreciate all your help.
    Edited by: user10232912 on Apr 26, 2012 2:07 AM

    >
    They can expect more than 1000 columns.
    Then they are idiots. IMO.
    Open challenge. Show me an entity with a 1000 attributes and I will show you a flawed data
    model and a total lack of grasping fundamentals of implementing that into a relation database product like Oracle.I second that - as someone who once had to ETL a system which had a table with 35.000 fields - that's 35K.
    It was a system which made extensive use of arrays - and arrays of arrays of arrays...
    Paul...

Maybe you are looking for