Convert long to varchar2

Hi there,
I am looking for a convertion, long to varchar2, in a sql statement.
If I run the following query :
select data_default from user_tab_columns
It works fine in sql developper but when I execute it in my PHP code it returns:
Notice: Undefined index: DATA_DEFAULT in /opt/lampp/htdocs/datamodel/index.php on line 64
This issue is due in the case where the columns has null.
So I try with the NVL function:
select nvl(data_default, 'null') from user_tab_columns
ORA-00932: inconsistent datatypes: expected LONG got CHAR
I found on internet some people are using the substr function but it did not working for me.
select substr(data_default, 1, 2000) from user_tab_columns
ORA-00932: inconsistent datatypes: expected NUMBER got LONG
Any one has an idea ?
Regards !

See this thread as well you can get an exaple user function
ORA-00932: inconsistent datatypes
G.

Similar Messages

  • PL/SQL Solution for Converting Long to VarChar2

    I recently had to convert a bunch of text stored in Long fields to a new VarChar2(2000) field in the same table.
    As you know if you've ever tried, you can't use a basic SQL the update statement will not do this, e.g. update table1 set field2 = field1 (where field2 is VarChar(2000) and field1 is Long) fails as does update table1 set field2 = substr(field1, 1, 2000).
    Interestingly PL/SQL's implementation of SubStr does work with Long fields. I was able to put together the following anonymous PL./SQL block to accomplish the task (msgtext is varchar(2000), msgtext2 is Long):
    DECLARE
    CURSOR message_cur
    IS
    SELECT ROWID, msgtext, msgtext2
    FROM tlrcmmessages
              FOR UPDATE;
    message_rec message_cur%ROWTYPE;
    BEGIN
    OPEN message_cur;
    LOOP
    FETCH message_cur
    INTO message_rec;
    EXIT WHEN message_cur%NOTFOUND;
    UPDATE tlrcmmessages
    SET msgtext = SUBSTR(message_rec.msgtext2, 1, 2000)
    WHERE CURRENT OF message_cur;
    END LOOP;
    CLOSE message_cur;
    END;
    I hopes this helps others out there in similar circumstances.
    Good luck,
    Rob Bratton, Bratton Enterprises

    Oracle strongly recommends to convert LONG fields into CLOB:
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adfnstyp.htm#429091
    Rgds.

  • Problem in converting Long Raw to Varchar2

    Hi
    I need to analyze the contents of a 'Long Raw ' field to proceed further. In an attempt to do that, using the following code, I could not see the data in a readable format.Kindly Help...
    create or replace procedure lr2vc1 (lv_id number) is
    c1 long raw;
    note_varchar2 varchar2(32000);
    begin
    select value into c1 from Test_table where id=lv_id; /*value is the Long Raw field*/
    note_varchar2 := utl_raw.cast_to_varchar2(c1);
    insert into lr2vc (prid,lrvalue) values (lv_id, note_varchar2);
    commit;
    --dbms_output.put_line(c1);
    end;
    Thanks
    Sandeep

    Whats wrong with the answer given here?:
    <br>
    Problem while converting Long Raw data to Varchar2

  • How can I converting long raw in clob on Apex when I'm creating a view?

    I need some help. I'm creating a view and I need converting long raw fields in clob, varchar2, or char when I create a view.
    Thanks for your help.

    What error did you get when using the functions in a SELECT on a view? If that did not work, identify the table the view is based on and write the SELECT statement directly against that table and not the view.
    I do not understand, "I try and they are rights".
    Mike

  • App to convert long voice memos to text

    Is anyone aware of an app (on Mac or iPhone) that can convert long (over a couple minutes) dictation to text? Dragon Dictation for iPhone works great, but it only handles recordings up to 30 seconds. It seems like there would at least be some Mac app that could convert longer .m4a voice memo files....?

    Sync them in iTunes via the phone Music pane. You'll find this at the bottom of the page:
    They will go into your music library and a voice memos playlist will be created.

  • Need to convert long data type to varchar2

    I need to convert a long datatype in an existing table to a
    varchar2, in either another table or view. I have a 3rd party
    application which needs to query the data in the long data type,
    but it can "handle" the long.
    What is the best way to do this? I tried to make a trigger, but
    I must be missing something. Here is the trigger.
    CREATE OR REPLACE TRIGGER "PROD".SV_GET_RTG_COMNT
    BEFORE INSERT OR UPDATE ON PROD.RELS_RTG_SEQ_COMNT
    FOR EACH ROW
    WHEN (OLD.rels_rtg_no = NEW.rels_rtg_no)
    DECLARE
    -- DECLARE VARIABLES
    RTG_COMNT_VAR VARCHAR2(32);
    RTG_COMNT_LONG LONG;
    BEGIN
    Select COMNT_TXT into RTG_COMNT_LONG
    from rels_rtg_seq_comnt;
    RTG_COMNT_VAR := 'TEXT' || substr(RTG_COMNT_LONG,1,32);
    -- If INSERTING
    Insert into SV_RTG_SEQ_COMNT (print_cd, comnt_no,
    seq_no, rtg_no, comnt_txt) values
    (:new.print_cd, :new.comnt_no, :new.seq_no, :new.rels_rtg_no,
    rtg_comnt_var);
    END;
    I tried to use the substr command on the comnt_txt in view but
    received an invalid datatype error.
    Any help would be greatly appreciated.
    Doug

    create another table with clob datatype
    1)create table clob_tab(pkval number,clob_col clob);
    2) insert into clob_tab (select pkval,to_lob(long_col) from
    long_tab);
    3) use dbms_lob package to do string manipulation using
    substr,instr functions on clob column.

  • Need to convert long type column to varchar2 type

    I got a problem in creating a staging table.. i have to pull out data from database to create data file.. But a column is of type long and has got enter character (chr 10) values in between.. Because of that character i cant able load data to staging table.. some error shows second end character needs.. so that data was not properly into table..
    for ex:
    08/21/07 14:46:02 MMURPHY
    per client mail date is 10/1/07
    this data has got enter character (chr 10) after MMURPHY while loading this data to staging.. i got error..
    so pls suggest me some solution to create sql loader file using pl/sql procedures..
    so that i convert that (chr10) value to some other value..

    Try to put this column into function which will be searching for chr(10), and replace it. Create control file like:
    colname type "REGEXP_REPLACE(:colname, ...)"

  • Convert XMLTYPE to VARCHAR2 or CLOB?

    Does anyone know how to convert an XMLTYPE variable to VARCHAR2 or CLOB? I am using the XMLELEMENT function to select XML into an XMLTYPE variable (VARCHAR2 and CLOB will not accept xml from this function). But I would like to convert the xml in the XMLTYPE variable to VARCHAR2 or CLOB. Can anyone please tell me how to do this? The reason is that I would like to call this procedure from MS ADO.
    Anthony Sneed
    email: [email protected]

    Hi,
    But I would like to convert the xml in the XMLTYPE variable to VARCHAR2 or CLOB.You can select XMLType data using PL/SQL or Java. You can also use the getClobVal(), getStringVal(), or getNumberVal() functions to retrieve XML as a CLOB, VARCHAR, or NUMBER, respectively.
    Example 4-18 Selecting XMLType Columns using getClobVal()
    This example shows how to select an XMLType column using SQL*Plus:
    SET long 2000
    SELECT e.poDoc.getClobval() AS poXML
    FROM po_xml_tab e;
    POXML
    <?xml version="1.0"?>
    <PO pono="2">
    <PNAME>Po_2</PNAME>
    <CUSTNAME>Nance</CUSTNAME>
    <SHIPADDR>
    <STREET>2 Avocet Drive</STREET>
    <CITY>Redwood Shores</CITY>
    <STATE>CA</STATE>
    </SHIPADDR>
    </PO>
    Look into the documentation: Oracle9i XML Database Developer's Guide - Oracle XML DB for more details.
    Hope that helps.
    OTN team@IDC

  • How to convert clob to varchar2 in an update trigger

    Hi,
    I need to convert a field (clob) to varchar2 in a update trigger, how can I do that?
    regards.

    The maximum amount of data you can store in CLOB column is 4GB.
    You have table TABLE1 having col1 CLOB datatype.You have one more table
    Table_audit_1 without having CLOB datatype column and want to move CLOB
    data into VARCHAR2 column which has maximum length of 4000 and want to
    audit col1 CLOB into VARCHAR2.It seems to me you dont care about the data
    beyond 4000 bytes.
    In 9i SUBSTR, INSTR can be performed without reference to the DBMS_LOB
    package.
    SQL> DROP TABLE mytable
      2  /
    Table dropped.
    SQL> DROP TABLE mytable1
      2  /
    Table dropped.
    SQL> CREATE TABLE mytable
      2  (a   NUMBER,b   CLOB)
      3  /
    Table created.
    SQL> CREATE TABLE mytable1
      2  (c  NUMBER,d   VARCHAR2(4000))
      3  /
    Table created.
    SQL> DECLARE
      2      loc           CLOB;
      3  BEGIN
      4      FOR i IN 1..5000
      5      LOOP
      6        loc:=loc||i;
      7      END LOOP;
      8      INSERT INTO mytable  (a,b) VALUES (1,loc);
      9      INSERT INTO mytable1 (c,d) VALUES (1,SUBSTR(loc,1,4000));
    10      COMMIT;
    11  END;
    12  /
    PL/SQL procedure successfully completed.
    SQL> SET LONG 5000
    SQL> CREATE OR REPLACE TRIGGER mytrigger BEFORE UPDATE ON mytable FOR EACH ROW
      2  BEGIN
      3      UPDATE mytable1
      4         SET d=SUBSTR(:NEW.b,1,4000)
      5       WHERE c=:NEW.a;
      6  END;
      7  /
    Trigger created.
    SQL> DECLARE
      2      loc           CLOB;
      3  BEGIN
      4      FOR i IN 1..1000
      5      LOOP
      6        loc:=loc||'A '||i;
      7      END LOOP;
      8      UPDATE mytable
      9         SET b=loc
    10       WHERE a=1;
    11      COMMIT;
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    SQL> SELECT LENGTH(b) FROM mytable
      2  /
    LENGTH(B)
          4893
    SQL> SELECT LENGTH(d) FROM mytable1
      2  /
    LENGTH(D)
          4000
    SQL> Khurram

  • After updating to 5.1, pages no longer lets me convert long, single page (up to 8 1/2 x 50) document to an 8 1/2 x 11 document with many pages.

    I have been using pages to create a document that I always export in two ways.  1st, I export a single page document that contains all of the data (sometimes this can go as long as 8 1/2 x 50).  I have to do this for web purposes.  Next, I duplicate the document, and change the page setup to 8 1/2 x 11, turning it into a document with many pages. This is for printing purposes.
    Before upgrading to Pages 5.1, this worked flawlessly.  After the upgrade, when I change the document to 8 1/2 x 11, Pages just deletes all of the data after the 11'' mark. 
    I am trying to make it behave like it did before the upgrade: when I convert the document to 8 1/2 x 11, it just made as many new pages as necessary and didn't delete any of the data.
    How can I do this?

    Pages 5 is buggy and has had over 100 fetaures removed.
    Pages '09 should still be in your Applications/iWork folder, use that.
    Peter

  • Convert CLOB to VARCHAR2 in Oracle 8i

    Hello all,
    I would like to convert a CLOB column from a table to a VARCHAR2.
    How can I do this?
    I would like that this works in Oracle 8i, 9i and 10g.
    Thank you very much.

    Hello APC,
    I found the problem.
    I have Oracle Reports 6i + patch 17.
    The problem was that I couldn't select a CLOB column and store his value in a CLOB variable.
    I needed to do the conversion DBMS_LOB.SUBSTR in the select statement and store his value in a VARCHAR2 variable.
    Thank you

  • Problem converting long AVI to MOV

    I am trying to convert one hour AVI file into a MOV format using Quicktime
    PRO on a PC.If I try and convert a short AVI video of less than 5 minutes I
    can can convert it and change the settings of both Video and Audio to suit
    my specification.If however I try and convert a longer AVI say one hour I
    can only set the video characteristics but NO audio at all.The audio
    settings area is greyed out and not changeable.
    My question is this.Is it possible to convert a long AVI video (say 1 hour)
    to a MOV format in Quicktime PRO on a PC and still be able to set the audio
    to the required specification?
    Thanks Stu
    P.S im using QT Pro 7.3

    If the audio settings in the export dialog can't be adjusted then the audio codec used in the file isn't supported by QuickTime Pro export.
    MPEG-1 is playback only.
    MPEG Streamclip (free) can convert your AVI with MPEG-1 audio.
    http://perian.org can also help QuickTime Pro with some codecs used in AVI's.

  • How to convert CLOB to varchar2 whose length is more than 4000

    Hi ,
    I have to retrive the CLOB data into varchar2 and spilt those comma seperated values into rows
    but i am getting following error
    " ORA-06502: PL/SQL: numeric or value error: character string buffer too small "
    the proc i used is like following :
    : create table test_clob (grp_id CLOB, id number)
    Create or replace proc test_clob(p_id number )
    Is
    V_clob CLOB;
    V_str varchar2(4000);
    V_main varchar2(30000);
    TYPE t_clob IS REF CURSOR;
    cur_clob t_clob;
    Begin
    Select grp_id
    Into v_str
    From test_clob
    Where id= p_id;
    ---converting column data in rows as I have to return the cursor as output
    V_main:= ' select grp_id from ( WITH t AS
    (SELECT REGEXP_SUBSTR(''' || v_str ||
    ''', ''[^,]+'', 1, LEVEL) txt
    FROM DUAL
    CONNECT BY LEVEL <=
    LENGTH(''' || v_str ||
    LENGTH(REPLACE(''' || v_str ||
    ''', '','')) + 1)
    SELECT REGEXP_SUBSTR(trim(txt), ''[^\,]+'', 1, 1) grp_id
    FROM t )';
    open cur_clob for ' select rtrim(xmlagg(xmlelement(e, grp_id || '','')).extract (''//text()'').getclobval (),'','') grp_id
    from ( '|| v_main||' ) ';
    loop
    fetch cur_clob
    into V_clob;
    exit when cur_clob %notfound;
    end loop;
    insert into test_clob
    values (p_id, v_clob);
    commit;
    End;
    Please help its very urgent

    957624 wrote:
    Hi ,
    I have to retrive the CLOB data into varchar2 and spilt those comma seperated values into rows
    but i am getting following error
    " ORA-06502: PL/SQL: numeric or value error: character string buffer too small "
    the proc i used is like following :
    : create table test_clob (grp_id CLOB, id number)
    Create or replace proc test_clob(p_id number )
    Is
    V_clob CLOB;
    V_str varchar2(4000);
    V_main varchar2(30000);
    TYPE t_clob IS REF CURSOR;
    cur_clob t_clob;
    Begin
    Select grp_id
    Into v_str
    From test_clob
    Where id= p_id;
    ---converting column data in rows as I have to return the cursor as output
    V_main:= ' select grp_id from ( WITH t AS
    (SELECT REGEXP_SUBSTR(''' || v_str ||
    ''', ''[^,]+'', 1, LEVEL) txt
    FROM DUAL
    CONNECT BY LEVEL <=
    LENGTH(''' || v_str ||
    LENGTH(REPLACE(''' || v_str ||
    ''', '','')) + 1)
    SELECT REGEXP_SUBSTR(trim(txt), ''[^\,]+'', 1, 1) grp_id
    FROM t )';
    open cur_clob for ' select rtrim(xmlagg(xmlelement(e, grp_id || '','')).extract (''//text()'').getclobval (),'','') grp_id
    from ( '|| v_main||' ) ';
    loop
    fetch cur_clob
    into V_clob;
    exit when cur_clob %notfound;
    end loop;
    insert into test_clob
    values (p_id, v_clob);
    commit;
    End;
    Please help its very urgentNo, nothing is urgent here and it is very rude to suggest it is, as well as it being a breach of the terms of use for the forums. Urgent issues relate to commercially live systems, and for those you need to raise a support request with Oracle Support. The forums are manned by volunteers with their own jobs to do, so suggesting they drop everything to help you urgently is very rude. Also, other people asking questions would like answers to theirs as soon as possible too, so suggesting your question is more urgent than theirs is also rude to those people. You will find that suggesting your question is urgent will actually prevent people from helping you on the forums as many people will simply choose to ignore you for your rudeness (either that or they'll be rude back)
    Please read {message:id=9360002} to learn how to ask a question properly.
    Now, in answer to your question...
    What is it you are really trying to do?
    If you have comma seperated data, why it is being stored like that in a CLOB? That seems like bad design for storing data.
    If the data is coming from a file, then you could consider using External Tables (or SQL*Loader) to load the comma seperated data in a structured way.
    If you really have data in a clob in comma seperated format, what are you wanting to do with it exactly i.e. what determines where the data should be split?
    Your code isn't clear, but it looks like, on the one hand you are splitting comma seperated data out of a string, and on the other hand you're turning it into XML to get a clob of data back.
    Please be clear by providing some example data and expected output, along with your database version as explained in the FAQ post I linked to above.

  • Convert NVARCHAR2 to VARCHAR2 in select statement

    I need to convert NVARCHAR2 values to VARCHAR2 in a select statement. Is this possible? The COUNTY_PARCEL_DATA colums are the NVARCHAR2 columns that need converting. I've tried TRANSLATE(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER USING CHAR_CS), CAST(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER AS VARCHAR2(100)), CONVERTCS(COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER, 'CHAR_CS') and others directly in the statement for each column. Anything I'm missing? Thanks.
    SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
    COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_NAME
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_TYPE
    AS ADDRESS,
    COUNTY_PARCEL_DATA.SITUS_CITY AS CITY,
    'AZ' AS STATE,
    COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP,
    'T4' AS TRACER
    FROM BENEFICIARY
    LEFT OUTER JOIN
    VARS_PARCEL
    ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
    LEFT OUTER JOIN
    COUNTY_PARCEL_DATA
    ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN
    LEFT OUTER JOIN
    OWNER
    ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
    WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
    (SELECT COLUMN_VALUE
    FROM TABLE(SPLIT_STRING (
    R_VARS_MAILING_NOTICES.NEIGHBORHOODS
    OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
    AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';
    Edited by: Guddie on Apr 6, 2010 12:23 PM

    Are you doing the NVARCHAR2 to VARCHAR2 conversions everywhere, see comments below
    SELECT BENEFICIARY.NAME_FIRST || ' ' || BENEFICIARY.NAME_LAST AS NAME,
    COUNTY_PARCEL_DATA.SITUS_STREET_NUMBER                        <==== Here, obviously
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_DIRECTION                <==== Here
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_NAME                        <==== Here
    || ' '
    || COUNTY_PARCEL_DATA.SITUS_STREET_TYPE                        <==== Here
    AS ADDRESS,
    COUNTY_PARCEL_DATA.SITUS_CITY AS CITY,                            <==== Here
    'AZ' AS STATE,
    COUNTY_PARCEL_DATA.SITUS_ZIP AS ZIP,                                 <==== Here
    'T4' AS TRACER
    FROM BENEFICIARY
    LEFT OUTER JOIN
    VARS_PARCEL
    ON BENEFICIARY.AVNUM = VARS_PARCEL.AVNUM
    LEFT OUTER JOIN
    COUNTY_PARCEL_DATA
    ON VARS_PARCEL.APN = COUNTY_PARCEL_DATA.APN                   <==== Here, maybe not so obvious
    LEFT OUTER JOIN
    OWNER
    ON BENEFICIARY.BENEFICIARY_ID = OWNER.BENEFICIARY_ID
    WHERE (SUBSTR (VARS_PARCEL.AVNUM, 0, 4) IN
    (SELECT COLUMN_VALUE
    FROM TABLE(SPLIT_STRING (
    R_VARS_MAILING_NOTICES.NEIGHBORHOODS
    OR R_VARS_MAILING_NOTICES.NEIGHBORHOODS IS NULL)
    AND BENEFICIARY.BENEFICIARY_TYPE = 'Tenant';This is assuming that all fields in COUNTY_PARCEL_DATA are NVARCHAR2.
    Edited by: AlanWms on Apr 6, 2010 3:53 PM changed "joins" to "conversions" in 1st sentence.

  • HELP! - Converting LONG to CLOB in  PL/SQL

    can i pass in a LONG as a parameter to a stored procedure and in
    the stored procedure convert or assign it to a CLOB column? i
    have tried passing in a CLOB as an input parameter using OO4O
    without any success. i am using the oracle oledb provider
    currently but may convert it over to using OO4O if i have to. i
    know i can pass in a LONG via ADO as an adLongVarChar datatype,
    but i am not sure what to do with the LONG inside the stored
    procedure. if anyone knows how to get a LONG into a CLOB could
    you please post some very basic sample PL/SQL code.
    if there is an easier way please let me know!
    the reason i am using CLOB's is because i need more than one
    LONG in certain tables, and you can only have 1 LONG per table.
    thanks

    i should have mentioned i am using oracle 8.1.7.2.1 and when i
    try to use TO_LOB() i get "Identifier TO_LOB must be declared."
    so i am assuming this is an oracle 9 function. is this correct?

Maybe you are looking for

  • Report for Checks Issued

    Hi Can somebody tell me how can i generate a REPORTS wherein it shows our CHECKS ISSUED TO SUPPLIERS as payments? Also would show the Invoice Number, Invoice Amount, Payment Date and Maturity Date... Your help is very much appreciated... janna

  • Smartforms - Change a text elements character Format

    Hello, I need to modify a Smartform by increasing the font size on some text elements.  When I highlight the text element to change and then click the dropdown for Character Format I can click the format I would like but it never changes. I've also t

  • Error: cannot read: C:\Documents; and Settings\JR\Desktop\logrand.java

    Thats the problem. Bug started happening all the sudden. Double click a java file on the desktop that just two second before was built fine. Go to build it and it says that. "error: cannot read: C:\Documents; and Settings\JR\Desktop\logrand.java" Now

  • 2D X axis Scaling on Reports

    HI, My time data comes in using the system time from the computer and does not start at zero.  It is often starting at 3000 sec or 6240 sec, etc.. When I run my report I am constantly having to change the beginning and end times in order to capture t

  • Order of Pictures

    Some of my pics are of apartments I show for a living,several thousand of them but while I have them in perfect order on my macbook ie numerical by address this does not transfer accurately to my iphone. I have tried everything I can think of, changi