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

Tags: Database

Similar Questions

  • change the data type of a column

    Since the previous post: how to change the data type of column number to varchar2 in oracle10g

    Measures may be:
    create table TestTable (ColA varchar2 (5));
    Insert into TestTable values('12345');

    ALTER table TestTable Add (ColATemp number (5));
    setting a day of TestTable set ColATemp = ColA;

    ALTER table TestTable remove column ColA;
    change the column in table TestTable rename ColATemp CLC;

    My question is:
    If the table half million records

    setting a day of TestTable set ColATemp = ColA;

    will it be a good solution? Any performance issues? There is no index on this column.

    Sort while you do DDL, you will not be able to do any operation on the table. You the best suites you. It's a time operation, you can change the table to change the data type, but it may not work if some of the data in the table confirms no new data type of column.

    Concerning

  • How to declare the data type of a column in a select query?

    How can we give the data type of each column on the fly during the selection of rows in a query?

    the cast function converts one data type to another.

    The syntax of the cast function is:

    Cast ({expr |}) (subquery) | (MULTISET (subquery)} AS type_name)

    Select cast (22 August 2003 ' AS varchar2 (30))
    Double;

    Published by: b_ * August 12, 2011 10:08

  • 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

  • change the column size will has no

    Hi all

    I have a question on oracle 10g. I will modify one of the type of column of varchar table (100) to varchar (200).
    Initially I intend to modify the table in readonly mode, then change the column.

    But I hit the options not valid error and discovered that, in 10g, do not have this feature, so I intend to do online, but during off peak hours.
    So my question is when I change the column, if there is an insert/update / delete on the table, they would wait or they will fail?

    Please notify.

    >
    1 let say if the previous DML operation were engaged
    4 h I fire the alter column statement
    3. the DML from query, they will wait the "alter column' finished or they fail?

    When you perform the alter column, there will be a level lock table to prevent the update of the rite of the table?
    >
    Yes - but the table will lock only for a moment. Edit a VARCHAR2 column to expand it is only a change in data dictionary. No actual data is changed.

    The table should be locked to change the dictionary, and is then immediately unblocked. There will be no problem of performance. You need just one or two seconds, there where there is no DML or DDL going on for this table.

  • How can I change the columns in File-> Open views program?

    I use El Capitan 10.11.3 on a MacBook Pro. I start with a clean system. I copied my files from my backup and reinstall my programs.

    This created a problem, seeking to resolve by changing the column headings in the views of program "file-> open.

    Whatever program I use, when I open a file, the window displays currently "Date added". It is of no use to me as the "Date added" to all my files is exactly the same - date, I have copied them on my own hard drive brilliant from my backup.

    In finder views, I can opt to display "update" instead of "added". So I order the files by date, whenever this is useful.

    However, whenever I try to open a file in a program, it is impossible to find things by date, because they all have the same "date added". I need to be able to see the "change date".

    I find anywhere that allows me to change this, either in the system preferences, or when opening a specific program. Don't I found clues to aid or the forum.

    Can someone tell me what I need to do?

    Thanks in advance.

    Mike

    Right click on the headers (if in list view) and select the headers you want to see.

    Alternatively, use the Arrangement to organize the desired date.

  • A statement UPDATE changes the line if the update changes the column even value?

    HI -.

    I have a main classification and the corresponding audit table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time. He is not able to determine that the value is the same.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    Best regards

    I have a main Table and the corresponding Audit Table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211

    Why?

    You try to resolve what made you what are the PROBLEM that select as the solution?

    Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time.

    Yes - it is EXACTLY what you say that you wanted to do and EXACTLY what the code does in this article.

    He is not able to determine that the value is the same.

    I think you mean that the code does NOT check if the value is the same. You can certainly change the code to do this check. But I have a question to start with your need for such a solution.

    My goal is to load the audit table data if the value in a cell in the main table is really have changed.

    OK - then modify the code to check EACH COLUMN and compare its NEW value to the OLD value and insert only the table of audit if SOME (or columns you care specifically) have changed.

    A statement UPDATE changes the line if the update changes the column even value?

    It depends on what you mean by 'change the line '. Of course to update a column with the SAME value does not change the resulting data value.

    But the physical structure of the line, the location of the pieces of line and information in the header block (YVERT, etc.) will change. And, as others have said Oracle doesn't know and doesn't care, so if the new value of a column is the same as the old value will create redo, undo and the rest.

    Start over and tell us what PROBLEM you're trying to solve. Then we can help you find the best way to solve it.

  • Change the column header font size

    Hi all

    In the view of the table, I am able to change the size of the font of a column, but this does not affect the column header.
    This translates into having the data in a single font size and position of the original size.
    I tried to update the class column header in view.css (analytics\res\s_oracle10\b_mozilla_4):
    . {ColumnHdg}
    color: #3c3c3c;
    border-style: solid;
    border-color: #c9cbd3;
    border-width: 0 1px 1px 0;
    background-color: #cfe0f1;
    do-size: 8pt;
    make-weight: bold;
    vertical-align: bottom;
    padding: 1px 2px 2px 3px;
    text-align: left;
    }
    but this does not at all affect the size of the text.

    NB: I refresh and clear the cache of the browser every time I make a change in the CSS file.

    One knows what the problem is. ??

    Concerning
    Adil

    Hello
    To change the column heading, go to the properties of column-> data format-> next to the column name, you can see change format-> give the font size of the column header.
    Is that what you want?

    Kind regards
    Srikanth

  • Windows Media Player - change the columns that appear under 'Now Playing'

    I would like to change the columns displayed in the views now play and Windows Media Player play list.  The factory default is to show only the fields title and length.  It wouldn't be that big a deal this is something fairly simple to access the page layout options, hit choose columns and select the check boxes for the columns I want to show... but the title and duration are the only fields that it allows me to select from.  He still refuses to allow me to select anything else.  I know that there is a way to display more information, but for the life of me I don't remember how to do so that he can do.  Help?

    Hey,.

    I've recreated the scenario on my Windows Media Player. It shows all the info like length, side, title, album, artist to contribute. Appoint you.

    Scan SFC should be your friend.

    http://support.Microsoft.com/kb/929833/en-us

  • How to change the column ordering the interactive report?

    How to change the column ordering the interactive report?

    Hello

    Run the report as a developer, click on the "wonder wheel", click "Select columns" and reorder your columns in the box 'report '.
    Then click again on the "wonder wheel", click on save report and save the default state.

    Greetings,
    Roel
    http://roelhartman.blogspot.com/
    You can reward this response in marking it as useful or Correct ;-)

  • Add/change the columns of data type (scripting)

    Hello

    I am writing a script to add default columns and their values in tables. So far, for me, it is possible to add columns to an existing table in the model.

    Then, I want to add value to the data type. I discovered there is a method called getDataType(). So far, I have not found the "setter; for this property.

    Like other scripts, I started by creating a table with columns, and then using the API to read the values.

    A simplified version of my code:

    get the columns of table

    myTab var = model.getTableSet () .getByName ("T_POSITIONS");

    colArray = myTab.getElementsCollection () .toArray ();

    loop through columns

    for (i = 0; i < colArray.length; i ++) {}

    the type of var data = colArray [i] .getDataType ();

    model.getAppView () .log (colArray [i] + "a datatype" + dataType);

    colArray [i] .setDataType ("VARCHAR2 (1)");

    }

    An error occurs when I want to run this script: could not find setDataType function in the object ID.

    I can't find the right method to add/change the datatype property.

    Any information would be appreciated.

    Hi Bart,.

    Here's what's in the column in the XML file:

    
    FDB11R21
    EMPLOYEES
    FIRST_NAME
    
    2015-01-13 12:45:08 UTC
    First name of the employee. A not null column.
    HR_870
    true
    false
    1
    LOGDT024
    20 BYTE
    false
    
    

    20 BYTES

    If you need set the size in "20 BYTE" or "20 CHAR".

    Philippe

  • change the column type of data in large tables

    Hello

    I have a very large table 3 TB and 97 scores and I need to extend the size of a column. This operation can take a long time and I'm afraid that it will block some SQL operations. What is the recommended way to do this? Can I use alter column? Should I add the column, copy values, delete the former and rename it?

    Kind regards

    Nestor Boscan

    Because you widen the column, all existing values are guaranteed to fit the new size. This should happen fairly quickly. If you were however decrease the size of a column, each value must be checked first before the DOF could complete to check it might all go in the smaller space. Change the alter table is a great value.

    If these fields are variable length (number, varchar2), then the space doesn't have to be 'reserved' for future data. Oracle will take care of the future inserts or updates of larger data as usual. If you increase a fixed length as a CHAR data type, then it is another story.

  • 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);

  • Changes of data type of column between the local and remote database

    Please point me the proper documentation, so I can understand what is happening.and how to solve the problem in the short term until we can change the database character set to match the remote database.

    Details:

    Remote database: set of 12 c CARS characters AL32UTF8

    Database local 11g 11.2.0.4 as UTF8 character.

    CREATE TABLE local_table_t AS (SELECT NAME FROM reference_table_t@remotedb)

    the NAME column in reference_table_t to remotedb is varchar2 (10 byte), it creates this column in local_table_t as varchar2 (30 bytes)

    CREATE TABLE local_table2_t AS (SELECT NAME FROM reference_table2_t@remotedb)

    the NAME column in reference_table_t to remotedb is varchar2 (10 char), it creates this column in local_table_t as varchar2 (30 char)

    This same problem also happens with views materialized from the remotedb.

    Thank you

    Dave.

    Found note size double or triple column when using (materialized) views / DEC in a db AL32UTF8 and the dblink pointing to a non-AL32UTF8 db (or vice versa). (Doc ID 1592514.1)

    that answers my question.

    Dave.

  • 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.

  • CHD: the string is used as an index of change in data type? String to double?

    Hello

    I'm new to the tiara. I'm reading the line of a channel number and then to read the data of a channel which is in the same line of another channel.

    That's why I use the SMC function but my index seems not to fit. What I need to change in the code?

    error:

    CHD (2, NOVALUE): = 785 wird die Textvariable «...» CHD (2, > N)

    Code:

     

    DIM intloop, zeilenwerte
    Line DIM, aktwert, index
    Call ChnAlloc ("zeilenwerte", lang, 1, DataTypeFloat64) ' Create channel, 'lang' is the size of a channel
    index = 0
    index = 1 to lang
    index = index + 1
    aktwert zeit (index) = ' get the value that will be compared to the SOPS in the following line of code
    Line = PNo (myChannel, aktwert) ' it returns the line only by comparing aktwert valued myChannel
    CHD (line, zeilenwerte) = intloop ' <--->here the error. try to get the value in a line @index do String data types does not match? what do I do then?
    Next

    Thank you very much for your help!

    Buddhist salvation,

    It seems to me that you would be better to use "Linear Mapping" in the palette of ANALYSIS "Suitable curve", but you should be able to get your code works by passing the name of the channel in this second parameter instead of an empty string variable.  You would have noticed that if you had OPTION EXPLICIT the first line of your code - always a good idea.

    Brad Turpin

    Tiara Product Support Engineer
    National Instruments

Maybe you are looking for

  • How can I reset my Terminal?

    I open Terminal, and it is what appears: Last login: my Mar 21 09:57:51 on ttys000 -bash: rt: command not found -bash: /Users/maxchapin/.bash_profile: line 3: close syntax error unexpected token 'then' -bash: /Users/maxchapin/.bash_profile: line 3: '

  • update the apps created from an old email address that is not in use most

    created from an old email address that is not in use most I am currently updating the purchased applications that were created when I got an e-mail and password. I have more access to this email address, nor I remember the old password. Any ideas? Th

  • TouchSmart screen problem

    My 2 year 1/2 old Touchsmart 300 has developed a thin vertical lines and cut color - a bit like a thermal image - not as clear that the color was.  Someone said that maybe it's a problem of graphics cards and because there is no separate Tower, maybe

  • HP Envy DV - 7 7292nr: HP Envy DV - 7 7292nr mPCI-e

    HelloI searched for a way to improve my laptop graphics card, but then I discovered that I can't do anything with it. (nVidia GTX 650 M).Recently, I found a device that lets you use a graphics card of regular size on laptops (BPLUS PEA4H) office. It

  • digital analog in a queue

    I want to create a queue for analog and digital data. The attached vi has two. How would you do different data type 2 feed to a queue? Should a digital waveform and an analog wave form to enter data in a queue. Any ideas? I use cDAQ-9172 and NI 9401