How to fill the new column with values based on the subquery

How can I fill a new column (teamid) with the following query below, at my table dept? I'm empty/null entries in teamid collar when I run the code ff:

ALTER table dept add (teamid varchar2 (15));

Update dept

define the teamid = select upper (substr (deptname, 1, 3)) | Upper (substr (Color, 1, 2)) | rownum

of the Department;

Want to output:

DEPTNAME COLOR TEAMID
SALESORANGESALOR1
ACCOUNTINGBLUEACCBL2
BILLINGYELLOWBILL3
SQL> create table dept as
  2  select 'SALES' deptname, 'ORANGE' color from dual union all
  3  select 'ACCOUNTING' deptname, 'BLUE' color from dual union all
  4  select 'BILLING' deptname, 'YELLOW' color from dual
  5  /
Table created

SQL>
SQL> select * from dept;
DEPTNAME   COLOR
---------- ------
SALES      ORANGE
ACCOUNTING BLUE
BILLING    YELLOW

SQL>
SQL> alter table dept add(teamid varchar2(15));
Table altered

SQL> update dept set teamid = upper(substr(deptname,1,3)) || upper(substr(color,1,2)) || rownum;
3 rows updated

SQL> select * from dept;
DEPTNAME   COLOR  TEAMID
---------- ------ ---------------
SALES      ORANGE SALOR1
ACCOUNTING BLUE   ACCBL2
BILLING    YELLOW BILYE3

SQL> rollback;
Rollback complete

SQL> drop table dept purge;
Table dropped

SQL>

----

Ramin Hashimzade

Tags: Database

Similar Questions

  • I have a column with two values, separated by a space, in each line. How to create 2 new columns with the first value in a column, and the second value in another column?

    I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?

    Add two new columns after than the original with space separated values column.

    Select cell B1 and type (or copy and paste it here) the formula:

    = IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    shortcut for this is:

    B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')

    C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")

    or

    the formula of the C1 could also be:

    = IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")

    Select cells B1 and C1, copy

    Select cells B1 at the end of the C column, paste

  • Please let me know how I can add a new column with a constraint not null, table already has data, without falling off the table... Please help me on this issue...

    Hello

    I have an emp_job_det with a, b, c columns table. Note that this TABLE ALREADY has DATA OF THESE COLUMNS

    IAM now add a new column "D" with forced not null

    Fistly I alter the table by adding the single column "D", if I do, the entire column would be created with alll of nulls for the column DEFAULT D

    ALTER table emp_job_det Add number D; -do note not null CONSTRAINT is not added

    Second... If I try to add the constraint not null, get an eoor as already conatained null values...

    (GOLD)

    In other words, if I put the query

    ALTER table emp_job_det Add number D NOT NULL; -THROWS ERROR AS TABLE ALREADY CONTAINS DATA

    So my question is how how can I add a new column with a constraint not null, table already has the data, without falling off the table

    Please help me on this issue...

    Add the column without constraint, then fill the column. Once all the rows in the table are given in the new column, and then add the constraint not null.

  • How to take a column of duplicate names and fill a different column with the same names, excluding duplicates?

    How to take a column of duplicate names and fill a different column with the same names, excluding duplicates?

    I find easier to use this copy separate Automator Service (download Dropbox).

    To install in your numbers > Services, double-click menu just the package downloaded .workflow and if necessary give permissions in system preferences > security & privacy.

    To use, just:

    1. Select the cells in the column with duplicate names.
    2. Choose separate copy in numbers > Services menu.
    3. Click once in the upper cell where you want the deduplicated values appear.
    4. Command-v to paste.

    SG

  • New column default value for value and to cancel the generation

    Hello

    When you add a new column with a default value that is defined in a table that has existing records, are there the undo data generated?

    Thank you

    Christophe Lizé

    Hoek wrote:
    Hello, Solomon,

    Congratulations to you, in the first place.

    Thank you.

    I am aware THAT DDL is implicitly committed. If there is a way to show there is generated cancellation, I would like to know how.

    Of course, some cancellations are generated when the statement ALTER TABLE is issued. And of course, undo is generated with respect to the DEFAULT value. If you need a test case with a larger table to separate the apples to oranges:

    SQL> CREATE TABLE tbl(
      2                   x NUMBER
      3                  )
      4  /
    
    Table created.
    
    SQL> INSERT
      2    INTO tbl(
      3             x
      4            )
      5    SELECT  level
      6      FROM  dual
      7      CONNECT BY level < 100001
      8  /
    
    100000 rows created.
    
    SQL> CREATE OR REPLACE
      2    TRIGGER AFTER_ALTER
      3      AFTER ALTER
      4      ON DATABASE
      5      DECLARE
      6          v_cnt NUMBER;
      7      BEGIN
      8          SELECT  used_urec
      9            INTO  v_cnt
     10            FROM  v$transaction;
     11          DBMS_OUTPUT.PUT_LINE('Undo records used: ' || v_cnt);
     12  END;
     13  /
    
    Trigger created.
    
    SQL> SET SERVEROUTPUT ON
    SQL> ALTER TABLE tbl
      2    ADD y VARCHAR2(10) DEFAULT 'hoek'
      3  /
    Undo records used: 268215
    
    Table altered.
    
    SQL>  
    

    SY.

  • How to fill the canvas with lines

    < mx:Canvas id = "b1" x = "10" y = "10" height = "40" width = "300" borderStyle = "solid" borderColor = "black" / >

    When I want to draw lines with difference of 15 pixels to fill the entire canvas I wrote the following

    for (var i: int = b1.x + 15; i < b1.x + b1.width; i = i + 15)
    {
    var line1:UIComponent = new UIComponent();
    var lineThickness1:Number = 1;
    var lineColor1:Number = 0 x 000000;
    var lineAlpha1:Number = 1;
    LINE1. Graphics.LineStyle (lineThickness1, lineColor1, lineAlpha1);
    LINE1. Graphics.MoveTo (i, B1.y);
    LINE1. Graphics.LineTo (i, B1.y + B1. Height);
    this.addChild (line1);
    }

    It works very well

    LLY,

    < mx:Canvas id = "b4" x = "600" y = "200" height = "60" width = "300" borderStyle = "solid" borderColor = rotation "black" = "40" / >

    I have the canvas above with the "b4" id only difference is that this canvas rotation

    How to fill the canvas with lines that I just did above?

    Hope this code will help you,

    for(var i: int = 15; i < b4.width; i = i + 15) {
         var line1: UIComponent = new UIComponent();
         var lineThickness1: Number = 1;
         var lineColor1: Number = 0x000000;
         var lineAlpha1: Number = 1;
         line1.graphics.lineStyle(lineThickness1, lineColor1, lineAlpha1);
         line1.graphics.moveTo(i, 0);
         line1.graphics.lineTo(i, b4.height - 1);
         //Add line in canvas instead of main container
         b4.addChild(line1);
    }
    
    
    
  • How to create a new project with other page with the new version of Muse layouts?

    Hello
    If someone would continue to operate as before with the inadmissible Muse version... is - this posible to have both versions installed? or how to create a new project with other page with the new version of Muse layouts?
    Or how to download third party) 3 different configurations (desktop/tablet/mobile) under the same url with a clean result, like up yet with the Muse does not?

    Thanks for any help,

    Patrick

    Use the new version! What you want to achieve, will work! Go to the 'Page' menu and choose 'Add another Layout' and the missed buttons are in plan view.

  • I need to update the screenshots for a new version of an app existing Itune application to download a new version. Since I did not create the original version, can you guide me how to create a new version with the new version number?

    I need to update the screenshots for a new version of an existing iTunes Connect App asks me to download a new version. Since I did not create the original version, can you guide me how to create a new version with the new version number?

    You must call the assistance of the company and ask them to help you with this. You can find contact information by logging on http://digitalpublishing.acrobat.com/ and looking at the Middle at the bottom of the page.

    Neil

  • How to fill a control ring with chains [] array?

    How to fill a control ring with chains [] array?

    It must be karma. (Try really bad karma because I couldn't post this question in my original)

    I must have been a Really bad guy in a previous life...  It's not like I'm bad in this one...

    So... what I want to do this time around?  Something that I thought would be easy... Well... it's a long story...  I had a simple solution, but the client wants something else.  -sigh-

    Here is what they want...  They want a control that allows for multiple selections to a control of the ring (or a control that allows a drop down selection menu).  Bites are filled at run time because it is based on 10 000 other precedents of things this particular choice.  So it must be dynamic.

    The snippet of code & images below show what I'm doing a little...

    The bottom image shows on the right bites which is filled in the control of the ring.  Since the number of items / items changes, I didn't have a bunch of controls stacked on another.  In addition, I have to deal with an unknown quantity of selections.

    Does anyone have a solution that can be recommended?  If so, can you share the solution / idea?

    Thank you

    RayR

    I have posted a code that does something similar here: http://forums.ni.com/t5/LabVIEW/array-of-cluster/m-p/1822451#M625032

    It uses a table hint and individual controls that are moved on top of the table and populated as needed.  This approach might work for you?  You would need a two-column table and only control ring, which you would fill properly whenever the currently active cell changes.

  • HOW TO FILL OUT FORM PDF WITH HEBROW ON CHROME?

    HOW TO FILL OUT FORM PDF WITH HEBROW ON CHROME?

    Chrome uses its own PDF Viewer (incompatible).

    Download the PDF file to your local drive, then fill it out of there with Adobe Reader.  Or use a browser that uses the Adobe PDF plugin.

  • How to fill the discharge battery on Qosmo G30?

    Hello

    How to fill the discharge battery on Qosmo G30?

    Thank you

    Hello

    Disconnect the power adapter and run the notebook until it automatically stops.
    In addition, you should disable or change the battery alert in Windows power management.

  • Any method to create a total SUM of a column whose values based on LAG?

    I have a question here, and the challenge is to explain my situation well. I am developing a workbook that shows by project and month, the cost of this period and the change in the cost of the previous period. I want a total SUM on the columns of this period cost and cost change in prerequisite Mth. So what I want to do resembles something like this--

    Months of project cost this time Chg prior Mth cost

    ABCDE Jan $50,000 NULL (since no line before)
    ABCDE February $ $75,000 25 000
    Mar $60,000 ABCDE - 15 000
    ------------------------ ----------------------------------------------
    Total of $ $185,000 10 000

    I do the Chg of cost of prior Mth as a new calculation and use the formula insert model process to use the model of the difference f (x) to create my calculation. Who is working just great. If you look at the underlying code for this new section, you can see the LAG function used in the calculation of this value. I'm late to a single line, as you can see in the example above.

    I can create a new total and take a NAP in the cost column this time and get the right answer (the $185 000).

    The problem that I am running is that I get nothing when I try to summarize my prior Mth column cost Chg. The result is just empty (prints the text of the total, but no amount).

    My thought is that the NULL row in this column was to spoil the AMOUNT of work. So, I created a new calculation and said CASES WHERE prior cost Chg of Mth IS NULL THEN 0.00 ELSE cost Chg of Mth prior. So I get a new column with the same numbers, except for the first line, where I now have a 0 instead of NULL. Then, I created a new total (SUM function) on this new column. Heck. Same result with regard to the other column. I do not receive an amount.

    Everybody run on an issue to try to sum a column of numbers being calculated from a SHIFT function in discoverer? Any suggestions on how I could get a SUM to calculate correctly to this column cost Chg prior Mth? Or have I met one of those irritating questions "cannot manage in discoverer?

    Of course I can export the workbook results run to Excel and create the calculation in there, and that works fine.

    John Dickey

    Hi John
    Thanks for the question and great information. That really helped. I love this kind of questions. They make me think :-)

    Just a thought but have you tried to change the AMOUNT for a sum of CELL?

    The SUM will try to assess the LAG on the total that would be invalid as, at least in theory, the SUM of the CELL must literally add the values.

    Best wishes
    Michael

  • Fill two empty columns with the values in a column (all in the same table)

    Can someone point me in the right direction? I want to fill the column prefix and suffix with the AcctNum data.

    "Prefix is the part of the number before the '-' and the suffix is everything after the '-'. '. Write a SQL command to fill the column prefix and suffix.
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    It is supposed to look like this:
    *Accounts* 
    
    AcctNum   Prefix   Suffix
    -------   ------   -------
    123-0097    123     0097
    X089-056
    123-0097
    123-0098
    F3377-D
    X089-057
    X089-058
    3-009712
    That's what I came with, but it does not work because it is basically putting multiple values into a single cell:
    update accounts
         set prefix=(select substr(acctnum, 1, instr(acctnum,'-')-1) from accounts),
         suffix=(select substr(acctnum, instr(acctnum, '-')+1) from accounts)
         where acctnum=(select prefix||'-'||suffix from accounts);
    I want this query is incredibly easy and I have forget something. Any help is greatly appreciated.

    Published by: 885913 on September 18, 2011 12:53
    UPDATE accounts a
    SET    ( prefix, suffix ) = (SELECT Substr(acctnum, 1, Instr(acctnum, '-') - 1),
                                        Substr(acctnum, Instr(acctnum, '-') + 1)
                                 FROM   accounts b
                                 WHERE  a.acctnum = b.acctnum);
    
  • SQLLDR: How to fill the empty columns with specific data by default?

    Hello

    We are 11G

    Here is a complete example:

    (1) the definition of the table:
    create table IMPORT_PRJ_TIMESHEETS
    (
      RESSOURCE_CODE VARCHAR2(20),
      REFERENCE_DATE VARCHAR2(20),
      STATUS         VARCHAR2(20),
      PROJET_CODE    VARCHAR2(50),
      TACHE_ID       VARCHAR2(100),
      TACHE_DESC     VARCHAR2(250),
      RAF            NUMBER,
      JOUR1          NUMBER,
      JOUR2          NUMBER,
      JOUR3          NUMBER,
      JOUR4          NUMBER,
      JOUR5          NUMBER,
      JOUR6          NUMBER,
      JOUR7          NUMBER,
      IMPORT_DATE    DATE
    );
    (2) the CTL:
    LOAD DATA
    CHARACTERSET WE8ISO8859P1
       APPEND INTO TABLE IMPORT_PRJ_TIMESHEETS
    -- Pour eliminer la ligne d'en-tete
    WHEN PROJET_CODE != 'ID projet'
       FIELDS TERMINATED BY '*-*' OPTIONALLY ENCLOSED BY '"'
    ( RESSOURCE_CODE       CONSTANT '!RESSOURCE_CODE!'
    , REFERENCE_DATE       CONSTANT '!REFERENCE_DATE!'
    , STATUS               CONSTANT '!STATUS!'
    , PROJET_CODE          CHAR
    , TACHE_ID             CHAR
    , TACHE_DESC           CHAR
    , RAF                  CHAR "TO_NUMBER( :RAF, '999G999D99')"
    , JOUR1                CHAR
    , JOUR2                CHAR
    , JOUR3                CHAR
    , JOUR4                CHAR
    , JOUR5                CHAR
    , JOUR6                CHAR
    , JOUR7                CHAR
    , IMPORT_DATE          SYSDATE
    )
    {code}
    
    
    3) the datafile :
    {code}
    ID projet*-*ID tâche*-*Tâche/Description*-*RàF*-*lun. 13/07*-*mar. 14/07*-*mer. 15/07*-*jeu. 16/07*-*ven. 17/07*-*sam. 18/07*-*dim. 19/07*-*
    FR-FR-NT2300135*-* *-*GAMMAWEB - Coordination*-*0,00*-* *-* *-* *-*8,00*-*8,00*-* *-* *-*
     *-* *-*Holiday*-* *-* *-*8,00*-* *-* *-* *-* *-* *-*
     *-* *-*Special leave*-* *-*8,00*-* *-* *-* *-* *-* *-* *-*
     *-* *-*Vacation*-* *-* *-* *-*8,00*-* *-* *-* *-* *-*
    
    {code}
    
    - As you can see, the datafile delimiter is "*-*" .... there's no pb about this.
    
    - Also, there are 5 lines in the datafile. Currently, the _*load status*_ is :
       - Line 1 is the header  >>> not loaded, and that's fine with me.
       - Line 2 is successfully loaded
       - Line 3 / Line 4 / Line 5 : are not loaded .. but I need these lines ...
    
    *What I'd like to get is to successfully load lines 3 to 5 with a default values for the first 3 columns (project/task ID/ task desc)*
    
    I hope it's clear enough and that you will be able to provide a good answer ..
    
    Thanks in advance,
      Olivier                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    In your example, the only ranked with value on all lines is TACHE_DESC.
    If this field is always filled, try this:
    WHEN TACHE_DESC! = "Task/Description".

    Concerning

  • How to fill the gaps with data?

    Hello

    I have data points with a header that contains the ID that I have to report to each row of data.

    I want the ID of the Patient to fill the fields below the rank (where the "Obs" and sequential numbers are) until it reaches the next patient id and then do the same thing again and again until the end.

    Is this possible in a single SQL UPDATE statement?

    Thank you, Daniel

    It's data, it's a column:

    Patient ID = system 1000207 = LVS + ZDV + ddI randomization Date = 26/03/2004
    OBS
    1
    2
    3
    4
    5
    6
    7
    Patient ID = regime 1000751 = LVS + d4T + 3TC randomization Date = 25/02/2004
    OBS
    8
    9
    10
    11
    12
    13
    14
    Patient ID = system 1001379 = LVP + d4T + 3TC randomization Date = 17/03/2004
    OBS
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    etc etc.

    Do you have any column order?

    If not, how you will order the data?

    If you have a column for the classification, the described selection will give you the id of the patient in all lines

    select col1,
           last_value(
              regexp_substr(col1,'Patient ID=([0-9]+)',1,1,null,1) ignore nulls
                    )
            over(order by ord_col) s
    from your_table;
    

    You can then use the MERGER based on the ROWID of update...

    Published by: JAC on May 21, 2013 20:18

Maybe you are looking for