Change data type for the column in a table - Oracle 8i

Team,

I need to change a VARCHAR2 column in number.

ALTER table xyz change number abc;

By giving the above statement, it says I need empty this column before you change.

I can't change the data type before emptying this column.

Please indicate any other solution. Give me some suggestions.

Empty the column for me here BIG task.

user11081688 wrote:
I can't change the data type before emptying this column.

Not according to the documentation:

You can change the data type of any column or decrease the size of the entire column if all rows in the column contains NULL values.

Please indicate any other solution. Give me some suggestions.

You can add another column with the correct data type.

ALTER TABLE xyz ADD COLUMN def NUMBER;
UPDATE TABLE xyz SET def = TO_NUMBER(abc);
ALTER TABLE xyz DROP COLUMN abc;
ALTER TABLE xyz ADD COLUMN abc NUMBER;
UPDATE TABLE xyz SET abc = def;
ALTER TABEL xyz DROP COLUMN xyz;

If I remember correctly, Oracle 8i does not support the change of name of column if this solution is a bit more complicated than 9i and above. Another option would be to create a new table with CREATE TABLE AS... SELECT, drop the old one and rename a new one to the old.

Tags: Database

Similar Questions

  • change the data type of the columns

    Oracle 10g version.
    I have a table with 150 columns.
    I would like to change the data type of the columns in my table to varchar.
    Do we have a query for this task?

    Thank you.

    Not knowing yet what you meet John:

    If your table is empty, you can use the datadictionary to generate a statement and run the query to a file that makes the DDL using dynamic SQL or spool and run that...

    Example:

    MHO%xe> create table bla (col1 number, col2 number);
    
    Tabel is aangemaakt.
    
    MHO%xe> select column_name, data_type from user_tab_columns where table_name = 'BLA';
    
    COLUMN_NAME                    DATA_TYPE
    ------------------------------ ---------------------------------------------------------------------
    COL1                           NUMBER
    COL2                           NUMBER
    
    MHO%xe> declare
      2    l_sql varchar2(4000);
      3    l_sep varchar2(1);
      4  begin
      5    l_sql := 'alter table BLA modify ('||chr(10);
      6    for rec in ( select column_name from user_tab_columns where table_name = 'BLA')
      7    loop
      8      l_sql := l_sql||l_sep||' '||rec.column_name||' varchar2(50)'||chr(10);
      9      l_sep := ',';
     10    end loop;
     11    --
     12    dbms_output.put_line(l_sql||' )');
     13    --
     14    execute immediate l_sql||' )';
     15    --
     16  end;
     17  /
    alter table BLA modify (
     COL1 varchar2(50)
    , COL2 varchar2(50)
     )
    
    PL/SQL-procedure is geslaagd.
    
    MHO%xe> select column_name, data_type from user_tab_columns where table_name = 'BLA';
    
    COLUMN_NAME                    DATA_TYPE
    ------------------------------ ---------------------------------------------------------------------
    COL1                           VARCHAR2
    COL2                           VARCHAR2
    
  • How to recover the data type of a column in a table?

    Hello

    I want to retrieve the data type of a column in a table. At the moment I'm querying attribute 'OCI_ATTR_DATA_TYPE', but it is SQLT_CHR varchar2 and nvarchar2 data type columns. I need to make a distinction between these columns of two separate data types. Y at - it all API through which I could get the exact data type of a column, i.e. "nvarchar2?

    Thanks in advance.

    Hashim

    Hello

    It is not a very direct way to do it. What you can do is to call OCIDescribeAny on the table that you want to get information. You can then get the OCI_ATTR_CHARSET_FORM attribute for the column. If the value of the attribute that you get is SQLCS_IMPLICIT, that would mean its a varchar/char/varchar2 column regular. If you get SQLCS_NCHAR, this means that the column is NCHAR. You can get the example of it here:

    http://download.Oracle.com/docs/CD/B14117_01/AppDev.101/b10779/oci06des.htm#446491

    Just look for the section "Recovering for a Table column Datatypes".

    Thank you
    Sumit

  • y at - it Systemtable of the data types of the column?

    Is QUESTION 1 Systemtable of the data types of the column?

    _________________________________________________________________
    QUESTION2

    IF REGEXP_SUBSTR (p_datatype, "[''!" [¤ % & / =? *; >: <]') IS NOT NULL

    We say: you can not write that! » ¤ % & / = ? ' ^ * ; >: <-each of each example ">".

    How can I say... you can NOT write PENIS, NIPPLES, hole word "NIPPLES".
    __________________________________________________________________

    Published by: user619226 on 19-sep-2008 01:15

    Do you mean something like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_txt VARCHAR2(200) := 'FRED,JOE';
      3  begin
      4    IF regexp_like(v_txt, '^[[:alnum:]]*$') THEN
      5      dbms_output.put_line('Text is OK as it contains just a word');
      6    ELSE
      7      dbms_output.put_line('Text is not OK.  Must only contain a single word');
      8    END IF;
      9* end;
    SQL> /
    Text is not OK.  Must only contain a single word
    
    PL/SQL procedure successfully completed.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_txt VARCHAR2(200) := 'FRED';
      3  begin
      4    IF regexp_like(v_txt, '^[[:alnum:]]*$') THEN
      5      dbms_output.put_line('Text is OK as it contains just a word');
      6    ELSE
      7      dbms_output.put_line('Text is not OK.  Must only contain a single word');
      8    END IF;
      9* end;
    SQL> /
    Text is OK as it contains just a word
    
    PL/SQL procedure successfully completed.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    v_txt VARCHAR2(200) := 'FRED JOE';
      3  begin
      4    IF regexp_like(v_txt, '^[[:alnum:]]*$') THEN
      5      dbms_output.put_line('Text is OK as it contains just a word');
      6    ELSE
      7      dbms_output.put_line('Text is not OK.  Must only contain a single word');
      8    END IF;
      9* end;
    SQL> /
    Text is not OK.  Must only contain a single word
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • table col name get the details of the table column and inserting of values depending on the data type of the column

    Hello

    I am train to write a procedure where I would spend the table as a parameter name and then the code would determine it is column names, and then he would insert records in each column depending on the data type. could someone help me with this.

    Thank you

    SM

    Hello

    Perhaps you need to dummy data just for the table.

    Here is my exercise

    create or replace
    procedure generate_rows(p_table_name varchar2, p_count number)
    is
      --
      function insert_statement(p_table_name varchar2) return clob
      is
        l_columns clob;
        l_expressions clob;
        l_sql clob default
          'insert into p_table_name (l_columns) select l_expressions from dual connect by level <= :p_count';
      begin
        select
          -- l_columns
          listagg(lower(column_name), ',') within group (order by column_id),
          -- l_expressions
          listagg(
            case
            when data_type = 'DATE'
              then  'sysdate'
            when data_type like 'TIMESTAMP%'
              then  'systimestamp'
            when data_type = 'NUMBER'
              then  replace('dbms_random.value(1,max)',
                      'max', nvl(data_precision - data_scale, data_length)
                    )
            when data_type = 'VARCHAR2'
              then  replace(q'|dbms_random.string('a',data_length)|',
                      'data_length', data_length
                    )
            else
                    'NULL'
            end, ',') within group (order by column_id)
        into
          l_columns,
          l_expressions
        from user_tab_columns
        where table_name = upper(p_table_name);
        --
        l_sql := replace(replace(replace(l_sql,
          'p_table_name', p_table_name),
          'l_columns', l_columns),
          'l_expressions', l_expressions);
        -- debug
        dbms_output.put_line(l_sql);
        --
        return l_sql;
      end;
    begin
      execute immediate insert_statement(p_table_name) using p_count;
    end;
    /
    
    -- test
    create table mytable(
      id number(4,0),
      txt varchar2(10),
      tstz timestamp with time zone,
      dt date,
      xml clob
    )
    ;
    set serveroutput on
    exec generate_rows('mytable', 10);
    select id, txt from mytable
    ;
    drop procedure generate_rows
    ;
    drop table mytable purge
    ;
    
    Procedure GENERATE_ROWS compiled
    Table MYTABLE created.
    PL/SQL procedure successfully completed.
    
    insert into mytable (id,txt,tstz,dt,xml) select dbms_random.value(1,4),dbms_random.string('a',10),systimestamp,sysdate,NULL from dual connect by level <= :p_count
            ID TXT
    ---------- ----------
             3 WnSbyiZRkC
             2 UddzkhktLf
             1 zwfWigHxUp
             2 VlUMPHHotN
             3 adGCKDeokj
             3 CKAHGfuHAY
             2 pqsHrVeHwF
             3 FypZMVshxs
             3 WtbsJPHMDC
             3 TlxYoKbuWp
    
    10 rows selected
    
    Procedure GENERATE_ROWS dropped.
    Table MYTABLE dropped.
    

    and here is the vision of Tom Kyte for the same https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2151576678914

    Edit: to improve my code, it must use p_count as bind as Tom.

  • The date type of the column in the view

    Hello

    I would like to keep the start_date column type as a "date" type. But when create the view like below the type of the column is automatically set to varchar2 (11)

    {code}
    create table emp
    (digital emp_no
    , varchar2 (10) name
    start_date date);

    insert into the emp
    values
    (10, "Alan", January 1, 2010 "")
    insert into the emp
    values
    (20, 'Smith', may 12, 2000 ')

    create or replace view emp_v
    (emp_no
    first name
    start_date
    )
    as
    Select
    e.emp_no
    e.first_name
    , to_char (e.start_date, ' Mon-dd-yyyy "")
    from emp e
    {code}

    Thanks in advance
    Concerning
    Anna

    insert into the emp
    values
    (10, "Alan", January 1, 2010 "")
    insert into the emp
    values
    (20, 'Smith', may 12, 2000 ')

    you forcing oracle to convert string to date here - the best practice is to say explicitly what you mean with a to_date()

    the reason for which the view is created with a varchar column is that you explicitly convert a character with to_char() value, something you don't need as demonstrated above the column date.

  • How do I edit/change data type on the report which has been selected by mistake


    Hello

    I've created a report in the APEX and a column is in error because the data type of a supposed to be a varchar2 column, but somehow the report was created with a data type Date. I want to change the data type without re-creating the whole report. Can anyone help? I tried to edit the report but could not be able to understand.

    Help...

    I found a solution for this, I thank you.

  • How can I find what is the data type of a column of a Table in oracle or SQL?

    (a) what happens if I want to know the type of data in a specific column in the Table.

    (b) how to find the column data types?

    Can someone help me please. I am new to oracle and try to learn a few tricks

    Hello

    How to do

    SQL > desc

    SQL> desc emp
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     EMPNO                                     NOT NULL NUMBER(4)
     ENAME                                              VARCHAR2(10)
     JOB                                                VARCHAR2(9)
     MGR                                                NUMBER(4)
     HIREDATE                                           DATE
     SAL                                                NUMBER(7,2)
     COMM                                               NUMBER(7,2)
     DEPTNO                                             NUMBER(2)
    
  • Disable the previous dating date picker in the column in a table

    can someone please help.

    on the date column in a table, need to disable previous dates.

    Current functionality. But when the validation page gets updated and the user is able to select earlier dates.



    To restrict the datePicker for new lines changed the URL of the button 'Add Row '.

    javascript:myAddRow();

    In the page edit, I added this to "Javascript > function and Variable global statement.

    function myAddRow()

    { apex.widget.tabular.addRow();

    $("td[headers='DETAIL_DATE'] input:last")

    .datepicker("option","changeMonth",false)

    .datepicker("option","minDate",$v("P2_MASTER_MONTH_MINDATE"))

    .datepicker("option","maxDate",$v("P2_MASTER_MONTH_MAXDATE")); };

    https://Apex.Oracle.com

    w/u/p: nani5048/test/test

    App 92603 5 page

    Thank you

    Nani

    I created a dynamic action

    the loading of the page

    $("td [en-têtes = 'STATUS_DATE'] entrée")

    . DatePicker ("option", "minDate", $v ("P5_MASTER_MONTH_MINDATE"));

    as well as the global javascript function

    function myAddRow() {}

    apex.widget.tabular.addRow ();

    $("td [en-têtes = 'STATUS_DATE'] entrée")

    . DatePicker ("option", "minDate", $v ("P5_MASTER_MONTH_MINDATE"));

    }

  • Disable previous Dates for date picker in the column in a table

    Hi all

    I'm in the form of the building where it contains details of the Transaction and I want to provide validations for start date and end date by disabling dates previous calendar datepicker.

    I wrote Javascript code in page load >service and global variables declaration:

    function f_disable_date(pThis){
        var row_id  = pThis.id.substr(4);  
        var start_date = $('#f02_'+row_id).val(); 
        
        //$(function() {
        $( "#f02_" ).datepicker({ minDate: -4});
    //});
    }
    

    But it is not disable dates. Please provide suggestion to make it work.

    APEX VERSION: 5.0

    Kind regards.

    See page 3

    I created a dynamic action

    real action on page load

    $("td [en-têtes = 'START_DATE'] entrée")

    . DatePicker ("option", "minDate", $v ("P3_X"));

    in P3_X

    matches the element hidden with select (sysdate-4) double value;

    its working fine

    But at the time of the Add_row()

    Just call it by making it as a javascript function so that it is also applicable to the new line

    I hope you got the point

  • How 2 call a procedure with the data type for the parameter Ftree.NODE

    Hello

    in this link
    http://Andreas.Weiden.ORCL.over-blog.de/article-29307730.html


    Down in the page after you run the package, I created the procedure and it compiled successfully but when call PR_WTNS in trigger WHEN-TREE-NŒUD-SELECTED

    PROCEDURE PR_WTNE (i_ndNode IN Ftree.NODE);

    as

    PR_WTNE (i_ndNode Ftree.NODE);


    I got the error message; A wrong number or types of argument in the call

    pls I'm stuck can help any one?


    Kind regards

    Abdetu...

    Published by: Abdetu on October 24, 2010 02:36

    Published by: Abdetu on October 24, 2010 02:36

    YKou have to give a variable of type Ftree.NODE when calling this function. If called fromm a WHEN-TREE-NODE-SELECTED-trigger, use: SYSTEM. TRIGGER_NODE

  • change data type...

    Hello...

    Change the data type of a column... replacement... it generates the error...
    ERROR at line 1:
    ORA-01439: column to be modified must be empty to change datatype 
    How can I change the data type of the column, without trucating and re - insert the records...

    Thank you
    Baskar.l

    Baskar.l wrote:
    Hello..

    is there a way to take the table offline? and do... rather than shoot the PB... Suppose that even if it is the activity less period... is the new records inserted when you change the column will be inserted in the new column?

    Thank you
    Baskar.l

    There is no need to bring the entire base down. Choose a time of low activity and go for it!

    If you are on 10g there is a chance that it will fail with an ORA-00054 as an exclusive table lock is necessary. If not you will have to try again.

    If you are in 11g, add a column does not require an exclusive lock, but drop the column will be even if the risk is always there.

    HTH!

  • How to change the data type of a column after the creation of the table

    It comes to my table desc

    SQL > desc job1

    Name                                      Null?    Type

    ----------------------------------------- -------- ----------------------------

    JOB_CODE NOT NULL VARCHAR2 (3)

    JOB_CLASS VARCHAR2 (30)

    CHG_HOUR NUMBER (5.2)

    OVERTIMECHARGE NOT NULL NUMBER

    I want to change column CHG_HOUR to store numbers up to 12 digits in length (including the decimal points).

    I tried the following and it did not help

    SQL > alter table job1 change column chg_hour number (6.6);

    ALTER table job1 change column chg_hour number (6.6)

    *

    ERROR on line 1:

    ORA-01735: invalid option of ALTER TABLE

    SQL > alter table job1 change chg_hour number (6.6);

    ALTER table job1 change chg_hour number (6.6)

    *

    ERROR on line 1:

    ORA-01438: value larger than the precision specified for the column

    where I'm going wrong?

    Hello

    I want to change the CHG_HOUR column to store numbers up to 12 digits in length (including the decimal points).

    I tried the following and it did not help

    ALTER table job1 change chg_hour number (12.6);

  • A question about the conservation of fields (hour, min, sec) time DATE type in the table on the changes of NLS_DATE_FORMAT

    Hello

    Oracle version: 12.1.0.1.0 - 64 bit

                      OS:   Fedora Core 17 X86_64

    My question is about the conservation of fields (hour, minute, second) time DATE type in the array on NLS_DATE_FORMAT changes.

    Take the following test case:

    SQL> create table tmptab(dateval date);
    
    Table created.
    
    SQL> alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
    
    Session altered.
    
    SQL> insert into tmptab(dateval) values('2014-01-01 00:00:00');
    
    1 row created.
    
    SQL> insert into tmptab(dateval) values('2014-01-01 10:00:00');
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> select * from tmptab;
    
    DATEVAL
    -------------------
    2014-01-01 00:00:00
    2014-01-01 10:00:00
    
    SQL> alter session set nls_date_format = 'yyyy';
    
    Session altered.
    
    SQL> select * from tmptab where dateval > '2014';
    
    no rows selected
    
    SQL>
    

    I don't understand why it returns nothing. The second test case above insert statement inserted a line with 10 as the value for the time of the DATE field column dateval.

    Accordingly, while comparing this with the literal '2014' (which based on the new value of NLS_DATE_FORMAT = "yyyy" is implicitly converted to DATE), shouldn't the above query returns the line 2014-01-01 10:00 ?

    I mean, I changed the NLS_DATE_FORMAT but data from time in the table fields are preserved and that's why they should normally be taken into account in the comparison of date.

    What I'm trying to say is that for me (Please correct me if I'm wrong), no matter what NLS_DATE_FORMAT configuration is the following test

    SQL> select * from tmptab where dateval > '2014';
    

    is the same thing that

    SQL> select * from tmptab where dateval > to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss');
    

    And because the line 2014-01-01 10: 00:00 in the tmptab table. The following test

    2014-01-01 10:00:00 > to_date('2014-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
    

    evolves normally true (beucase of TIME = 10 on the left side of the test) and therefore this line must be returned which is not the case in the test above.

    You kindly could you tell me what I misunderstood?

    Thanks in advance,

    This is the price for the use of implicit conversions. Implicit DATE conversion rules are not as direct as it can be assumed. In your case, all you provide is year as date format. In this case date implicit conversion rules assumes that month in the current month, day 1 and time as 00:00:00.

    SQL > alter session set nls_date_format = "yyyy";

    Modified session.

    SQL > select to_char (to_date ('2014 "), ' mm/dd/yyyy hh24:mi:ss') twice;

    TO_CHAR (TO_DATE('20)
    -------------------
    01/08/2014-00:00:00

    SQL >

    So, when you start:

    Select * from tmptab where dateval > '2014 '.

    Oracle implicitly converts date using "YYYY", which translates as August 1, 2014 '2014'. That's why your quesry returns no rows.

    SY.

  • Display the data type of a column in the status bar

    Hi all

    n pl/sql developer, when I select a column in a table.

    If I clicked with the mouse on the column in the query results box, it shows me the type of data and the size of the column in the status bar

    Developer SQL does not by default,

    is there an option I can change to do the same task?

    Thank you

    No, you will need to open a popup DESC of the query to see the data types of the data returned.

Maybe you are looking for