ORA-01704 inserting xmltype.

HI.
How can I do to make this insert works? I am getting Error SQL: ORA-01704: literal de cadena demasiado largo
01704. 00000 -  "string literal too long"
*Cause:    The string literal is longer than 4000 characters.
*Action:   Use a string literal of at most 4000 characters.
           Longer values may only be entered using bind variables.
Insert into BF_MOTORPAGOS.BF_MTP_FRA_TEMPLATEBODY (FTB_TEMPLATEBODYID,FTB_TEMPLATEREFID,FTB_TYPEFORMATID,FTB_TYPESTRUCTUREID,FTB_STRUCTUREBODY,FTB_STRUCTUREBODYXML,FTB_STATE) values ('4','2','2','7',sys.xmltype('<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
  <mapping name="estructura de encabezados" lineainicio="01" lote="05" transaccion="06" lotefin="08" lineafinal="09" nit="NitEmpresaPrincipal" identificador="NumIdCliente" fecha="fechacreacion" AGREEMENT="83" TEMPLATEREFERENCE="2" TYPEFORMAT="2"/>
  <code value="01" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="NitEmpresaPrincipal" inicio="3" fin="12" longitud="10" type="integer" requerido="1"/>
    <item name="NitEmpresaAdicional" inicio="13" fin="22" longitud="10" type="integer" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="23" fin="25" longitud="3" type="string" requerido="0"/>
    <item name="fechacreacion" inicio="26" fin="33" longitud="8" type="date" requerido="1"/>
    <item name="horagrabacion" inicio="34" fin="37" longitud="4" type="string" requerido="1"/>
    <item name="ModificadorArchivo" inicio="38" fin="38" longitud="1" type="string" requerido="1"/>
    <item name="reservado" inicio="39" fin="220" longitud="182" type="string" requerido="0"/>
  </code>
  <code value="05" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="CodServicio" inicio="3" fin="15" longitud="13" type="integer" requerido="1"/>
    <item name="NumLote" inicio="16" fin="19" longitud="4" type="integer" requerido="1"/>
    <item name="DescripcionServicio" inicio="20" fin="34" longitud="15" type="string" requerido="1"/>
    <item name="reservado" inicio="35" fin="220" longitud="186" type="string" requerido="0"/>
  </code>
  <code value="06" longitud="220" interrumpe="0">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="RefUsuario" inicio="3" fin="50" longitud="48" type="integer" requerido="1"/>
    <item name="RefSecUsuario" inicio="51" fin="80" longitud="30" type="string" requerido="0"/>
    <item name="PeriodosFacturados" inicio="81" fin="82" longitud="2" type="integer" requerido="0"/>
    <item name="Ciclo" inicio="83" fin="85" longitud="3" type="string" requerido="0"/>
    <item name="ValorServicioPrincipal" inicio="86" fin="99" longitud="14" type="integer" requerido="1"/>
    <item name="CodServFactAd" inicio="100" fin="112" longitud="13" type="string" requerido="0"/>
    <item name="VlrServAd" inicio="113" fin="126" longitud="14" type="decimal" requerido="0"/>
    <item name="fechaven" inicio="127" fin="134" longitud="8" type="date" requerido="1"/>
    <item name="idefr" inicio="135" fin="142" longitud="8" type="integer" requerido="0"/>
    <item name="NumCtaClienteReceptor" inicio="143" fin="159" longitud="17" type="string" requerido="1"/>
    <item name="TipoCtaClienteReceptor" inicio="160" fin="161" longitud="2" type="integer" requerido="0"/>
    <item name="NumIdCliente" inicio="162" fin="171" longitud="10" type="string" requerido="0"/>
    <item name="NomClteReceptor" inicio="172" fin="193" longitud="22" type="string" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="194" fin="196" longitud="3" type="integer" requerido="0"/>
    <item name="reservado" inicio="197" fin="220" longitud="24" type="string" requerido="0"/>
  </code>
  <code value="08" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegLote" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="ValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="ValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="NLote" inicio="48" fin="51" longitud="4" type="integer" requerido="1"/>
    <item name="reservado" inicio="52" fin="220" longitud="169" type="string" requerido="0"/>
  </code>
  <code value="09" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegDetalle" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="TotalValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="TotalValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="reservado" inicio="48" fin="220" longitud="173" type="string" requerido="0"/>
  </code>
</root>')
    ,sys.xmltype('<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
  <mapping name="estructura de encabezados" lineainicio="01" lote="05" transaccion="06" lotefin="08" lineafinal="09" nit="NitEmpresaPrincipal" identificador="NumIdCliente" fecha="fechacreacion" AGREEMENT="2" TEMPLATEREFERENCE="2" TYPEFORMAT="2"/>
  <code value="01" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="NitEmpresaPrincipal" inicio="3" fin="12" longitud="10" type="integer" requerido="1"/>
    <item name="NitEmpresaAdicional" inicio="13" fin="22" longitud="10" type="integer" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="23" fin="25" longitud="3" type="string" requerido="0"/>
    <item name="fechacreacion" inicio="26" fin="33" longitud="8" type="date" requerido="1"/>
    <item name="horagrabacion" inicio="34" fin="37" longitud="4" type="string" requerido="1"/>
    <item name="ModificadorArchivo" inicio="38" fin="38" longitud="1" type="string" requerido="1"/>
    <item name="reservado" inicio="39" fin="220" longitud="182" type="string" requerido="0"/>
  </code>
  <code value="05" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="CodServicio" inicio="3" fin="15" longitud="13" type="integer" requerido="1"/>
    <item name="NumLote" inicio="16" fin="19" longitud="4" type="integer" requerido="1"/>
    <item name="DescripcionServicio" inicio="20" fin="34" longitud="15" type="string" requerido="1"/>
    <item name="reservado" inicio="35" fin="220" longitud="186" type="string" requerido="0"/>
  </code>
  <code value="06" longitud="220" interrumpe="0">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="RefUsuario" inicio="3" fin="50" longitud="48" type="integer" requerido="1"/>
    <item name="RefSecUsuario" inicio="51" fin="80" longitud="30" type="string" requerido="0"/>
    <item name="PeriodosFacturados" inicio="81" fin="82" longitud="2" type="integer" requerido="0"/>
    <item name="Ciclo" inicio="83" fin="85" longitud="3" type="string" requerido="0"/>
    <item name="ValorServicioPrincipal" inicio="86" fin="99" longitud="14" type="integer" requerido="1"/>
    <item name="CodServFactAd" inicio="100" fin="112" longitud="13" type="string" requerido="0"/>
    <item name="VlrServAd" inicio="113" fin="126" longitud="14" type="decimal" requerido="0"/>
    <item name="fechaven" inicio="127" fin="134" longitud="8" type="date" requerido="1"/>
    <item name="idefr" inicio="135" fin="142" longitud="8" type="integer" requerido="0"/>
    <item name="NumCtaClienteReceptor" inicio="143" fin="159" longitud="17" type="string" requerido="1"/>
    <item name="TipoCtaClienteReceptor" inicio="160" fin="161" longitud="2" type="integer" requerido="0"/>
    <item name="NumIdCliente" inicio="162" fin="171" longitud="10" type="string" requerido="0"/>
    <item name="NomClteReceptor" inicio="172" fin="193" longitud="22" type="string" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="194" fin="196" longitud="3" type="integer" requerido="0"/>
    <item name="reservado" inicio="197" fin="220" longitud="24" type="string" requerido="0"/>
  </code>
  <code value="08" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegLote" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="ValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="ValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="NLote" inicio="48" fin="51" longitud="4" type="integer" requerido="1"/>
    <item name="reservado" inicio="52" fin="220" longitud="169" type="string" requerido="0"/>
  </code>
  <code value="09" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegDetalle" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="TotalValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="TotalValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="reservado" inicio="48" fin="220" longitud="173" type="string" requerido="0"/>
  </code>
</root>'),'1');

You can either :
1- enclose the INSERT statement in an anonymous PL/SQL block and use XMLType variables to pass XML content to the INSERT. You'll be able to use string literal up to 32767 bytes, it should be sufficient for this case.
2- split the XML string into multiple CLOB chunks of max. 4000 bytes, e.g.
xmltype(
to_clob('<?xml version="1.0" encoding="ISO-8859-15"?>
<root>
  <mapping name="estructura de encabezados" lineainicio="01" lote="05" transaccion="06" lotefin="08" lineafinal="09" nit="NitEmpresaPrincipal" identificador="NumIdCliente" fecha="fechacreacion" AGREEMENT="83" TEMPLATEREFERENCE="2" TYPEFORMAT="2"/>
  <code value="01" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="NitEmpresaPrincipal" inicio="3" fin="12" longitud="10" type="integer" requerido="1"/>
    <item name="NitEmpresaAdicional" inicio="13" fin="22" longitud="10" type="integer" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="23" fin="25" longitud="3" type="string" requerido="0"/>
    <item name="fechacreacion" inicio="26" fin="33" longitud="8" type="date" requerido="1"/>
    <item name="horagrabacion" inicio="34" fin="37" longitud="4" type="string" requerido="1"/>
    <item name="ModificadorArchivo" inicio="38" fin="38" longitud="1" type="string" requerido="1"/>
    <item name="reservado" inicio="39" fin="220" longitud="182" type="string" requerido="0"/>
  </code>
  <code value="05" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="CodServicio" inicio="3" fin="15" longitud="13" type="integer" requerido="1"/>
    <item name="NumLote" inicio="16" fin="19" longitud="4" type="integer" requerido="1"/>
    <item name="DescripcionServicio" inicio="20" fin="34" longitud="15" type="string" requerido="1"/>
    <item name="reservado" inicio="35" fin="220" longitud="186" type="string" requerido="0"/>
  </code>
  <code value="06" longitud="220" interrumpe="0">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="RefUsuario" inicio="3" fin="50" longitud="48" type="integer" requerido="1"/>
    <item name="RefSecUsuario" inicio="51" fin="80" longitud="30" type="string" requerido="0"/>
    <item name="PeriodosFacturados" inicio="81" fin="82" longitud="2" type="integer" requerido="0"/>
    <item name="Ciclo" inicio="83" fin="85" longitud="3" type="string" requerido="0"/>
    <item name="ValorServicioPrincipal" inicio="86" fin="99" longitud="14" type="integer" requerido="1"/>
    <item name="CodServFactAd" inicio="100" fin="112" longitud="13" type="string" requerido="0"/>
    <item name="VlrServAd" inicio="113" fin="126" longitud="14" type="decimal" requerido="0"/>
    <item name="fechaven" inicio="127" fin="134" longitud="8" type="date" requerido="1"/>
    <item name="idefr" inicio="135" fin="142" longitud="8" type="integer" requerido="0"/>
    <item name="NumCtaClienteReceptor" inicio="143" fin="159" longitud="17" type="string" requerido="1"/>
    <item name="TipoCtaClienteReceptor" inicio="160" fin="161" longitud="2" type="integer" requerido="0"/>
    <item name="NumIdCliente" inicio="162" fin="171" longitud="10" type="string" requerido="0"/>
    <item name="NomClteReceptor" inicio="172" fin="193" longitud="22" type="string" requerido="0"/>
    <item name="CodEntidadFinancieraOrigen" inicio="194" fin="196" longitud="3" type="integer" requerido="0"/>
    <item name="reservado" inicio="197" fin="220" longitud="24" type="string" requerido="0"/>
  </code>
  <code value="08" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegLote" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="ValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="ValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="NLote" inicio="48" fin="51" longitud="4" type="integer" requerido="1"/>
    <item name="reservado" inicio="52" fin="220" longitud="169" type="string" requerido="0"/>
  </code>') || to_clob('
  <code value="09" longitud="220" interrumpe="1">
    <item name="TipoRegistro" inicio="1" fin="2" longitud="2" type="string" requerido="1"/>
    <item name="TotalRegDetalle" inicio="3" fin="11" longitud="9" type="integer" requerido="1"/>
    <item name="TotalValorServicioPrincipal" inicio="12" fin="29" longitud="18" type="decimal" requerido="1"/>
    <item name="TotalValorServicioAdicional" inicio="30" fin="47" longitud="18" type="decimal" requerido="0"/>
    <item name="reservado" inicio="48" fin="220" longitud="173" type="string" requerido="0"/>
  </code>
</root>')
3- use external files :
xmltype(bfilename('XML_DIR', 'FTB_STRUCTUREBODY.xml'), nls_charset_id('WE8ISO8859P15'))
Option #3 would be my choice most of the time to insert large XML content.

Similar Messages

  • ORA-01704: string literal too long (URGENT)

    Folks,
    I get error - ORA-01704: string literal too long,
    when trying to insert a value >4k into the SDIDOC column of the table below:
    CREATE TABLE "B1"."SDI_XML_TAB"
    ( "SDIID" VARCHAR2(60 BYTE) NOT NULL ENABLE,
    "SDIDOC" "SYS"."XMLTYPE" ,
    CONSTRAINT "SDI_XML_TAB_PK" PRIMARY KEY ("SDIID")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "B1SYSTEM" ENABLE
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "B1SYSTEM"
    XMLTYPE COLUMN "SDIDOC" STORE AS CLOB (
    TABLESPACE "B1SYSTEM" ENABLE STORAGE IN ROW CHUNK 16384 PCTVERSION 10
    NOCACHE LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)) ;
    The SQL I used using OCI was:
    "INSERT INTO SDI_XML_TAB(SDIID,SDIDOC) VALUES('ABC','clobVal')"
    What am I doing wrong?
    P.S. I also used the following and it gives the same error:
    "INSERT INTO SDI_XML_TAB(SDIID,SDIDOC) VALUES('ABC',XMLType('clobVal'))"
    Thanks,
    Arthur
    Message was edited by:
    ArthurJohnson

    Check this cool-bi.com

  • Error message :ORA-01704: string literal too long

    Hello:
    I need your help. I have a long long string must be insert to
    database. I use long data type and long varchar data type to
    define table. But I got the error messages is ORA-01704: string
    literal too long when I insert data. Please tell me the solution.
    Thank you so so much.

    Hello,
    I have a table with a column "XML_Data" of type CLOB.
    I am trying to insert XML of the size 59975. I
    get a error message ORA-01704: string literal too
    long.
    How to enter that large XML??
    Regards,
    Sanjeev.Try using Oracles XMLDB, by dropping the XML file into the XMLDB WebDAV area and then you can access it directly through the database "resource_view". No limits on file size whatsoever.
    If you're using XML within an Oracle database you're better off doing things this way as it gets stored in an XMLType column (sys.xmltype) which is a superset object of the CLOB datatype, providing all the object methods you need to navigate, update and query your XML. You won't be able to do much with it just sitting in a CLOB column without re-writing the wheel that Oracle have already built.
    ;)

  • ORA-01704 error while running dbms_sql for a clob

    Hi,
    I'm running following code and getiing error ORA-01704: string literal too long
    declare
    cursor_name INTEGER;
    t1 clob;
    t2 clob;
    r number;
    begin
    select a1 into t1 from temp
    where n1 = 'test';
    t2 := 'insert into temp (a1,n1) values (''' || t1 || ''',''test12'')' ;
    cursor_name := dbms_sql.open_cursor;
    DBMS_SQL.PARSE(cursor_name, t2, DBMS_SQL.NATIVE);
    r := DBMS_SQL.EXECUTE(cursor_name);
    DBMS_SQL.CLOSE_CURSOR(cursor_name);
    dbms_output.put_line(r);
    end;
    clob t1 is 32598 butes long.
    in temp table a1 is a clob.
    Could anyone please tell me why the error and how to solve the problem.
    Thanks
    Tarun

    This is one of the many posts over here where the OP can not be bothered to include the four digit version number.
    I can never understand why the version number is left out other than out of rudeness, arrogance and utter laziness.
    Apparently the small lot here responding should be clairvoyant and/or remember all version numbers.
    I'm going to call for a boycot of people posting without version number!!!!
    As to the code:
    There is no reason why you are using dbms_sql here, you are misusing Oracle, and it should have been static sql.
    At least t2 should have been a bind variable, dbms_sql does support bind variables!
    As far as I know the command string should be a varchar2, not a clob, and if t2 is a bind variable there is no need for t1 to be a clob.
    Sybrand Bakker
    Senior Oracle DBA

  • Using clobs and ORA-01704: string literal too long

    Hi,
    I am attempting to add oracle support to an existing J2ee application. The issue I am facing is the use of CLOB datatypes and the 4k string literal limitation that Oracle has.
    I have dowloaded the 10.2.0.3 thin driver and am connected to a 9i release 2 database. When I execute a statement such as the following (say the table has one varchar2 field and two clob fields
    Insert into my_table VALUES ('hi','something','pretend this string is 5000 characters')
    I still receive the error
    java.sql.SQLException: ORA-01704: string literal too long
    I have read that the version 10 drivers were supposed to address this limitation. Is there something I am missing or must I change my home grown database layer to use bind variables or clob manipulation in a separate update/insert statement.? I am trying to avoid this situation since the database layer works fine for the situation of MSSQL and text fields which have no such limitation.
    Any advice you have here is greatly appreciated.
    Thanks,
    Joe

    Hi,
    I am attempting to add oracle support to an existing J2ee application. The issue I am facing is the use of CLOB datatypes and the 4k string literal limitation that Oracle has.
    I have dowloaded the 10.2.0.3 thin driver and am connected to a 9i release 2 database. When I execute a statement such as the following (say the table has one varchar2 field and two clob fields
    Insert into my_table VALUES ('hi','something','pretend this string is 5000 characters')
    I still receive the error
    java.sql.SQLException: ORA-01704: string literal too long
    I have read that the version 10 drivers were supposed to address this limitation. Is there something I am missing or must I change my home grown database layer to use bind variables or clob manipulation in a separate update/insert statement.? I am trying to avoid this situation since the database layer works fine for the situation of MSSQL and text fields which have no such limitation.
    Any advice you have here is greatly appreciated.
    Thanks,
    Joe

  • PL-SQL-ORA-01704 - String literal too long

    Hello guyz;
    I am trying to store a value of over 4000 character long in a CLOB column and I got the error message that says "PL-SQL-ORA-01704 - String literal too long".
    What can I do to overcome this challenge?
    Thanking you for your usual support.

    sb92075 wrote:
    Problem Exists Between Keyboard And Chair
    We can't say what you are doing wrong since we don't know specifically what you actually do.Okay let me put it down this way.
    I have an application using SQL Server as d backend engine & now, the user wants to migrate to Oracle. I now wrote a mini-program to create a schema/user in oracle with the schema/database (being used by the app) from SQL server. I verified the structure very well & every is just fine. Now, data migration (from SQL Server to Oracle).
    I was able to move most tables data successfully without issue until I attempted to load a table which has a column (in SQL defined as text with over 4000 (var)chars/CLOB in Oracle). On moving a particular row to oracle db (after few rows have already been INSERTed into this particular table x), I got that err msg.
    After battling with that for a while, I concluded to make d (DataMigrator) app take just d first 4000 string - only if the value in that field value length > 4000. This worked perfectly without issue but you know the implication - Data lost.
    Do I need to switch something on/off in Oracle that expands the CLOB default maximum field size? Because I foresee this happening as soon as the application (that would now sit on Oracle) is now in use.
    If you still don't understand this, I don't know how beta 2 explain this!
    Edited by: aweklin on Mar 17, 2013 8:25 AM
    Edited by: aweklin on Mar 17, 2013 8:25 AM
    Edited by: aweklin on Mar 17, 2013 8:27 AM
    Edited by: aweklin on Mar 17, 2013 8:27 AM

  • "ORA-01704: string literal too long" in Oracle 10g

    I would like to explain my problem with an example, let's create the following table:
    CREATE TABLE longtest
    (text LONG);
    I have to insert lots of data into this table and when I run this command:
    INSERT INTO LONGTEST VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    ..................more than 4000 characters..................
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
    I get the following error:
    ORA-01704: string literal too long
    To workaround this, I used bind variables, like this:
    BEGIN
    EXECUTE IMMEDIATE 'INSERT INTO LONGTEST VALUES (:a) '
    using
    'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    ..............(repeat more than 32768 characters)..............
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
    COMMIT;
    END;
    This worked fine with Oracle 9.2.0.4 but when I do the same thing
    in Oracle 10.2.0.2 there is a 32768 characters limit.
    I am planning to upgrade the database but I need a workaround for
    this, anyone knows why Oracle behaves differently in 10g??

    So, I wonder if anyone can explain why the following code works fine in Oracle 9.2.0.4 but not in Oracle 10.2.0.2:
    CREATE TABLE longtest
    (text LONG);
    BEGIN
    EXECUTE IMMEDIATE 'INSERT INTO LONGTEST VALUES (:a) '
    using
    'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    ..............(repeat more than 32768 characters)..............
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
    COMMIT;
    END;
    Regards,
    Cassiano

  • SQL Error: ORA-01704: string literal too long

    select * from table(fn_split('some 10000 characters with comma separation .........................'))
    Error report:
    SQL Error: ORA-01704: string literal too long
    01704. 00000 - "string literal too long"
    *Cause:    The string literal is longer than 4000 characters.
    *Action:   Use a string literal of at most 4000 characters.
    how to pass my 10k record string

    933663 wrote:
    The string is through a user interface.So, that interface is using what datatype for the string? What language is the interface written in?
    insert into table
    select * from table(fn_split('2,4,2,5,7'));Do you understand what a string literal is? You cannot provide a varchar2 string that exceeds 4000 bytes from within SQL. Fact. It just cannot be done.
    If you are passing the string from a user interface using a datatype that supports more than 4000 bytes, and you pass it directly to PL/SQL code by calling the function or procedure directly (not using SQL) then you can use up to 32767 bytes for your VARCHAR2.
    The code you've posted (which happens to be some of my own code posted years ago on these forums) takes a VARCHAR2 as an input. You would have to change that to accept a CLOB datatype and work on the CLOB instead. However, you still wouldn't be able to pass in a string literal of more than 4000 bytes from SQL for it.
    Looking at your other thread: Seperate the string value
    ... it looks like the 'user' is trying to pass in a table definition. What is it your application is trying to do? Surely you are not trying to create a table at run time?
    So explain, what is the business issue you are trying to solve? We may be able to provide a better way of doing it.

  • ORA-01704: string literal too long for CLOB colum

    Hi,
    I'm trying to execute sql script containing a lot of insert into statements.
    Insert into table (clob_column) values ("value of 5500 characters");
    I get the below error message. Please let me know how do resolve this issue without PL/SQL ?
    ORA-01704: string literal too long

    Hi,
    LOB columns store locators that reference the location of the actual LOB value. Depending on the column properties you specify when you create the table, and depending the size of the LOB, actual LOB values are stored either in the table row (inline) or outside of the table row (out-of-line).
    LOB values are stored out-of-line when any of the following situations apply:
    •If you explicitly specify DISABLE STORAGE IN ROW for the LOB storage clause when you create the table.
    •If the size of the LOB is greater than approximately 4000 bytes (4000 minus system control information), regardless of the LOB storage properties for the column.
    •If you update a LOB that is stored out-of-line and the resulting LOB is less than approximately 4000 bytes, it is still stored out-of-line.
    LOB values are stored inline when any of the following conditions apply:
    •When the size of the LOB stored in the given row is small, approximately 4000 bytes or less, and you either explicitly specify ENABLE STORAGE IN ROW or the LOB storage clause when you create the table, or when you do not specify this parameter (which is the default).
    •When the LOB value is NULL (regardless of the LOB storage properties for the column).
    Read this for more details..
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28393/adlob_tables.htm

  • [ORA-01704: string literal too long] in a long xquery

    I get an error when using queries with xmlquery.
    If the quoted string part is longest than 4000 chr then I get
    ORA-01704: string literal too long.
    Example...
    select xmlquery(
    ' <Root >
         {for $xxx in ora:view("ttttttt")
            let $nnn := $xxx/ROW/nnn/number()
    [total chr>4000] '
    RETURNING CONTENT)
    from dual
    Is it really not possible to write Oracle xmlqueries longest than 4000chr or there's a workaround for it?

    I got similary problem using the OCCI to insert record in my table.
    I have a BLOB field in my table and whenever I quote an HEX string that is bigger than 4000 chars I get the error: ORA-01704: string literal too long
    To sort that problem I have to pass to the prepared SQL statement, but now I got a new problem for which I do not have solution.
    I write here the piece of C++ code to insert and the error I get hoping somebody can help me.
    I have problem to write into a Blob object.
    I get the error: ORA-22275: Invalid LOB Locator Specified.
    The error occurs when I try to write into the blob variable:
    blobField.writeChunk(....
    Routine:
    void insert2 (void) throw (SQLException)
    cout << "=== Prepare Statement ===" << endl;
    Statement* stmtIns = occiConn->createStatement("insert into test_tab values (:1,:2,:3,:4,:5)");
    cout << "=== Prepare the Blob data ===" << endl;
    // Prepare all Blobs in an array of char.
    char* data[5];
    ub2 dataLen[5];
    int i;
    for (i = 0; i < 5; i++)
    data[i] = new char[16364];
    memset(data, 65+i, 16364);
    dataLen[i] = 16364;
    cout << "=== Assign the other fields ===" << endl;
    stmtIns->setInt(1, i + 10);
    stmtIns->setInt(2, i + 1000);
    stmtIns->setInt(3, i + 10000);
    stmtIns->setInt(4, i + 20);
    // Assign the blob field
    Blob blobField(occiConn);
    blobField.setEmpty();
    cout << "=== Opening the blob field in read/write mode ===" << endl;
    blobField.open(OCCI_LOB_READWRITE);
    cout << "=== Writing data into the blob ===" << endl;
    blobField.writeChunk(dataLen[0], reinterpret_cast<unsigned char*>(data[0]), dataLen[0], 1);
    blobField.close();
    cout << "=== Done ===" << endl;
    stmtIns->setBlob(5, blobField);
    cout << "=== Execute the iteration ===" << endl;
    stmtIns->executeUpdate();
    for (i = 0; i < 5; i++)
    delete [] data[i];
    stmtIns->executeUpdate("COMMIT");
    occiConn->terminateStatement(stmtIns);

  • Exception in thread "main" java.sql.SQLException: ORA-01704: string literal

    Hi Everyone,
    I am Using This Code to read the Mail from server and inserting those into database but i am getting error like
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import java.sql.*;
    public class ReadMail_OLD {
    static StringBuffer s= new StringBuffer();
    static StringBuffer s1= new StringBuffer();
    public static void main(String args[]) throws Exception {
    String host = "***.****.co.in";
    String user = "***@***.**.**";
    String password = "******";
    String Message_2000 = new String();
    String Message_2001 = new String();
    Connection conn;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@1.2.3.5:1050:abcgdb", "abc", "efg");
    Statement stm = conn.createStatement();
    String strsql = "insert into READ_MAIL_MSG (MESSAGE_ID,SENT_DATE,MAIL_FROM,MAIL_TO,MAIL_SUBJECT,MESSAGE) values (" ;
    // Get system properties
    Properties properties = System.getProperties();
    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);
    // Get a Store object that implements the specified protocol.
    Store store = session.getStore("pop3");
    //Connect to the current host using the specified username and password.
    store.connect(host, user, password);
    //Create a Folder object corresponding to the given name.
    Folder folder = store.getFolder("inbox");
    // Open the Folder.
    folder.open(Folder.READ_ONLY);
    Message[] message = folder.getMessages();
    // Display message.
    for (int i = 0; i < message.length; i++)
    //System.out.println("------------ Message " + (i + 1) + " ------------");
    //System.out.println("SentDate : " + message.getSentDate());
    //System.out.println("From : " + message[i].getFrom()[0]);
    //System.out.println("Subject : " + message[i].getSubject());
    //System.out.print("Message : ");
    InputStream stream = message[i].getInputStream();
    int j = 0;
    Message_2000 = "";
    Message_2001 = "";
    while(stream.available()>0 && j < 500)
    // read the byte and convert the integer to character
    s.append((char) stream.read());
    j = j+1;
    Message_2000 = s.toString();
    Message_2001 = Message_2000.replace("'"," ");
    System.out.println(strsql+"'"+(i + 1)+"','"+message[i].getSentDate()+"','"+message[i].getFrom()[0]+"','***@***.co.in','"+message[i].getSubject()+"','"+s.toString()+"')");
    stm.execute(strsql+"'"+(i + 1)+"','"+message[i].getSentDate()+"','"+message[i].getFrom()[0]+"','***@****.co.in','"+message[i].getSubject()+"','"+Message_2001+"')");
    folder.close(true);
    store.close();
    when i execute this some messages get inserted into table but for some messages
    Exception in thread "main" java.sql.SQLException: ORA-01704: string literal too long
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1983)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1141)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2149)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2032)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2894)
    at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:942)
    at ReadMail_OLD.main(ReadMail_OLD.java:64)
    Edited by: 997089 on May 1, 2013 9:29 PM
    Edited by: 997089 on May 1, 2013 9:30 PM

    Hi All,
    Thanks for Your Reply .
    I got the answer i have made a mistake in loop after every iteration i have not cleared the stringBuffer Varaible so the after one or two iteration it givesthe error.
    import java.io.*;
    import java.util.*;
    import javax.mail.*;
    import java.sql.*;
    public class ReadMail_OLD {
    static StringBuffer s= new StringBuffer();
    static StringBuffer s1= new StringBuffer();
    public static void main(String args[]) throws Exception {
    String host = "***.****.co.in";
    String user = "***@***.**.**";
    String password = "******";
    String Message_2000 = new String();
    String Message_2001 = new String();
    Connection conn;
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@1.2.3.5:1050:abcgdb", "abc", "efg");
    Statement stm = conn.createStatement();
    String strsql = "insert into READ_MAIL_MSG (MESSAGE_ID,SENT_DATE,MAIL_FROM,MAIL_TO,MAIL_SUBJECT,MESSAGE) values (" ;
    // Get system properties
    Properties properties = System.getProperties();
    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);
    // Get a Store object that implements the specified protocol.
    Store store = session.getStore("pop3");
    //Connect to the current host using the specified username and password.
    store.connect(host, user, password);
    //Create a Folder object corresponding to the given name.
    Folder folder = store.getFolder("inbox");
    // Open the Folder.
    folder.open(Folder.READ_ONLY);
    Message[] message = folder.getMessages();
    // Display message.
    for (int i = 0; i < message.length; i++)
    //System.out.println("------------ Message " + (i + 1) + " ------------");
    //System.out.println("SentDate : " + message.getSentDate());
    //System.out.println("From : " + message.getFrom()[0]);
    //System.out.println("Subject : " + message.getSubject());
    //System.out.print("Message : ");
    InputStream stream = message.getInputStream();
    int j = 0;
    Message_2000 = "";
    Message_2001 = "";
    while(stream.available()>0 && j < 500)
    // read the byte and convert the integer to character
    s.append((char) stream.read());
    j = j+1;
    Message_2000 = s.toString();
    Message_2001 = Message_2000.replace("'"," ");
    System.out.println(strsql+"'"+(i + 1)+"','"message.getSentDate()"','"message.getFrom()[0]"','***@****.co.in','"message.getSubject()"','"s.toString()"')");
    stm.execute(strsql+"'"+(i + 1)+"','"message.getSentDate()"','"message.getFrom()[0]"','***@****.co.in','"message.getSubject()"','"Message_2001"')");
    s.delete(0, s.length());
    folder.close(true);
    store.close();
    Thanks for Reply
    Edited by: 997089 on May 1, 2013 9:28 PM
    Edited by: 997089 on May 1, 2013 9:30 PM

  • ORA-01704: string literal too long in Oracle 10.2.0.2

    We are running some Xqueries that are larger than 4k.
    Yesterday we were running on an Oracle 10.2.0.1 database, when we tried to run a large Xquery then we immediately got an ORA-01704 error.
    Since some messages on this forum indicate that in Oracle 10.2.0.2 this problem was solved, we patched the database this morning to level 10.2.0.2.
    At first everything seemd fine after that. The xquery had a type-mismatch and running the query resulted in a normal XP0003 syntax error. However, after we solved the type-mismatch in the query we got our old ORA-01704 error back.
    Might it be that the XMLQuery function now can handle larger input than 4k. but the parsing under water is still limited?
    And how can we solve this problem? It's urgent!
    By the way, the Xquery we used in this example is 5599 characters long.
    Hope to hear from you.
    Andre

    Hi,
    I faced the same problem and I created an EXE in .NET. I copied all my XML files in a directory named ReviewCaseXML and used the same to generate the script for all the xml files.
    class Migrate
    static void Main(string[] args)
    Console.Clear();
    string directorypath = ConfigurationManager.AppSettings["DirectoryPath"];
    string[] filePaths = Directory.GetFiles(directorypath, "*.xml");
    Array.Sort(filePaths);
    FileStream finalScript = null;
    File.Open(directorypath + "\\DBScript\\Final.sql", FileMode.Create);
    foreach (string file in filePaths)
    ProcessXMLFile(file);
    // ProcessXMLFile(directorypath + "\\CCV41E051v2 - Equipment Breakdown Clarification Clause (Amended).xml");
    Console.WriteLine("Complete. Press any key to exit.");
    Console.ReadKey();
    private static void ProcessXMLFile(string file)
    string endorsementName = string.Empty;
    XmlDocument doc = new XmlDocument();
    doc.Load(file);
    XmlNodeList varNodes = doc.SelectNodes("//var");
    foreach (XmlNode varNode in varNodes)
    foreach (XmlAttribute attrib in varNode.Attributes)
    if (attrib.Value.Equals("Name", StringComparison.InvariantCultureIgnoreCase))
    endorsementName = varNode.InnerText;
    if (!string.IsNullOrEmpty(endorsementName))
    GenerateScriptFileForXML(endorsementName, doc.OuterXml);
    public static void GenerateScriptFileForXML(string EndorsementName, string xml)
    int startingIndex;
    decimal fragmentCount;
    string fagmentToBeCopied;
    int fragmentLenght = 3000;
    fragmentCount = (Convert.ToDecimal(xml.Length) / Convert.ToDecimal(fragmentLenght));
    StringBuilder sb = new StringBuilder();
    sb.AppendFormat("SET DEFINE OFF {0}", Environment.NewLine);
    sb.AppendFormat("DECLARE TEMPLOB clob := '';{0}BEGIN {1}", Environment.NewLine, Environment.NewLine);
    sb.AppendFormat("dbms_lob.createtemporary(TEMPLOB, TRUE);{0}", Environment.NewLine);
    for (int ctr = 0; ctr < fragmentCount; ctr++)
    if (ctr == 0)
    startingIndex = ctr * fragmentLenght;
    else
    startingIndex = (ctr * fragmentLenght) ;
    if (ctr + 1 > fragmentCount)
    fragmentLenght = xmltobeScript.Length - (ctr * fragmentLenght );
    sb.Append("dbms_lob.append(TEMPLOB,'");
    fagmentToBeCopied = xmltobeScript.Substring(startingIndex, fragmentLenght);
    fagmentToBeCopied = fagmentToBeCopied.Replace("'", "''");
    sb.AppendFormat(fagmentToBeCopied);
    sb.AppendFormat("');{0}", Environment.NewLine);
    sb.AppendFormat("{0}Update ENDORSEMENTMASTER set THTEMPLATEXML = XMLTYPE(TEMPLOB) where ENDORSEMENTNAME='{1}';",Environment.NewLine, EndorsementName);
    sb.AppendFormat("{0} END ; {1}", Environment.NewLine, Environment.NewLine);
    sb.AppendFormat("COMMIT; {0} / {1}", Environment.NewLine, Environment.NewLine);
    SaveFile(EndorsementName + ".sql", ConfigurationManager.AppSettings["DirectoryPath"], sb.ToString());
    public static void SaveFile(string filename, string directory, string data)
    try
    filename = filename.Replace("/", "");
    StreamWriter stringWriter = new StreamWriter(directory + "\\DBScript\\" + filename);
    stringWriter.Write(data);
    stringWriter.Flush();
    stringWriter.Close();
    FileStream finalScript = null;
    byte[] finalString;
    finalString = System.Text.Encoding.Unicode.GetBytes(data);
    finalScript = File.Open(directory + "\\DBScript\\Final.sql", FileMode.Append, FileAccess.Write);
    finalScript.Write(finalString, 0, finalString.Length);
    finalScript.Close();
    Console.WriteLine("{0} saved sucessfully.", filename);
    catch (Exception e)
    Log.ErrorFormat(e, "{0} not saved.", filename);
    Console.WriteLine("{0} not saved.", filename);
    Console.Write(e.Message);
    Console.ReadKey();
    }

  • Insert XMLTYPE data into CLOB column

    Hi,
    I am trying to insert XMLTYPE datatype column value into the CLOB datatype column.
    I get an error -
    ORA - 00932: Inconsistent datatypes: expected CLOB got -
    How do I insert xml type data into clob?
    Thanks!

    Here is my sql code:
    I have a view :
    create or replace view test_view
    (id,
    code,
    desc)
    as select
    id,
    code,
    xmlroot(xmlelement("empname", ename), version '1.0') as desc
    from employee;
    I have a table emp_details_table. The columns in the emp_details_table are
    ID number,
    CODE varchar2,
    EMP_DETAILS CLOB
    I am tring to insert the 'test_view' data into the 'emp_details_table' and I get an error cannot insert xmltype data into clob.
    insert into emp_details_table
    (ID , CODE, EMP_DETAILS)
    select
    (ID, CODE, DESC) from test_view;
    Thanks.

  • ORA-01704 error form spatial data type (SDO_UTIL.FROM_WKTGEOMETRY)

    I am trying to make a program (C# & ODP.NET)to do the task , get geometry data From sqlserver2008 database and INSERT INTO Oracle11 Spatial Database.
    Because of using the Well-Known text (WKT) syntax , so I need to use "SDO_UTIL.FROM_WKTGEOMETRY('POLYGON ((56678400..." to insert geometry data to oracle. When the polygon text is longest than 4000 chr, I got the exception
    [ORA-01704: string literal too long]
    How can we solve this problem? It's urgent!
    Hope to hear from you.
    Fan

    Try with bind variables:
    oerr ora 1704
    01704, 00000, "string literal too long"
    // *Cause:  The string literal is longer than 4000 characters.
    // *Action:  Use a string literal of at most 4000 characters.
    //          Longer values may only be entered using bind variables.Please read http://www.oracle.com/technetwork/issue-archive/2005/05-sep/o55odpnet-101704.html.

  • Limitation for CLOB columns? - ORA-01704: string literal too long

    Hello!
    I'm trying to update a CLOB column with more than 35000 characteres, but I get "ORA-01704: string literal too long".
    The code:
    declare
    l_clob clob;
    begin
    update test set test = empty_clob()
    WHERE ID = 1
    returning test into l_clob;
    dbms_lob.write( l_clob, length('A...here 35000xA...A'), 1,'A...here 35000xA...A');
    end;
    Is there any limitation for CLOB columns?
    Thanks for help.
    Daniel

    user605489 wrote:
    32768 characteres :)Actually it's 1 character less than 32K...
    *32767*
    SQL> declare
      2    v_vc varchar2(32768);
      3  begin
      4    null;
      5  end;
      6  /
      v_vc varchar2(32768);
    ERROR at line 2:
    ORA-06550: line 2, column 17:
    PLS-00215: String length constraints must be in range (1 .. 32767)
    SQL>I guess it comes from a legacy thing where signed words (2 bytes) are/were used to represent a value. As the most significant bit of the word is used to represent the sign of the number the range goes from -32768 to 32767.

Maybe you are looking for