Update a table using the clause

Hello

I want to update a table using the selected values.

Cases in the sample:


create table as empsalary)

Select 1 as empid, 0 in the wages of all the double union

Select option 2, the double 0);

Data update are as follows

with saldata as

(

Select 1 as empid, 5000 as wages, 500 as double pf

Union of all the

Select option 2, 10000,1000 like double pf

)

Select empid, salary saldata

I tried the following query but does not work

updated set of empsalary table (empid, salary) =

(

Select * from)

with saldata as

(

Select 1 as empid, salary, 500 5000 as pf Union double all the

Select option 2, 10000,1000 like double pf

)

Select empid, salary saldata

) sl

where sl.empid = empsalary.empid

)

I use oracle 10g.

Help, please.

Krishna Devi wrote:

Hello

I want to update a table using the selected values.

Cases in the sample:

create table as empsalary)

Select 1 as empid, 0 in the wages of all the double union

Select option 2, the double 0);

Data update are as follows

with saldata as

(

Select 1 as empid, 5000 as wages, 500 as double pf

Union of all the

Select option 2, 10000,1000 like double pf

)

Select empid, salary saldata

I tried the following query but does not work

updated set of empsalary table (empid, salary) =

(

Select * from)

with saldata as

(

Select 1 as empid, salary, 500 5000 as pf Union double all the

Select option 2, 10000,1000 like double pf

)

Select empid, salary saldata

) sl

where sl.empid = empsalary.empid

)

I use oracle 10g.

Help, please.

Thanks for posting creates table and test data.

The error message would have helped because it's pretty obvious that this is the problem:

Update table empsalary

*

ERROR on line 1:

ORA-00903: invalid table name

Just remove the word "table".

Tags: Database

Similar Questions

  • Problem with update of table (using the subquery to retrieve value)

    Hello
    I update a table based on the value of the subquery.
    Here's the update statement.

    UPDATING temp xm
    SET xm.col1 = (SELECT DISTINCT col1
    Of
    (SELECT col1, col2 COUNT (col2)
    FROM table2
    WHERE col1 = xm.col1
    AND col2 = xm.col2
    GROUP BY col1)
    where col2 in (select... in the table3)
    )
    WHERE xm.col5 = < value >
    AND xm.col6 = < value >

    When I run this statement I get following error.
    ORA-00904: "XM". "" Col1 ": invalid identifier.

    Can someone help me why I get this error?
    Why doesn't the main table alias in the subquery?

    Is it possible to avoid this / re - write the query in a different way?

    Thank you

    Published by: user552703 on November 2, 2009 20:42

    You can nest only 1 level deep (referring to the table to be updated).

    Have you looked at using the MERGE command? It is "easier" perform updates of this nature, assuming you are using a recent version of Oracle (9 or MORE).

  • Get the 500 error trying to create a table using the REST API

    Hello

    I tried to create a table using the REST API for Business Intelligence Cloud, but I got 500 Internal Server Error for a while now.

    Here are the details that I use to create a table.

    Capture.JPG

    and the json to create the schema that I use is

    [{'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ["ROWID"]}]

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['RELATIONID']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['ID']}

    , {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['RESPONDEDDATE']},

    {'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [255], 'columnName': ['RESPONSE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_CREATEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_CREATEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_LASTMODIFIEDDATE']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [18], 'columnName': ['SYS_LASTMODIFIEDBYID']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['TIMESTAMP'], 'precision': [0], 'length': [0], 'columnName': ['SYS_SYSTEMMODSTAMP']},

    {'Nullable': [false], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [10], 'columnName': ['SYS_ISDELETED']},

    [{'Nullable': [true], 'defaultValue': 'dataType' [null],: ['VARCHAR'], 'precision': [0], 'length': [50], 'columnName': ['TYPE']}]

    I tried this using postman and code, but I always get the following response error:

    Error 500 - Internal server error

    Of RFC 2068 Hypertext Transfer Protocol - HTTP/1.1:

    10.5.1 500 internal Server Error

    The server encountered an unexpected condition which prevented him from meeting the demand.

    I am able to 'get' existing table schemas, delete the tables, but I'm not able to make put them and post operations. Can someone help me to identify the problem, if there is no fault in my approach.

    Thank you

    Romaric

    I managed to create a table successfully using the API - the only thing I see in your JSON which is different from mine is that you have square brackets around your values JSON where I have not. Here is my CURL request and extract my JSON file (named createtable.txt in the same directory as my CURL executable):

    curl u [email protected]: password UPDATED h x ' X-ID-TENANT-NAME: tenantname ' h ' Content-Type: application/json '-binary data @createtable.txt https://businessintell-tenantname.analytics.us2.oraclecloud.com/dataload/v1/tables/TABLE_TO_CREATE k

    [

    {

    'columnName': 'ID',

    'dataType': 'DECIMAL ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': false

    },

    {

    'columnName': 'NAME',

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'STATUS."

    'dataType': 'VARCHAR ',.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    "columnName': 'CREATED_DATE."

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    },

    {

    'columnName': 'UPDATED_DATE ',.

    'dataType': 'TIMESTAMP '.

    'Length': 20,.

    "accuracy": 0.

    'Nullable': true

    }

    ]

  • Selection of the list of clients using the clause "EXISTS".

    Dear all,

    I have 3 tables, say,

    TABLE1:

     

    CUST_CODE

    (PRIMARY KEY)

    CUST_NAME

    CUST_COUNTRY_CODE

    CUST_CITY_CODE

    CUST_AREA_CODE

    A

    CUST1

    COU1

    CIT1

    A1

    B

    CUST2

    COU2

    CIT2

    A2

    C

    CUST3

    COU2

    CIT2

    A3

    D

    CUST4

    COU3

    CIT4

    A4

    E

    CUST5

    COU3

    CIT5

    A5

    TABLE2

     

    STOCK_SYS_ID

    (PRIMARY KEY)

    STOCK_CUSTOMER_CODE

    STOCK_CUSTOMER_

    COU_CODE

    STOCK_

    CUSTOMER_

    CIT_CODE

    STOCK_

    CUSTOMER_

    ARE_CODE

    STOCK_DOC_

    CREATED

    1

    A

    [Leaving empty as we have reference only to the customers and the date here...]

    10/15/2015

    2

    B

    15/09/2015

    3

    A

    16/08/2015

    4

    C

    18/08/2015

    5

    E

    22/07/2015

    6

    C

    31/01/2015

    7

    A

    15/10/2014

    TABLE 3

     

    AREA_CODE

    AREA_COUNTRY_CODE

    AREA_CITY_CODE

    A1

    COU1

    CIT1

    A2

    COU2

    CIT2

    A3

    COU3

    CIT2

    A4

    COU3

    CIT3

    A5

    COU4

    CIT5

    How can I find the list of clients of TABLE1, which are present in TABLE2 by 2015 and have country-city-zone, both correct mapping as specified in section TABLE3 using the clause "EXISTS".

    Is that my output will be like,

     

    CUST_CODE

    (ONLY CORRECT CUSTOMER CODES)

    CUST_NAME

    A

    CUST1

    B

    CUST2


    Thanks in advance,

    Séverine Suresh

    Hello

    So, you want to see 3 columns in table1 correspond to 3 columns in t3.  It is not enough for only 1 column equal:

    Area_Code must be equal

    country_code and must be equal

    city_code and must be equal.

    Here's a way to encode that, by using the EXISTS operator in a WHERE clause:

    SELECT cust_no, cust_name

    FROM table1 t1

    WHEN THERE IS)

    SELECT 0

    Table 3 T3

    WHERE t3.area_code = t1.cust_area_code

    AND t3.area_country_code = t1.cust_country_code

    AND t3.area_city_code = t1.cust_city_code

    )

    ;

    I hope that answers your question.

    If not, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results you want to start from these data (otherwise what you've posted already).

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • My Adobe Acrobat widget does not work. Whenever I try to convert a webpage to PDF, a window opens saying that "any version of Acrobat can be found, install Acrobat 11.0.09 or update version to use the extension create PDFs.» I downloaded the last drunk ve

    My Adobe Acrobat widget does not work. Whenever I try to convert a webpage to PDF, a window opens saying that "any version of Acrobat can be found, install Acrobat 11.0.09 or update version to use the extension create PDFs.» I downloaded the latest version but iut still does not work. I use a MAC and Chrome as a browser.

    Can you help me?

    If you use Adobe Reader, you will not be able to create a PDF file. Adobe Reader cannot create a PDF file, modify/edit the content of a PDF page or export the contents of a PDF page.

    For those, you must use Acrobat or one of Adobe's online subscription services.

    Be well...

  • Adobe lightroom does not update when I use the application manager to download upgrades.

    Hello

    I have problems with adobe lightroom.  It is not updated when I use the application manager to download the new updates.  I tried to uninstall the application and re-download it, however the application manager will not allow that to happen because it shows that it is already installed and up to date. I think that the problem may have started when I installed lightroom using a link which you offered when creative cloud first started offering of lightroom.  This version of the program does not appear to work with the application manager.  Please let me know what I should do to fix the problem.

    Best regards

    S

    Hello

    Please, try to remove Adobe Extension manager and install again. The reinstallation of the extensions Manager try to day light the room.

    If it does not resolve that question please make a complete own using adobe cleaner tool and reinstall everything.

    Thank you

    Kapil Malik

  • Creating external Tables using the EXECUTE IMMEDIATE in PL/SQL

    Hi guys,.

    I am trying to create an external Table using the EXECUTE IMMEDIATE in a procedure and I managed to compile and no errors were generated. But when I try to run it from sql using the exec command I get the following error:

    ------------------------------------------------------------------------
    ERROR on line 5:
    ORA-00911: invalid character
    ORA-06512: at "GEO. TEST_DDL', line 4
    ORA-06512: at line 5

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

    I tried to check the whole statement to create the external table, but I can't find where is the error. Surprisingly, if I simply run the command table create external on sqlplus it works, but not a procedure.

    If anyone can help with ideas or experience?

    Geoffrey Kossami

    The error means that there is an identifier somewhere that starts with a nonalphanumeric. This is a typical mistake of editing. A procedure compiles correctly is not of course because the underlying dynamic sql running is OK. Which of course only be resolved when you try to run it.

    There is certainly a problem with the text you provide to be run as a piece of dynamic sql code. You should try to watch it with dbms_output and run this code in sqlplus. But your problem is with the code you run as dynamic PL/SQL, it is not itself compilable.

    Jack

  • trigger to update a table after the use of commit_form;

    Hi, I have a master detail shipping form where I enter the details and use commit_form; to save data... after that I want to update a column named as transit in deteil table
    but the changes are not reflected.
    PROCEDURE transit_update IS
    BEGIN
           if :shipbill.billtype in ( 'Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair')
              then          
              update ship_1 set transit_qty = transact_qty
         where 
         billid =:shipbill.billid;
    
    
         end if ;
         
         if :shipbill.billtype in ('Received from staff','Received from site','Received from store','Received from STC')
              then          
              update ship_1 set transit_qty = 0
         where 
              billid =:shipbill.billid;
         
    
         end if ;
    END;
    I wrote it under the procedure and tried to call the block level under update post trigger but it doesn't...

    Hello
    Why not put the sub condition in PRE-INSERT/PRE-UPDATE (at the level of the blocks) of the retail block?

    IF :shipbill.billtype IN ('Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair') THEN
      :ship_1.transit_qty = :ship_1.transact_qty;
    ELSIF :shipbill.billtype IN ('Received from staff','Received from site','Received from store','Received from STC') THEN
      :ship_1.transit_qty = 0;
    END IF;
    

    If billtype is not simple text (filled in by the user) and then trying to find no matter what other condtion. To reduce misspellings error etc.

    -Clément

  • Insert using the table with the clause and select?

    Hello gurus,

    Can I insert in a table by making use of clause and select?

    something similar to this...
         insert into test_table
          (with abc as 
              (select * from emp_tble
               where dept_no = 10
               )
             select * from abc;
       );          
    
         if not i would i do by making use of  with clause & select ... any example would be great !!
    
    
      
    Thank you very much!!!

    Brackets are disturbing only:

    SQL> insert into test_table
       (with t as (select * from emp) select * from t)
    /
    Error at line 12
    ORA-32034: unsupported use of WITH clause
    
    SQL> insert into test_table
      with t as (select * from emp) select * from t
    /
    14 rows created.
    
  • PL/SQL parameter in fusion by using the clause

    Hi all

    I need to create a procedure where I use the Merge clause. However, by using the condition, I have to put value user_define (V_LOCALE_CD). This value checks table of locale and then to make a match with table of flex_labels_test.

    There is no specific requirement and I don't have the test data.

    My only question how do I use user set the value using the condition. Here is the procedure I created as follows.

    create or replace the PROCEDURE UPSERT_FLEX_LABEL_3 (V_LOCALE_CD IN VARCHAR2,

    V_VALUE IN VARCHAR2,

    V_FIELDVALUE IN VARCHAR2,

    V_FIELDNAME IN VARCHAR2,

    V_TABLENAME IN VARCHAR2,

    N_FLEX_TYPE NUMBER,

    V_COLOR IN VARCHAR2 DEFAULT NULL,

    N_IMAGE_LIBRARY_ID IN THE NUMBER DEFAULT NULL,

    N_HIERARCHY_ID IN DEFAULT NUMBER 5237260000000000001,

    N_IS_INHERITED IN THE DEFAULT NUMBER 1)

    AS

    L_COUNT NUMBER;

    NUMBER OF N_LOCALE_ID;

    NUMBER OF NN_HIERARCHY_ID: = 5237260000000000001;

    NUMBER OF NN_IS_INHERITED: = 1;

    NUMBER OF INSERTCOUNT;

    UPDATECOUNT NUMBER;

    NUMBER OF ERR_CODE;

    ERR_MSG VARCHAR2 (100);

    BEGIN

    -SELECT ID IN N_LOCALE_ID OF PLACES WHERE LOCALE_CD = V_LOCALE_CD;

    / * IT WILL CHECK DUPLICATES, IF THEY ARE PRESENT, THEN IT WILL UPDATE RECORD ELSE IT WILL INSERT A NEW RECORD * /.

    BEGIN

    Merge into fl flex_labels_test

    using (select locale id where locale_cd = V_LOCALE_CD) L

    on (l.id = fl.locale_id)

    When matched then

    GAME UPDATE

    HIERARCHY_ID = NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID),

    IS_INHERITED = NVL (N_IS_INHERITED, NN_IS_INHERITED),

    FLEX_TYPE = N_FLEX_TYPE,

    VALUE = V_VALUE,

    IMAGE_LIBRARY_ID = N_IMAGE_LIBRARY_ID,

    COLOR = V_COLOR

    WHERE TABLENAME = V_TABLENAME

    AND FIELDNAME = V_FIELDNAME

    AND FIELDVALUE = V_FIELDVALUE

    When not matched then

    INSERT (HIERARCHY_ID, ID_PARAMETRES_REGIONAUX, IS_INHERITED, FLEX_TYPE, TABLENAME, FIELDNAME, FIELDVALUE, VALUE, IMAGE_LIBRARY_ID, COLOR)

    VALUES (NVL (N_HIERARCHY_ID, NN_HIERARCHY_ID), N_LOCALE_ID, NVL (N_IS_INHERITED, NN_IS_INHERITED), N_FLEX_TYPE, V_TABLENAME, V_FIELDNAME, V_FIELDVALUE, V_VALUE, N_IMAGE_LIBRARY_ID, V_COLOR);

    UPDATECOUNT: = NUMBER OF ROWS SQL %;

    EXCEPTION

    WHILE OTHERS THEN

    ERR_CODE: = SQLCODE;

    ERR_MSG: = SUBSTR (SQLERRM, 1, 200);

    DBMS_OUTPUT. PUT_LINE ("ERRORS" |) ERR_CODE | ' AND ' | ERR_MSG);

    END;

    COMMIT;

    DBMS_OUTPUT. PUT_LINE ('RECORD INSERTCOUNT =' |) NVL(INSERTCOUNT,0));

    DBMS_OUTPUT. PUT_LINE (' UPDATECOUNT RECORD ='|) NVL(UPDATECOUNT,0));

    EXCEPTION

    WHEN NO_DATA_FOUND THEN

    RAISE_APPLICATION_ERROR (-20001, "ID NOT FOUND REGIONAL SETTINGS");

    END;

    I guess that's what I was looking for. Thank you guys for your efforts.

    FUSION using parameter variables

  • Update a table of the source - duplicates exist in the source

    Hi all

    I need a logic to know how to update a target from the source table. It is here in source table contains duplicate data.
    Oracle version is 10.2.0.3.0
    OS - Sun Solaris

    Target table - fields A, B, and C. A and B are primary keys.

    A, B AND C
    1 1
    1 2
    2 2
    2 1

    Table of the source - no primary key.

    A, B AND C
    1 1 2
    1 1 2
    1 1 3
    2 1 4

    From the fields A and B, column C must be updated on the source table.

    In the target table, 4 ranks should get updated to the value 4.
    In the target table - for the first row in the source table, the 3 first lines are adapting. I'm fine with all values (2,2,3).
    In the target table - for the second and third rows, the value of c must be null.
    Currently I'm updating it through cursor. but it takes a lot of time.
    In production, less than one percent of the files are duplicate records. It asked me to update the right folders with regular update instruction and duplicate with the slider or other logic records. where less than one per 100 records will be be curly to the cursor. Basically, the direction as to reduce the load on the slider.

    Your help is most appreciated.

    Thank you

    Try a different USING clause:

    using (select a, b, c, d
           from
              (select a, b, c, d
                     ,row_number() over (partition by a, b order by c) rn
               from   s
              )
           where rn = 1
          ) s
    

    This will select the first row (numerically) within each combination, b. If you want the last line add a DESC in the order of.

  • "missing the SELECT keyword" error during an insert into the temporary table using the blob value

    I'm trying to insert into an oracle temp table using select that retrieves data from a blob field but I get the error: "lack the SELECT keyword.

    How we store temporary in oracle result when we make this type of operation (extraction of data in fields and try to load them into a separate table on the fly.?)

    with cte as)

    Select user_id, utl_raw.cast_to_varchar2 (dbms_lob.substr (PREFERENCES)) as USER my_blob

    )

    create table new_table as

    SELECT user_id,EXTRACTvalue(xmltype(e.my_blob),'/preferences/locale') regional settings

    E ETC

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

    BLOB data - value - which is

    <? XML version = "1.0" encoding = "ISO-8859-1" ?>

    - < Preferences >

    < time zone > America/New_York < / > zone

    < displayscheduleinusertimezone > Y < / displayscheduleinusertimezone >

    < local > Spanish < /locale >

    < DateFormat > JJ/mm/aaaa < / DateFormat >

    < timeFormat > hh: mm aaa < / timeFormat >

    < longformat > Long_01 < / longformat >

    < doubleformat > Double_01 < / doubleformat >

    < percentformat > Percentage_01 < / percentformat >

    < currencyformat > Currency_01 < / currencyformat >

    < / Preferences >

    A WITH clause that must immediately precede the SELECT keyword:

    SQL > create table t:

    2 with the o as (select double dummy)

    3 select * West longitude;

    Table created.

  • How to use the clause type conditionally create new lines

    This question is just for learning - no object other than to start real world to create versions of some queries known to learn how to measure the performance of the MODEL clause clause of the MODEL versions.

    The question is: How can you write a STANDARD clause that pivots (updates) ONLY the lines that actually need to rotate and do NOT change the lines that have no value and cannot be rotated.

    I found a good site that has about two dozen example articles on different pieces. This first link is the beginning of the series.

    SQL features tutorials - Clause TYPE

    http://www.sqlsnippets.com/en/topic-11663.html

    This link is to a clause of FAQ of BluShadow MODEL version "how to convert rows to columns."

    Line - MODEL method string

    http://www.sqlsnippets.com/en/topic-11987.html

    The solution to this link uses this line of source:

    POSITION KEY VAL

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

    R08 0 v1, v2, v3,.

    and this result set:

    POSITION KEY VAL

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

    R08 1 v1

    R08 2 v2

    R08 3 v3

    The reason why it produces that result set is this clause of the statement of MODEL

    RETURN THE UPDATED LINES

    If you comment on this article, you will see that the original lines are all in position 0. This means that the solution reproduced EACH SOURCE LINE even if there is only one item in the list of values.

    Thus, even a line source with a single value (for example, the r01 'a') will be updated and updated this line is returned.

    For a large number of data sources with only a few lines that actually need to rotate it would be a great performance of infringement.

    This is the sample data source

    with t as (button 1, 'a' value 'abc' col2, col3 'def' of the double
    Select Union all 2, 'b', 'ghi', 'jkl' from dual
    Union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Union all select 4, 'f', 'stu', 'vwx' from dual
    )
    Select the key, value, col2, col3
    t

    KEY, VALUE, COL2, COL3
    1, a, abc, def
    2, b, GHI, jkl
    3, "c, d, e, mno, pqr.
    4, f, stu, vwx

    Lines 1, 2 and 4 only have a value of (a, b, c respectively.

    Only line 3 must rotate. It contains "c, d, e" and which must become 3 lines in the result set

    Value of the key, col2 col3
    1 an abc def
    2B ghi jkl
    3 c mno, pqr
    3 d mno, pqr
    3 e mno, pqr
    4 f stu vwx

    The nut of the problem is that if the clause 'RETURN UPDATED ROWS' is used, then the lines 1, 2 and 4 must be updated in order to be returned in the result set. And if this clause is NOT used, then line 3 must be updated by 'c', d, e 'c' and two new product lines: one line for a ' and one for 'e '.

    How can you do this with the TYPE clause without the help of the clause "Return LINES UPDATE"? I don't have a solution to sample showing what I tried because I can't understand what it takes to even try.

    I have a solution that uses "RETURN UPDATED ROWS" but I want to compare this performance to the exercise, when this clause is NOT used.

    We ask BluShadow to add the solution of MODEL clause to this FAQ with other similar solutions.

    Like this?

    SQL > with t as
    () 2
    3 select the 1 key, 'a' val, 'abc' col2, col3 'def' of the double


    Select 4 Union all 2, 'b', 'ghi', 'jkl' from dual
    5 union all select 3, 'c, d, e, 'mno', 'pqr' from dual.
    Select 6 Union all the 4 'f', 'stu', 'vwx' from dual
    7)
    8. Select the key
    9, key_1
    10, val
    11, regexp_substr (val, ' [^,] +', 1, key_1) val_new
    12, col2
    13, col3
    14 t
    model 15
    16 partition by (key)
    dimension (1 key_1) 17
    18 measures (val, col2, col3, (length (val) - length (replace (val, ",")) + 1) as len)
    19 rules
    (20)
    21 val [for 1 to increment of len key_1 [1] 1] = val [1]
    22, col2 [for 1 to increment of len key_1 [1] 1] = col2 [1]
    23, col3 [for 1 to increment of len key_1 [1] 1] = col3 [1]
    24)
    25 order
    26 by key
    27, key_1;

    KEY KEY_1 VAL VAL_N NECK NECK
    ---------- ---------- ----- ----- --- ---
    1 1 has an abc def
    2 b 1 b ghi jkl
    3 1 c, d, e c mno pqr
    3 2 c, d, e d mno pqr
    3 3 c, d, e e mno pqr
    4 1 f f stu vwx

    6 selected lines.

  • Update of Table, summarizing the content of the separate column.

    Hi all

    Small update problem: -.

    CREATE THE TABLE:
     
    CREATE TABLE TestTab10
    (
    GROUPID VARCHAR2(10),
    ITEMS_1 NUMBER(2), 
    ITEMS_2 NUMBER(2),
    ITEMS_3 NUMBER(2),
    TOT_ITEMS VARCHAR(50),
    SEQNO NUMBER(10)
    );
    DATA: -.
     
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','13','','','123456');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','','16','','123457');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10002','','','','','123458');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123459');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123460');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123461');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','11','13','','','123462');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','12','','','123463');
    INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','13','14','','123464');
    Select * from TestTab10;
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                                               SEQNO
    ---------- ---------- ---------- ---------- -------------------------------------------------- ----------
    10001              12         13                                                                   123456
    10001              12                    16                                                        123457
    10002                                                                                              123458
    10003                         13                                                                   123459
    10003                         13                                                                   123460
    10003                         13                                                                   123461
    10004              11         13                                                                   123462
    10004                         12                                                                   123463
    10004                         13         14                                                        123464
    Desired results: -.
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                                               SEQNO
    ---------- ---------- ---------- ---------- -------------------------------------------------- ----------
    10001              12         13            121316                                                 123456
    10001              12                    16 121316                                                 123457
    10002                                                                                              123458
    10003                         13            13                                                     123459
    10003                         13            13                                                     123460
    10003                         13            13                                                     123461
    10004              11         13            11131214                                               123462
    10004                         12            11131214                                               123463
    10004                         13         14 11131214                                               123464
    I need to update the Tot_items column with the number of distinct elements which is held within each groupid.

    The ideas people?

    Thanks in advance.

    Lack OP wants ordered items:

    merge
      into  testtab10 a
      using (
             with t as (
                        select  rowid rid,
                                listagg(items_1 || ',' || items_2 || ',' || items_3,',')
                                  within group (order by seqno)
                                  over(partition by groupid) items
                            from  testtab10
                       )
             select  rid,
                     xmlquery(
                              'string-join(for $n in distinct-values(ora:tokenize($str,",")) order by xs:integer($n) return $n,",")'
                              passing ',' || items as "str"
                              returning content
                             ) tot_items
               from  t
            ) b
      on (a.rowid = b.rid)
      when matched
        then
          update
            set a.tot_items = b.tot_items
    /
    
    9 rows merged.
    
    SQL>  select  *
      2     from  testtab10
      3  /
    
    GROUPID       ITEMS_1    ITEMS_2    ITEMS_3 TOT_ITEMS                 SEQNO
    ---------- ---------- ---------- ---------- -------------------- ----------
    10001              12         13            12,13,16                 123456
    10001              12                    16 12,13,16                 123457
    10002                                                                123458
    10003                         13            13                       123459
    10003                         13            13                       123460
    10003                         13            13                       123461
    10004              11         13            11,12,13,14              123462
    10004                         12            11,12,13,14              123463
    10004                         13         14 11,12,13,14              123464
    
    9 rows selected.
    
    SQL>
    

    SY.

  • Mod_user handling in a table using the trigger

    Hello

    I have a table with two columns value ' test' and the mod_user. Currently, the table has a before Update trigger to update the mod_user as a user of the system
    Now, I need to change the trigger to meet the criteria below

    (1) in an update statement if I manually put the mod_user, then it should be updated such as defined in the update statement.

    For example:
    UPDATE test
    Value = 1,
    mod_user = "xyz".
    WHERE value = 4;

    In the scenario above mod_user should be updated to "xyz" in the table

    (2) if I don't talk to any term set for mod_user, the default windows user should be changed in the table.
    UPDATE test
    Value = 1
    WHERE value = 4;

    In the scenario above mod_user should be updated as a user of windows in the table

    The trigger statement, I used doesn't seem to work.

    CREATE OR REPLACE TRIGGER t_mod_test
    BEFORE the UPDATE OF value WE test
    FOR EACH LINE
    BEGIN
    : new.mod_user: = NVL (SYS_CONTEXT ('USERENV', 'OS_USER'), USER);
    END;

    Any suggestions on how I can do the work of scenario would be very appreciated.

    Thanks in advance
    DAS

    It looks like you want something like

    SQL> create table test(
      2    value number,
      3    mod_user varchar2(100)
      4  );
    
    Table created.
    
    SQL> create or replace trigger t_mod_test
      2    before update on test
      3    for each row
      4  begin
      5    if( updating( 'MOD_USER' ) )
      6    then
      7      null;
      8    else
      9      :new.mod_user := NVL( sys_context('USERENV', 'OS_USER')
     10                           ,user );
     11    end if;
     12  end;
     13  /
    
    Trigger created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace trigger t_mod_test
      2    before update on test
      3    for each row
      4  begin
      5    if( not updating( 'MOD_USER' ) )
      6    then
      7      :new.mod_user := NVL( sys_context('USERENV', 'OS_USER')
      8                           ,user );
      9    end if;
     10* end;
    SQL> /
    
    Trigger created.
    
    SQL> insert into test values( 4, 'xyz' );
    
    1 row created.
    
    SQL> update test
      2     set value = 1
      3        ,mod_user = 'abc'
      4   where value = 4;
    
    1 row updated.
    
    SQL> select * from test;
    
         VALUE MOD_USER
    ---------- ----------
             1 abc
    
    SQL> update test
      2     set value = 2
      3   where value = 1;
    
    1 row updated.
    
    SQL> select * from test;
    
         VALUE
    ----------
    MOD_USER
    ------------------------------------------------------------------------------
    
             2
    JCAVEDDBC64\jcave
    
    SQL>
    

    Justin

Maybe you are looking for

  • What software do I need to run a VI on an SMU-1065?

    Hello I want to run a VI on my SMU-1065.  So far I'm install DAQmx and LabVIEW Real-time on the host and target module. Do I need anything else? Also, is there a way to install the module time LabVIEW Real-time on the host without CD? In other words,

  • I need to restart aid and assistance

    I need to restart the service help and support, but I need to install security patches.  I need help in the installation of security patches.

  • BlackBerry Smartphones, please help to restore contacts wiped on Bold 9900

    Hello I had a few problems with apps on my BB Bold 9900 smartphone and erased all the data. Now I'm trying to restore the list of contact., but there are some difficulties: 1 - I don't have a backup on my computer - I have not yet installed the Black

  • Sims 3 do not open

    At first my game Sims 3 not opened at all when I tried to open it, so I troubleshooted and the setting has changed, not everytime I open it it asks the admin password, I put the password and press 'Yes', but it still does not work. Help, please.

  • Creative cloud Sync problem

    HelloAfter awakening from the sleep of my MAC, CC could not synchronize anything, saying: there were errors with some files. He also said that he had no internet connection, even if I could open a browser and search on the Internet and receive emails