Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    Wisconsin
    Posts
    4

    Unanswered: Adding a concatenated column to existing table

    I'm trying to add a column to an existing table. The column data is a concatenation of two other fields in the table. It must also have an alias.

    Here's what I've got, but I get an invalid datatype error on the first ||. Any ideas?

    ALTER TABLE emps
    ADD (
    first_name||' '||last_name AS full_name varchar2(46)
    );

    first_name||' '||last_name AS full_name varchar2(46)
    *

    ERROR at line 3:
    ORA-00902: invalid datatype

  2. #2
    Join Date
    Apr 2003
    Location
    Greenville, SC (USA)
    Posts
    1,155
    1. ALTER TABLE emps ADD (full_name varchar2(46))
    2. update emps set full_name = first_name||' '||last_name .....

    HTH
    Gregg

  3. #3
    Join Date
    Jan 2004
    Location
    Germantown, MD
    Posts
    34
    not sure... But I think you mean to do this:

    ALTER TABLE emps
    ADD (full_name varchar2(46));

    UPDATE emps SET full_name = first_name||' '||last_name;

    -Rip
    "The world is a dangerous place, not because of those who do evil, but because of those who look on and do nothing. "
    - Albert Einstein

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    This seems rather pointless. You are going to need a trigger to maintain that redundant data. Why not just create a view?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •