Insert long string to database

Hi,
I am using the JDBC in my program. I'm trying to insert a string
of length greater than 4000 into a LONG field and receive the
following errors,
"ORA-01704: string literal too long"
Can anyone explain how this is done?
I checked it on Internet, it may be a problem of Oracle.
Does anyone has a solution for it?
Thanks

Hi ,
Can u post the code.
If a String is longer than 4000 characters. It has to be streamed
inside. setXXX() won't work.
Regards
Elango.

Similar Messages

  • Inserting long string into Oracle

    When my code inserts about 5K character into a table, I got an error message saying that the Oracle could only handle 4K character. I am currently looking at LOB but havn't had a clear idea yet. Could someone give me some help on this? According to the sample code, I will have to use Oracle JDBC driver for LOB. But we are using BEA's Kona driver for all JDBC connections. Is there an easy way to insert long string?

    hii
    nams u solve ur problem using setCharacterStream method
    but it does't work if the string more than 4000 char
    raises "java.sql.SQLException: Protocol violation"
    here's the code
    PreparedStatement ps = con.prepareStatement( "UPDATE candidate SET cv_new = ?");
    StringReader cvReader=new StringReader(cv_new);
    int abc=cv_new.length();
    ps.setCharacterStream( 1, cvReader, abc);
    ps.executeUpdate();
    is that any problem in that code or it's a jdbc driver broblem ??
    i'm using classes 12.zip
    thanks

  • How to insert long text data in oracle for LONG column type??

    Anybody who can tell me what is best way to store long text (more than 8k) in Oralce table.
    I am using Long datatype for column but it still doenst let me insert longer strings.
    Also I am using ODP.Net.
    Anybody with a good suggestion???
    Thanks in advance

    Hi,
    Are you getting an error? If so, what?
    This works for me..
    Greg
    create table longtab(col1 varchar2(10), col2 long );
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    using System.Text;
    public class longwrite
    public static void Main()
    // make a long string
    StringBuilder sb = new StringBuilder();
    for (int i=0;i<55000;i++)
    sb.Append("a");
    sb.Append("Z");
    string indata = sb.ToString();
    Console.WriteLine("string length is {0}",indata .Length);
    // insert into database
    OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl");
    con.Open();
    OracleCommand cmd = new OracleCommand();
    cmd.CommandText = "insert into longtab values(1,:longparam)";
    cmd.Connection = con;
    OracleParameter longparam = new OracleParameter("longparam",OracleDbType.Long,indata .Length);
    longparam.Direction = ParameterDirection.Input;
    longparam.Value = indata ;
    cmd.Parameters.Add(longparam);
    cmd.ExecuteNonQuery();
    Console.WriteLine("insert complete");
    //now retrieve it
    cmd.CommandText = "select rowid,col2 from longtab where col1 = 1";
    OracleDataReader reader = cmd.ExecuteReader();
    reader.Read();
    string outdata = (string)reader.GetOracleString(1);
    Console.WriteLine("string length is {0}",outdata.Length);
    //Console.WriteLine("string is {0}",outdata);
    reader.Close();     
    con.Close();
    con.Close();
    }

  • How to insert a very long string into a column of datatype 'LONG'

    Can anyone please tell me how can I insert a very long string into a column of datatype 'LONG'?
    I get the error, ORA-01704: string literal too long when I try to insert the value into the table.
    Since it is an old database, I cannot change the datatype of the column. And I see that the this column already contains strings which are very long.
    I know this can be done using bind variables but dont know how to use it in a simple query.
    Also is there any other way to do it?

    Hello,
    To preserve formatting in this forum, please enclose your code output between \ tags. And when executing you code as a pl/sql or sql script
    include following lineset define off;
         Your code or output goes here
      \Regards
    OrionNet                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to insert a string containing a single quote to the msql database? help

    how can i insert a string which contains a single quote in to database... anyone help
    Message was edited by:
    sijo_james

    Absolutely, Positively use a PreparedStatement. Do not use sqlEscape() function unless you have some overriding need (and I don't know what that could possibly be).
    There are 1000's of posts on the positive aspects of using a PreparedStatement rather than using a Statement. The two primary positive attributes of using a PreparedStatement are automatic escaping of Strings and a stronger security model for your application.

  • Trying To Insert XML String Greater Than 4000 Characters in PHP Fails

    Dear Sir,
    Subject:-Trying To Insert XML String Greater Than 4000 Characters in PHP Fails ORA-01704.
    In an attempt to design web app in PHP and inserting data into "CLOB" field of "articles" table associated with it, returning ORA-01704: string literal too long error.
    Platform: OEL5
    Database 11g(11.0.7.0)
    php : 5.2
    I refer to oracle document ID: [ID 336888.1] it is asking to contact support.
    Please help us in this regards.
    Many Thanks,
    mkyazdani

    Hi,
    I appreciate you, yes it is similar i have referred that manual and also inform to our php developer about the changes we need to make in our php script.
    Regards,
    mkyazdani

  • Automatic trim of too long strings

    Hi,
    if I try to insert a too long string value into a VARCHAR column, I get the error ORA-12899.
    Is it possible to set the Oracle database so that too long strings get trimmed automatically?
    Thank you.

    Hi,
    Welcome to the forum!
    Unfortunately, there's nothing quite like what you want in Oracle.
    Even if you write a trigger to cut off the excess, you can still get the ORA-12899 error. For example, if table_x.col_1 is defined as VARCHAR2 (10), this statement:
    INSERT INTO table_x (col_1) VALUES ('ABCDEFGHIJKLMNOP');will get the error, even if you have a trigger that says
    :NEW.col_1 := SUBSTR (:NEW.col_1, 1, 10);You could define col_1 as VARCHAR2 (4000), and have a trigger that includes the statement show above, to make sure that the actual values will be 10 characters or less. You cound even have a CHECK constraint (LENGH (col_1) <= 10).
    Think carefully about what Someoneelse said. Do you really want to throw away part of what users enter, automatically and without any warning? Will that cause confusion?

  • Inserting long text in a programmatically created table

    Hi there!
    I have to create, in a programmatic way, a 2dtable where some cells have to contain a long string. As it seems to be not possible to have an automatic word-wrap, I triend to insert carriage return/line feed (vbCrLf) inside my string, but the result didn't change.
    Maybe I need to set some specific table property to do that?
    thank you,
    andrea

    Hello Andrea!
    You have to use a variable like TV or a text channel for every column you want to set. There is no direct way to fill a cell. In your script you only have to set the variable or channel. As you expected you have to use a vbCRLF to get multiline text. DIAdem will display multiline text but did not recognize it. That means that the program do not make a vertical alignment. The first line will be vertical centerted and all other lines will be below. Result: A white gap above the text! You have to 'play' with the cell and text height to get a half-decent text display. BTW: I made my tests with DIAdem 9.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • Oerror while inserting in to 11g database from SOA suite 11g db adaptor

    Hi,
    I am getting following error while inserting in to 11g database from SOA suite 11g database adaptor. Can you please help me on this.
    "{http://schemas.oracle.com/bpel/extension}bindingFault" has been thrown.
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'insert' failed due to: DBWriteInteractionSpec Execute Failed Exception. insert failed. Descriptor name: [LoggerDBInsert.LoggedError]. Caused by java.sql.SQLSyntaxErrorException: ORA-01722: invalid number . ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. ORA-01722: invalid number 1722
    Regards,
    Bharat

    It looks like you try to insert a string-value in a number-column.
    can you check all your assign and their values before you invoke the db-adapter, then you should be able to narrow down the problem.

  • Passing a long string from Vb to stored proc

    Hi,
    I am passing a long string from Vb to this stored proc ..
    defn:
    Create Or Replace Procedure saveTaxFormInDB(intFormUID IN number,
    intCLUID IN number,
    PDFdata IN varchar2,
    Status IN OUT Varchar2) AS
    Problem lies with the string pdfdata. I am sending it from VB as:
    Set cmdParamStr = cmdAdoCmd.CreateParameter("Data", adVarChar,
    adParamInput, 32767, strData)
    I have checked the parameters in VB while sending and I have the
    correct string argument to be passed to "PDFData", But i am not
    sure if it is getting the value correctly.
    Because I know that the code is raising exception while
    accessing PDFData. (eg. in places like insert ..(pdfdata) and
    length(pdfdata)...)
    Please advise how i can solve this problem.
    Please Note that the string is not VERY large. I do not need to
    use LOBS in any way. the string is definitely within the limits
    of varchar2(which i think is 4000 chars.. correct me if i am
    wrong).
    Many thanks

    what is the backend MS SQl server or Oracle.??
    If it is MS SQLSERVER, then
    1.Create a SqlCommand object with the parameters as the name of the stored procedure that is to be executed and the connection object con to which the command is to be sent for execution.
    SqlCommand command = new SqlCommand("Name of StoredProcedure",con);
    2.Change the command objects CommandType property to stored procedure.
    command.CommandType = CommandType.StoredProcedure;
    3.Add the parameters to the command object using the Parameters collection and the SqlParameter class.
    command.Parameters.Add(new SqlParameter("@parametername",SqlDbType.Int,0,"Filedname"));
    4.Specify the values of the parameters using the Value property of the parameters
    command.Parameters[0].Value=4;
    command.Parameters[1].Value="ABC";
    If it is oracle,
    OracleConnection con = new OracleConnection("uid=;pwd=");
    try
    con.Open();
    OracleCommand spcmd = new OracleCommand("Name of StoredProcedure");
    spcmd.CommandType = CommandType.StoredProcedure;
    spcmd.Connection = con;
    spcmd.Parameters.Add("empid", OracleType.Number, 5).Value = txtEmpid.Text;
    spcmd.Parameters.Add("sal", OracleType.Number, 5).Value = txtSal.Text;
    spcmd.ExecuteNonQuery();
    }

  • AES256 bit encyption key from 64 character long string

    Hi,
    I have Oracle 10.2 on Windows 2003. I have recently started working on a project that requires encrypting information before sending it over. I have got 64 character long string to use it as a key.
    I am getting ORA-06502: PL/SQL: numeric or value error: raw variable length too long
    <pre>
    declare
    input_string VARCHAR2 (200) := 'SomeText';
    output_string VARCHAR2 (200);
    encrypted_raw RAW (2000); -- stores encrypted binary text
    decrypted_raw RAW (2000); -- stores decrypted binary text
    key_bytes_raw RAW (32); -- stores 256-bit encryption key
    encryption_type PLS_INTEGER; -- total encryption type
    begin
    DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
    encryption_type := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
    key_bytes_raw := UTL_I18N.STRING_TO_RAW('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6', 'AL32UTF8');
    encrypted_raw := DBMS_CRYPTO.ENCRYPT
    src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
    typ => encryption_type,
    key => key_bytes_raw
    -- The encrypted value in the encrypted_raw variable can be used here
    decrypted_raw := DBMS_CRYPTO.DECRYPT
    src => encrypted_raw,
    typ => encryption_type,
    key => key_bytes_raw
    output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
    DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    Please let me know hot to convert 64 character long string in to 256bit key.
    Thanks
    -Smith

    smith_apex wrote:
    My client is using Java and they are saying that they are using this key for their AES256 Encryption and working fine. I have asked them to provide me 32 bytes key as in Oracle 256bit is 32 character string.
    Let me see what they have to say.
    I was wondering why Java has 64 bytes for 256 AES encryption when Oracle need only 32 bytes for same encryption.I am not sure I completely understand how those built-in packages work but the doc example produces the raw key that is same in length (in terms of number of characters) as the one you are using.
    Yet your UTL_I18N packaged function fails for your key but works for the documentation example.
    Documentation example:
    SQL> select * from v$version ;
    BANNER
    Oracle Database 10g Release 10.2.0.5.0 - Production
    PL/SQL Release 10.2.0.5.0 - Production
    CORE     10.2.0.5.0     Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    declare
       input_string       VARCHAR2 (200) := 'Secret Message';
       output_string      VARCHAR2 (200);
       encrypted_raw      RAW (2000);             -- stores encrypted binary text
       decrypted_raw      RAW (2000);             -- stores decrypted binary text
       num_key_bytes      NUMBER := 256/8;        -- key length 256 bits (32 bytes)
       key_bytes_raw      RAW (32);               -- stores 256-bit encryption key
       encryption_type    PLS_INTEGER :=          -- total encryption type
                                DBMS_CRYPTO.ENCRYPT_AES256
                              + DBMS_CRYPTO.CHAIN_CBC
                              + DBMS_CRYPTO.PAD_PKCS5;
    begin
       DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
       DBMS_OUTPUT.PUT_LINE ('Encryption Type: ' || encryption_type);
       key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES (num_key_bytes);
       DBMS_OUTPUT.PUT_LINE ('Key Bytes(RAW): ' || key_bytes_raw);
       encrypted_raw := DBMS_CRYPTO.ENCRYPT
             src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
             typ => encryption_type,
             key => key_bytes_raw
       DBMS_OUTPUT.PUT_LINE ('Encrypted string: ' || encrypted_raw);
        -- The encrypted value in the encrypted_raw variable can be used here
       decrypted_raw := DBMS_CRYPTO.DECRYPT
             src => encrypted_raw,
             typ => encryption_type,
             key => key_bytes_raw
       output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    32   33   34  /
    Original string: Secret Message
    Encryption Type: 4360
    Key Bytes(RAW): 52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF
    Encrypted string: 0BDDC2B94F7044700D85624297A39025
    Decrypted string: Secret Message
    PL/SQL procedure successfully completed.
    SQL> select length('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF') from dual ;
    LENGTH('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF')
                                                 64
    SQL> select dump('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF') from dual ;
    DUMP('52EC66508FDF1E5DE5FD38EC2467FAA91009B738A2926AA870E142C080C72EBF')
    Typ=96 Len=64: 53,50,69,67,54,54,53,48,56,70,68,70,49,69,53,68,69,53,70,68,51,56,69,67,50,52,54,55,70,65,65,57,49,48,48,57,66,55,51,56,65,50,57,50,54,65,65,56,55,48,69,49,
    52,50,67,48,56,48,67,55,50,69,66,70Your example:
    declare
       input_string       VARCHAR2 (200) := 'SomeText';
       output_string      VARCHAR2 (200);
       encrypted_raw      RAW (2000);             -- stores encrypted binary text
       decrypted_raw      RAW (2000);             -- stores decrypted binary text
       key_bytes_raw      RAW (32);               -- stores 256-bit encryption key
       encryption_type    PLS_INTEGER;          -- total encryption type
    begin
       DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
       encryption_type :=   DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
       key_bytes_raw := UTL_I18N.STRING_TO_RAW('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6', 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Key Bytes(RAW): ' || key_bytes_raw);
       encrypted_raw := DBMS_CRYPTO.ENCRYPT
             src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
             typ => encryption_type,
             key => key_bytes_raw
        -- The encrypted value in the encrypted_raw variable can be used here
       decrypted_raw := DBMS_CRYPTO.DECRYPT
             src => encrypted_raw,
             typ => encryption_type,
             key => key_bytes_raw
       output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
       DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    end;
    27   28   29   30  /
    Original string: SomeText
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: raw variable length too long
    ORA-06512: at line 12
    SQL> select length('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6') from dual ;
    LENGTH('EICCMKJD94JFGNIW03LJKDLFUTCNV3209KFJD67023JLCLMXZLMC9543YKFLSEU6')
                                                 64
    SQL> select dump('eiccmkjd94jfgniw03ljkdlfutcnv3209kfjd67023jlclmxzlmc9543ykflseu6') from dual ;
    DUMP('EICCMKJD94JFGNIW03LJKDLFUTCNV3209KFJD67023JLCLMXZLMC9543YKFLSEU6')
    Typ=96 Len=64: 101,105,99,99,109,107,106,100,57,52,106,102,103,110,105,119,48,51,108,106,107,100,108,102,117,116,99,110,118,51,50,48,57,107,102,106,100,54,55,48,50,51,106,
    108,99,108,109,120,122,108,109,99,57,53,52,51,121,107,102,108,115,101,117,54

  • Extract multiple data from long string

    I am working in Crystal Reports XI looking at an SQL database. How can I pick up several different data bits from a realy long string? Each element I want is preceded by "Old Value =" or "New Value =". The problem is that there are up to 4 different sets of these "Old Value =", "New Value =" so I can only get the first set if I use "InStr" to find "Old Value =" or "New Value =".
    Since they are preceded by unique headings like "RuntimeMinutes", I thought I could use "InStr" to find that "RuntimeMinutes" or whichever and then use that value as the location number nested in another "InStr" to find "New Value =" and nest it all in a "Mid" expression. But however I did it I got an error highlighting that "InStr" nested in "InStr" saying it was not an integer or the value was less than 1.
    Any ideas?

    The way that I'd deal with this is by creating formula fields for each value that you want to extract.  In the sample below, I'm assuming your string looks something like this:
    RuntimeMinutes OldValue=123 NewValue=234 DbReads OldValue=12345 NewValue=34567
    The formula for {@Runtime Minutes Old Value} would then look like (basic syntax):
    dim pos as number
    ' Find where RuntimeMunutes old and new values start:
    pos = InStr({really long string}, "RuntimeMinutes")
    ' Find first OldValue after RuntimeMinutes:
    pos = InStr(pos + 14, {really long string}, "OldValue")  ' 14 = Len("RuntimeMinutes")
    ' Pull out the value:
    formula = val(mid({really long string}, pos + 9,
                        Instr(pos + 9, {really long string}, " ") - pos - 9)) ' 9=Len("OldValue=")
    And do the same for all of the other values you need. 
    HTH,
    Carl

  • SQLJ with EJB. Do not insert data in the database

    Hi All!
    I4m developing an application using SQLJ and EJB (session beans,
    container managed transactions), and when I try to insert data
    in the database it doesn't work. All goes well (apparently), but
    the changes do not have effect in the DB.
    I've tried to use bean managed transactions, but when I try to
    insert data, I get the error: NOT IN A TRANSACTION. The code of
    the client in the bean managed is the following:
    public class MiEJBCLiente {
    public static void main(String[] args) {
    String namespaceURL
    = "jdbc:oracle:thin:@rabinf56:1521:prinpal";
    String ejbUrl
    = "sess_iiop://rabinf56:2481:prinpal/test/Bean";
    String username = "xxx";
    String password = "xxx";
    // Setup the environment
    Hashtable environment = new Hashtable();
    // Tell JNDI to speak sess_iiop
    environment.put
    (javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    // Tell sess_iiop who the user is
    environment.put(Context.SECURITY_PRINCIPAL, username);
    // Tell sess_iiop what the password is
    environment.put(Context.SECURITY_CREDENTIALS, password);
    // Tell sess_iiop to use credential authentication
    environment.put(Context.SECURITY_AUTHENTICATION,
    ServiceCtx.NON_SSL_LOGIN);
    environment.put
    (jdbc_accessURLContextFactory.CONNECTION_URL_PROP, namespaceURL);
    UserTransaction ut = null;
    // Lookup the URL
    hello.MiBeanHome homeInterface = null;
    try {
    Context ic = new InitialContext(environment);
    DriverManager.registerDriver (new
    oracle.jdbc.driver.OracleDriver());
    ut = (UserTransaction)ic.lookup
    ("jdbc_access://test/BeanTrans");
    homeInterface = (hello.MiBeanHome) ic.lookup(ejbUrl);
    catch (SQLException e) {
    // That's it!
    try {
    System.out.println("Creating a new EJB instance");
    hello.MiBean remoteInterface = homeInterface.create();
    ut.begin ();
    remoteInterface.inserta();
    ut.commit();
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    I4m waiting for suggests.
    Thanks in advance...

    Hi,
    Are you sure it's a front-end bug? Try to double check your back-end code.
    If you still believe the bug is in the front-end, try to debug the insertHandler function to see if you are attaching the UserVO properly into the UserEvent.
    Best regards,
    Pablo Souza

  • Put_line long string

    Hi guys
    I am trying to ult_file.put_line a long string ~maximum 5000 characters to a file. I think i have exccess the default limit and receive an error. So i extend the maximum character per line by override the utl_file.fopen method. After that it stopped the error, but the output characters are all non readable characters - 扡扡扡扡扡扡扡扡扡扡扡扡扡扡扡扡扡扡
    Could someone suggest me a solution to insert my long string?
    Thank you
    Bryan

    Procedure Write_to_file(filename in string, orderid in number, orderversion in number) is
    f SYS.Utl_File.file_type;
    tmporderid number(10);
    tmporderversion number(10);
    str string(1032);
    begin
    tmporderid := orderid;
    tmporderversion := orderversion;
    f := utl_file.fopen('EXPORTDIR2',filename,'W');
    FOR s in
    (Select SAP_STRING1
    FROM BSACC_V_SAP_TABLE_2
    where OrderId = tmporderid
    AND OrderVersion = tmporderversion )
    Loop
    utl_file.put_line(f,s.sap_string1||chr(10));
    end loop;
    utl_file.fclose(f);
    end;
    Window XP professional English
    Oracle 10g

  • Can i insert data in my database from a web intelligence report?

    if that's not possible,can I do it from a stored procedure based Universe or with a derived table? Does BusinessObjects in general allow me to execute statements to insert data in my database?

    Hi Erika,
    afaik it is not possible write back to database from web intelligence .
    from dashboards with web services you can achieve this.

Maybe you are looking for