Column Datatype modify

Hi,
How can i modify a column datatype varchar2(100) into blob in a table.
Regards,
Fame

create table x (y varchar2(100));
insert into x values ('A');
commit;
alter table x rename column y to z;
alter table x add (y clob);
update x set y = z;
commit;
alter table x drop column z;
Table dropped.
Table created.
1 row created.
Commit complete.
Table altered.
Table altered.
1 row updated.
Commit complete.
Table altered.
drop table x purge;
create table x (y varchar2(10));
insert into x values ('A');
commit;
alter table x rename column y to z;
alter table x add (y blob);
update x set y = utl_raw.cast_to_raw (z);
commit;
select * from x;
update x set y = (z);
commit;
select * from x;
alter table x drop column z;
Table dropped.
Table created.
1 row created.
Commit complete.
Table altered.
Table altered.
1 row updated.
Commit complete.
Z          Y
A          A
1 row selected.
1 row updated.
Commit complete.
Z          Y
A          
1 row selected.
Table altered.

Similar Messages

  • Column Datatype Change

    Hi,
    I created a table with some 10 columns earlier, now one of the column datatype needs to be changed to varchar2(2), which actually in the database it is number.
    The thing the table now contains 10 records. Its not allowing me to modify the column datatype, because it has rows in it. How to change the column datatype with data in the table. Pl reply ASAP.
    Thanks

    See the following example.
    Let's modify deptno column from number to varchar2 :
    SCOTT@demo102> desc emp2
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO NUMBER(2)
    SCOTT@demo102> select count(*) from emp2;
      COUNT(*)
            14
    SCOTT@demo102> alter table emp2 modify deptno varchar2(2);
    alter table emp2 modify deptno varchar2(2)
    ERROR at line 1:
    ORA-01439: column to be modified must be empty to change datatype
    SCOTT@demo102> alter table emp2[b] add deptno2 varchar2(2);
    Table altered.
    SCOTT@demo102> update emp2 set deptno2=deptno;
    14 rows updated.
    SCOTT@demo102> commit;
    Commit complete.
    SCOTT@demo102> alter table emp2 drop column deptno
    SCOTT@demo102> /
    Table altered.
    SCOTT@demo102> alter table emp2 rename column deptno2 to deptno
    SCOTT@demo102> /
    Table altered.
    SCOTT@demo102> desc emp2
    Name                                      Null?    Type
    EMPNO                                              NUMBER(4)
    ENAME                                              VARCHAR2(10)
    JOB                                                VARCHAR2(9)
    MGR                                                NUMBER(4)
    HIREDATE                                           DATE
    SAL                                                NUMBER(7,2)
    COMM                                               NUMBER(7,2)
    DEPTNO VARCHAR2(2)
    SCOTT@demo102>
    Pl reply ASAP.Since this is saturday, and saturday is an unworked day in most of countries, and since this forum is based on volunteers, you cannot ask ASAP...
    Nicolas.

  • OBIEE - changing imported column datatypes

    Hi All,
    I am trying to join 2 tables in physical layer but the columns on which I am making join condition have different datatypes defined(one is datetime,another is timestamp).Hence, I am getting error incompatible datatypes can't be joined.
    I don't want to change the columns datatypes in ohysical layer bcz I am not sure if some other report using this rpd might be using the join conditions based on existing datatypes.Is there any alternative to this?
    Please suggest.
    Thanks,
    Neha

    Please try to use this function. it is good if we have sample data for both columns.Please provide if you have issues using following function
    Evaluate( 'to_date(%1,%2)',Evaluate( 'TO_CHAR(%1)' as char,20090101) , 'yyyymmdd')
    Thanks
    NK

  • Changing column datatype value

    Can any body forward me the SQL for changing the datatype value from
    Varchar2(64) to Varchar2(2)
    Arif

    You can do that if the column is empty, or its contents size is not bigger than the new size :
    SQL> create table test_tab(a varchar2(100));
    Table created.
    SQL> alter table test_tab modify a varchar2(50);
    Table altered.
    SQL> insert into test_tab values('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
    1 row created.
    SQL> alter table test_tab modify a varchar2(40);
    Table altered.
    SQL> ed
    Wrote file afiedt.buf
      1* alter table test_tab modify a varchar2(20)
    SQL> /
    alter table test_tab modify a varchar2(20)
    ERROR at line 1:
    ORA-01441: cannot decrease column length because some value is too big
    SQL>

  • Data of column datatype CLOB is moved to other columns of the same table

    Hi all,
    I have an issue with the tables having a CLOB datatype field.
    When executing a simple query on a table with a column of type CLOB it returns error [POL-2403] value too large for column.
    SQL> desc od_stock_nbcst_notes;
    Name Null? Type
    OD_STOCKID N NUMBER
    NBC_SERVICETYPE N VARCHAR(40)
    LANGUAGECODE N VARCHAR(8)
    AU_USERIDINS Y NUMBER
    INSERTDATE Y DATE
    AU_USERIDUPD Y NUMBER
    MODIFYDATE Y DATE
    VERSION Y SMALLINT(4)
    DBUSERINS Y VARCHAR(120)
    DBUSERUPD Y VARCHAR(120)
    TEXT Y CLOB(2000000000)
    NBC_PROVIDERCODE N VARCHAR(40)
    SQL> select * from od_stock_nbcst_notes;
    [POL-2403] value too large for column
    Checking deeply, some of the rows have got the data of the CLOB column moved in another column of the table.
    When doing select length(nbc_providercode) the length is bigger than the datatype of the field (varchar(40)).
    When doing substr(nbc_providercode,1,40) to see the content of the field, a portion of the Clob data is retrieved.
    SQL> select max(length(nbc_providercode)) from od_stock_nbcst_notes;
    MAX(LENGTH(NBC_PROVIDERCODE))
    162
    Choosing one random record, this is the stored information.
    SQL> select length(nbc_providerCode), text from od_stock_nbcst_notes where length(nbc_providerCode)=52;
    LENGTH(NBC_PROVIDERCODE) | TEXT
    -------------------------+-----------
    52 | poucos me
    SQL> select nbc_providerCode from od_stock_nbcst_notes where length(nbc_providerCode)=52;
    [POL-2403] value too large for column
    SQL> select substr(nbc_providercode,1,40) from od_stock_nbcst_notes where length(nbc_providercode)=52 ;
    SUBSTR(NBC_PROVIDERCODE
    Aproveite e deixe o seu carro no parque
    The content of the field is part of the content of the field text (datatype CLOB, containts an XML)!!!
    The right content of the field must be 'MTS' (retrieved from Central DB).
    The CLOB is being inserted into the Central DB, not into the Client ODB. Data is synchronized from CDB to ODB and the data is reaching the client in a wrong way.
    The issue can be recreated all the time in the same DB, but between different users the "corrupted" records are different.
    Any idea?

    939569 wrote:
    Hello,
    I am using Oracle 11.2, I would like to use SQL to update one column based on values of other rows at the same table. Here are the details:
    create table TB_test (myId number(4), crtTs date, updTs date);
    insert into tb_test(1, to_date('20110101', 'yyyymmdd'), null);
    insert into tb_test(1, to_date('20110201', 'yyyymmdd'), null);
    insert into tb_test(1, to_date('20110301', 'yyyymmdd'), null);
    insert into tb_test(2, to_date('20110901', 'yyyymmdd'), null);
    insert into tb_test(2, to_date('20110902', 'yyyymmdd'), null);
    After running the SQL, I would like have the following result:
    1, 20110101, 20110201
    1, 20110201, 20110301
    1, 20110301, null
    2, 20110901, 20110902
    2, 20110902, null
    Thanks for your suggestion.How do I ask a question on the forums?
    SQL and PL/SQL FAQ

  • Selective XML Index feature is not supported for the current database version , SQL Server Extended Events , Optimizing Reading from XML column datatype

    Team , Thanks for looking into this  ..
    As a last resort on  optimizing my stored procedure ( Below ) i wanted to create a Selective XML index  ( Normal XML indexes doesn't seem to be improving performance as needed ) but i keep getting this error within my stored proc . Selective XML
    Index feature is not supported for the current database version.. How ever
    EXECUTE sys.sp_db_selective_xml_index; return 1 , stating Selective XML Indexes are enabled on my current database .
    Is there ANY alternative way i can optimize below stored proc ?
    Thanks in advance for your response(s) !
    /****** Object: StoredProcedure [dbo].[MN_Process_DDLSchema_Changes] Script Date: 3/11/2015 3:10:42 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- EXEC [dbo].[MN_Process_DDLSchema_Changes]
    ALTER PROCEDURE [dbo].[MN_Process_DDLSchema_Changes]
    AS
    BEGIN
    SET NOCOUNT ON --Does'nt have impact ( May be this wont on SQL Server Extended events session's being created on Server(s) , DB's )
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    select getdate() as getdate_0
    DECLARE @XML XML , @Prev_Insertion_time DATETIME
    -- Staging Previous Load time for filtering purpose ( Performance optimize while on insert )
    SET @Prev_Insertion_time = (SELECT MAX(EE_Time_Stamp) FROM dbo.MN_DDLSchema_Changes_log ) -- Perf Optimize
    -- PRINT '1'
    CREATE TABLE #Temp
    EventName VARCHAR(100),
    Time_Stamp_EE DATETIME,
    ObjectName VARCHAR(100),
    ObjectType VARCHAR(100),
    DbName VARCHAR(100),
    ddl_Phase VARCHAR(50),
    ClientAppName VARCHAR(2000),
    ClientHostName VARCHAR(100),
    server_instance_name VARCHAR(100),
    ServerPrincipalName VARCHAR(100),
    nt_username varchar(100),
    SqlText NVARCHAR(MAX)
    CREATE TABLE #XML_Hold
    ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY , -- PK necessity for Indexing on XML Col
    BufferXml XML
    select getdate() as getdate_01
    INSERT INTO #XML_Hold (BufferXml)
    SELECT
    CAST(target_data AS XML) AS BufferXml -- Buffer Storage from SQL Extended Event(s) , Looks like there is a limitation with xml size ?? Need to re-search .
    FROM sys.dm_xe_session_targets xet
    INNER JOIN sys.dm_xe_sessions xes
    ON xes.address = xet.event_session_address
    WHERE xes.name = 'Capture DDL Schema Changes' --Ryelugu : 03/05/2015 Session being created withing SQL Server Extended Events
    --RETURN
    --SELECT * FROM #XML_Hold
    select getdate() as getdate_1
    -- 03/10/2015 RYelugu : Error while creating XML Index : Selective XML Index feature is not supported for the current database version
    CREATE SELECTIVE XML INDEX SXI_TimeStamp ON #XML_Hold(BufferXml)
    FOR
    PathTimeStamp ='/RingBufferTarget/event/timestamp' AS XQUERY 'node()'
    --RETURN
    --CREATE PRIMARY XML INDEX [IX_XML_Hold] ON #XML_Hold(BufferXml) -- Ryelugu 03/09/2015 - Primary Index
    --SELECT GETDATE() AS GETDATE_2
    -- RYelugu 03/10/2015 -Creating secondary XML index doesnt make significant improvement at Query Optimizer , Instead creation takes more time , Only primary should be good here
    --CREATE XML INDEX [IX_XML_Hold_values] ON #XML_Hold(BufferXml) -- Ryelugu 03/09/2015 - Primary Index , --There should exists a Primary for a secondary creation
    --USING XML INDEX [IX_XML_Hold]
    ---- FOR VALUE
    -- --FOR PROPERTY
    -- FOR PATH
    --SELECT GETDATE() AS GETDATE_3
    --PRINT '2'
    -- RETURN
    SELECT GETDATE() GETDATE_3
    INSERT INTO #Temp
    EventName ,
    Time_Stamp_EE ,
    ObjectName ,
    ObjectType,
    DbName ,
    ddl_Phase ,
    ClientAppName ,
    ClientHostName,
    server_instance_name,
    nt_username,
    ServerPrincipalName ,
    SqlText
    SELECT
    p.q.value('@name[1]','varchar(100)') AS eventname,
    p.q.value('@timestamp[1]','datetime') AS timestampvalue,
    p.q.value('(./data[@name="object_name"]/value)[1]','varchar(100)') AS objectname,
    p.q.value('(./data[@name="object_type"]/text)[1]','varchar(100)') AS ObjectType,
    p.q.value('(./action[@name="database_name"]/value)[1]','varchar(100)') AS databasename,
    p.q.value('(./data[@name="ddl_phase"]/text)[1]','varchar(100)') AS ddl_phase,
    p.q.value('(./action[@name="client_app_name"]/value)[1]','varchar(100)') AS clientappname,
    p.q.value('(./action[@name="client_hostname"]/value)[1]','varchar(100)') AS clienthostname,
    p.q.value('(./action[@name="server_instance_name"]/value)[1]','varchar(100)') AS server_instance_name,
    p.q.value('(./action[@name="nt_username"]/value)[1]','varchar(100)') AS nt_username,
    p.q.value('(./action[@name="server_principal_name"]/value)[1]','varchar(100)') AS serverprincipalname,
    p.q.value('(./action[@name="sql_text"]/value)[1]','Nvarchar(max)') AS sqltext
    FROM #XML_Hold
    CROSS APPLY BufferXml.nodes('/RingBufferTarget/event')p(q)
    WHERE -- Ryelugu 03/05/2015 - Perf Optimize - Filtering the Buffered XML so as not to lookup at previoulsy loaded records into stage table
    p.q.value('@timestamp[1]','datetime') >= ISNULL(@Prev_Insertion_time ,p.q.value('@timestamp[1]','datetime'))
    AND p.q.value('(./data[@name="ddl_phase"]/text)[1]','varchar(100)') ='Commit' --Ryelugu 03/06/2015 - Every Event records a begin version and a commit version into Buffer ( XML ) we need the committed version
    AND p.q.value('(./data[@name="object_type"]/text)[1]','varchar(100)') <> 'STATISTICS' --Ryelugu 03/06/2015 - May be SQL Server Internally Creates Statistics for #Temp tables , we do not want Creation of STATISTICS Statement to be logged
    AND p.q.value('(./data[@name="object_name"]/value)[1]','varchar(100)') NOT LIKE '%#%' -- Any stored proc which creates a temp table within it Extended Event does capture this creation statement SQL as well , we dont need it though
    AND p.q.value('(./action[@name="client_app_name"]/value)[1]','varchar(100)') <> 'Replication Monitor' --Ryelugu : 03/09/2015 We do not want any records being caprutred by Replication Monitor ??
    SELECT GETDATE() GETDATE_4
    -- SELECT * FROM #TEMP
    -- SELECT COUNT(*) FROM #TEMP
    -- SELECT GETDATE()
    -- RETURN
    -- PRINT '3'
    --RETURN
    INSERT INTO [dbo].[MN_DDLSchema_Changes_log]
    [UserName]
    ,[DbName]
    ,[ObjectName]
    ,[client_app_name]
    ,[ClientHostName]
    ,[ServerName]
    ,[SQL_TEXT]
    ,[EE_Time_Stamp]
    ,[Event_Name]
    SELECT
    CASE WHEN T.nt_username IS NULL OR LEN(T.nt_username) = 0 THEN t.ServerPrincipalName
    ELSE T.nt_username
    END
    ,T.DbName
    ,T.objectname
    ,T.clientappname
    ,t.ClientHostName
    ,T.server_instance_name
    ,T.sqltext
    ,T.Time_Stamp_EE
    ,T.eventname
    FROM
    #TEMP T
    /** -- RYelugu 03/06/2015 - Filters are now being applied directly while retrieving records from BUFFER or on XML
    -- Ryelugu 03/15/2015 - More filters are likely to be added on further testing
    WHERE ddl_Phase ='Commit'
    AND ObjectType <> 'STATISTICS' --Ryelugu 03/06/2015 - May be SQL Server Internally Creates Statistics for #Temp tables , we do not want Creation of STATISTICS Statement to be logged
    AND ObjectName NOT LIKE '%#%' -- Any stored proc which creates a temp table within it Extended Event does capture this creation statement SQL as well , we dont need it though
    AND T.Time_Stamp_EE >= @Prev_Insertion_time --Ryelugu 03/05/2015 - Performance Optimize
    AND NOT EXISTS ( SELECT 1 FROM [dbo].[MN_DDLSchema_Changes_log] MN
    WHERE MN.[ServerName] = T.server_instance_name -- Ryelugu Server Name needes to be added on to to xml ( Events in session )
    AND MN.[DbName] = T.DbName
    AND MN.[Event_Name] = T.EventName
    AND MN.[ObjectName]= T.ObjectName
    AND MN.[EE_Time_Stamp] = T.Time_Stamp_EE
    AND MN.[SQL_TEXT] =T.SqlText -- Ryelugu 03/05/2015 This is a comparision Metric as well , But needs to decide on
    -- Peformance Factor here , Will take advise from Lance if comparision on varchar(max) is a vital idea
    --SELECT GETDATE()
    --PRINT '4'
    --RETURN
    SELECT
    top 100
    [EE_Time_Stamp]
    ,[ServerName]
    ,[DbName]
    ,[Event_Name]
    ,[ObjectName]
    ,[UserName]
    ,[SQL_TEXT]
    ,[client_app_name]
    ,[Created_Date]
    ,[ClientHostName]
    FROM
    [dbo].[MN_DDLSchema_Changes_log]
    ORDER BY [EE_Time_Stamp] desc
    -- select getdate()
    -- ** DELETE EVENTS after logging into Physical table
    -- NEED TO Identify if this @XML can be updated into physical system table such that previously loaded events are left untoched
    -- SET @XML.modify('delete /event/class/.[@timestamp="2015-03-06T13:01:19.020Z"]')
    -- SELECT @XML
    SELECT GETDATE() GETDATE_5
    END
    GO
    Rajkumar Yelugu

    @@Version : ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
        May 14 2014 18:34:29
        Copyright (c) Microsoft Corporation
        Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
    (1 row(s) affected)
    Compatibility level is set to 110 .
    One of the limitation states - XML columns with a depth of more than 128 nested nodes
    How do i verify this ? Thanks .
    Rajkumar Yelugu

  • Reg: View column datatype

    Hi Team,
    While creating the views, column automatically converted into varchar2(81) data type from number datatype.
    but stage1 table has legacy_trx_number is number data type and statg2 table has header_num is number data type.
    Just i added the highlighted part in the view. So automatiicaly converted number to varchar2 datatype. How to keep data type remain the same as source stage table datatype even though those columns used in the view.
    CREATE OR REPLACE VIEW test_view  AS
        SELECT h1.legacy_trx_number
          ||'.'
          ||h2.header_num legacy_trx_number,
          h1.legacy_trx_date,
          h1.ledger_id,
          h1.legal_entity_id,
          h1.header_record_identifier,
          h2.header_num,
          h2.gl_date,
          h2.header_value_full,
          h2.header_value
        FROM stage1 H1,
          stage2 H2
      WHERE h1.header_record_identifier = h2.header_record_identifier;
    Please help give me suggestion on this.
    Thanks in advance.

    You can do it like this!
    Example:-
    SQL> ed
    Wrote file afiedt.buf
      1  create view v_num_test
      2  as
      3* select to_number(5478||'.'||87489) result from dual
    SQL> /
    View created.
    SQL> select * from v_num_test;
        RESULT
    5478.87489
    SQL> desc v_num_test
    Name                                      Null?    Type
    RESULT                                             NUMBER

  • BLOB column datatype

    Hi
    I have one column which is of datatype BLOB.File was there in the blob column. File Contains the XML tags.My Requirement is need to extract the tag value.
    EX:in XLM i need to extract <name>Rajesh</name>
    Bottom line is Need to extract one tag value from BLOB dataype column which contains the file in which XML tags were there.
    Plz Help

    user12057782 wrote:
    Hi
    I have one column which is of datatype BLOB.File was there in the blob column. File Contains the XML tags.My Requirement is need to extract the tag value.
    EX:in XLM i need to extract <name>Rajesh</name> That's not good. BLOB should store binary data. CLOB should store character based data. XML is character based, so you could end up corrupting the XML by storing it in a BLOB.
    Oracle also has an XMLTYPE datatype specifically for storing XML data in, so why aren't you using that?
    Bottom line is Need to extract one tag value from BLOB dataype column which contains the file in which XML tags were there.Here's a basic example of extracting XML from an XMLTYPE (you can easily convert CLOB to XMLTYPE using it's constructor method)...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select XMLTYPE('<cube>
      2                                <dimension>
      3                                   <sourcename>A1</sourcename>
      4                                   <targetname>X1</targetname>
      5                                </dimension>
      6                                <dimension>
      7                                   <sourcename>B1</sourcename>
      8                                   <targetname>Y1</targetname>
      9                                </dimension>
    10                                <dimension>
    11                                   <sourcename>C1</sourcename>
    12                                   <targetname>Z1</targetname>
    13                                </dimension>
    14                             </cube>
    15                           ') as xml
    16             from dual
    17            )
    18  -- end of test data
    19  select x.*
    20  from t
    21      ,XMLTABLE('/cube/dimension'
    22                PASSING t.xml
    23                COLUMNS sourcename VARCHAR2(2) PATH '/dimension/sourcename'
    24*                      ,targetname VARCHAR2(2) PATH '/dimension/targetname') x
    SQL> /
    SO TA
    A1 X1
    B1 Y1
    C1 Z1
    SQL>If that isn't quite what you want, provide more information with your database version, example data and expected output, as detailed in the FAQ: {message:id=9360002}
    I'm surprised that as a member who's been here for 3 years+ and asked 32 questions, you still haven't understood how to ask a question so that people can help you. Perhaps that explains why you still have 27 question showing as unanswered.

  • Retrieving column datatype n its size.

    Hi..,
    I have a query regarding ODI.
    I have a source table & one target table.
    I want to write data from source table to target table...but there are two more columns in target where i like to write the datatype n size of respective rows from source table.
    Is it possible thru ODI?
    Hope for a reply.

    Hi..,
    I have a query regarding ODI.
    I have a source table & one target table.
    I want to write data from source table to target table...but there are two more columns in target where i like to write the datatype n size of respective rows from source table.
    Is it possible thru ODI?
    Hope for a reply.

  • Fact columns Datatype is changing from char to int in OBIEE 11g

    Hi ,
    I am taking measure columns - "product description","tot cost" against a dimension "project name" .
    I am generating this report in a planing form and OBIEE .
    in planing form :
    product description tot cost
    project name
    P1 A 1500
    p2 B 1700
    p3 C 1800
    in obiee report :
    product description
    project name
    P1 16 1500
    p2 17 1700
    p3 19 1800
    Somehow , measure's datatype are getting changed from char to number , in OBIEE report.
    By default , the data type for all fact's is Double .I tried changing that to varchar , but result is same .
    Do I need to change anything in physical layer / RPD .
    OBIEE version : 11.1.1.6
    Essbase version : 11.1.2

    Hi ,
    Thanks for your reply . To confirm , the data type of product description column is "double" in essbase .
    I found out ,thers's a RDBMS table , consisting of two columns - ID, text value . where product description's are in text value's with the corresponding ID's(integer values) .
    Now , when I am creating a form in planning , its fetching the text values of product description (there's some inbulit setting's available for this in plannng) .
    However , in obiee its fetching the ID values of product description .
    So ,
    1. Is there any similer setting I can do for OBIEE , so that it's fetches only text value's of product description .
    2. If not , then I have to join the essbase fact table with this RDBMS table . I am not sure how to do it .

  • New Logical Column Datatype

    I am trying to add a new logical column to the BMM layer. But by default the data type is showing as UNKNOWN and is grayed out. How can i change it? I am trying to perform a calculation on the new column added.
    Thanks!

    Hi,
    user10797474 is correct. It takes the default datatype depending on your logic. So in the properties of the column, check the "Use existing columns as source" and then click the button with the three dots. Then create your logic in this expression builder. Select the columns and formulas from the list so you do not have to type them. Once you save from the expression builder, the default datatype should be set.
    Rajesh

  • Change column datatype from varchar2 to number(10) and keep existing data

    Hi,
    I need to change the datatype on a column that already has data in it from a varchar2 to number(10). The data that is already there is not necessarily number data, however I must be able to keep the old data to. We are running 10g. Does anyone have any ideas? Thanks. Here's the current data.
    Current Values for From_Value
    T
    U
    T2
    K
    M
    A
    T
    T1
    O
    E
    S
    NSTU
    4

    Example of keeping the data in the current column and adding a new numeric column for numeric data:
    SQL> drop table t purge;
    Table dropped.
    SQL> create table t(i int, x varchar2(10));
    Table created.
    SQL> insert into t values(1, 'T1');
    1 row created.
    SQL> insert into t values(2, 2);
    1 row created.
    SQL> --
    SQL> alter table t add (xn number);
    Table altered.
    SQL> --
    SQL> begin
      2  for c in (select i, x from t)
      3  loop
      4   begin
      5   update t set xn = to_number(c.x) where i = c.i;
      6   exception
      7    when invalid_number then null;
      8   end;
      9  end loop;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> show errors
    No errors.
    SQL> select * from t;
             I X                  XN
             1 T1
             2 2                   2

  • Query to Find all the Tables and their corresponding columns,dataType in DB

    Hi all,
    I need a query which can give me all the Tables existing in my DB and their corresponding Columns existed for those tables and Datatype for each column .
    Thanks in Advance,
    viajy

    Hi,
    For your user tables you can use USER_TAB_COLUMNS.
    Just give DESC USER_TAB_COLUMNS at your SQL> prompt.
    You will know on that object.
    Regards,
    Sailaja

  • GetString() and column datatypes

    Hi,
    I have a program that reads the row values of a SELECT statement as strings.
    std::string value = resultSet->getString(IntCol); // read an integer value as string instead of getInt()
    The getString() function returns a std::string for almost all datatypes (like integer, float) correctly, except when it comes to Timestamp. Here getString() returns an empty string.
    What surprised me that it worked as well for a column with the DATE datatype (getString() returns a string formatted with the session parameter NLS_DATE_FORMAT).
    But this is not true for the Timestamp datatype. Here, I have to create explicitly a Timestamp object:
    Timestamp time = resultSet->getTimestamp();
    std::string value = time.toText(format, 6);
    Is that a bug? Why isn't the session variable NLS_TIMESTAMP_FORMAT used (like DATE)?
    Any suggestions appreciated! Thanks.
    Christian

    Use either a NLS_TIMESTAMP_FORMAT or explicitly convert timestamp to string by using TO_CHAR

  • Re: Reg: View column datatype

    Hi All,
    After changing it, I was getting the output like for legacy_trx_number.
    220135.1
    220135.2
    220135.3
    220135.4
    220135.5
    220135.6
    220135.7
    220135.8
    220135.9
    220135.1 -- It should be 220135.10 after converting into to_number(h1.legacy_trx_number||'.'||h2.header_num legacy_trx_number)
    220135.11
    220135.12
    220135.13
    220135.14
    220135.15
    220135.16
    If it is varchar2 data type then i was gettign the correct output from view query output. can you let me know how to avoid this problem.
    Thanks in advance.

    In addition to your previous thread, you have 3 choices: -
    1) If a table/view is created with number datatype with precession 2, then 220135.10 value will be stored as 220135.1 in it. In short number type ignores trailing zero after decimal.
    2)  You can stick to your view creation with varchar2 datatype.
    3) Or as Blu suggested, you can display using to_char with format code. Like for  TO_CHAR( 220135.1, 'FM999999.00' ). But along with this, your all decimal part( before 10) will also have a trailing zero with them.
    Thanks!

Maybe you are looking for

  • Agent port passed by user  Is busy

    I'm helping with their OEM 12c evaluation and we cannot get past this issue :- Issue similar to below note: EM 12c: Agent Deployment Fails With Error: "Agent port passed by user is busy and cannot proceed with the configuration" (Doc ID 1473185.1), b

  • Material Ledger Movement type Groups

    I need to activated ML in a SAP ECC 5.0 client, But When I add entries in OMX7  (Define Movements type groups of Material Ledger) I can not modify "Revaluation of consumptios" field. Is there any dependence I need to review before add a group? I have

  • Adobe AIR Corrupting JSON data?

    I am experiencing a very strange issues with Adobe AIR truncating JSON responses randomly. I have an AIR application which communicates with a server process via JSON. The issue I am experiencing is that the server is sending a valid JSON response bu

  • Dual intalled SSD recognition problem

    hello, i have upgraded my 2011 macbook pro 13" hard drive to ssd M500 and it recognized but couldnt write and did not show up finder but Disk Utility, so i googling it a lot and most of problems could fix by changing cable. so i found one cable from

  • Where is the option (preference) to eliminate the "Save to Online Account" from the Save or Save to Screen?

    Or to enter "none" in the online account. My earlier versions of Acrobat were not plagued by this.