Need logic to update the column in a Varchar table

Hello

Could you tell me logic below.

I have a xx_dbc of the table where one of the Attribute1 column is varchar2 (240).

Attribute1 has values such as

==================

(AIN, PUP, GRI, NINE)

(AIN, PUP)

(AIN)

(GRI, NINE)

I have to update this column for each record with values AIN = 10, PUP = 20, GRI = 30, NINE = 40

Columns must be updated as below

(10,20,30,40)

(10.20)

(10)

(30, 40)

Thank you.

Hello

Here's one way:

WITH the replacements AS a

(

SELECT "AIN" AS old_str, '10' AS new_str FROM dual UNION ALL

SELECT 'PUP', '20' FROM dual UNION ALL

SELECT 'GRI', '30' FROM dual UNION ALL

SELECT 'NEW', '40' DOUBLE

)

normalized_data AS

(

SELECT p_key

LEVEL AS sort_key

REGEXP_SUBSTR (attribut1,

, '[^(,)]+'

1

LEVEL

) AS str

OF xx_dbc

-WHERE... - If you need any filtering, put it here

CONNECT BY LEVEL<= 1="" +="" regexp_count="" (attribute1,="">

AND PRIOR p_key = p_key

AND PRIOR SYS_GUID () IS NOT NULL

)

SELECT '(' ||) LISTAGG (NVL (r.new_str, n.str)

, ','

) (ORDER BY sort_key) group

|| ')' AS new_attribute1

n.p_key - if wanted

OF normalized_data n

LEFT OUTER JOIN replacements r ON r.old_str = n.str

GROUP BY n.p_key

ORDER BY n.p_key

;

Like everything else, it depends on your version of Oracle.

In the above query, p_key can be any unique key of xx_dbc, including attribute1 or ROWID.

Relational databases, such as Oracle, work best when each column of each row contains 1 single piece of information, not a list delimited a number of parts.  It is so fundamental to the design of the table what he called the first normal form.  Most of the work to this problem is to convert your data denormalized in first normal form, and then convert back again.  This problem, like many others, would be much simpler and more effective if your table is in first normal form.

The above query assumes that the replacement of the chains (for example 'AIN' and '10') are not already in a table.  If they are, or they can be derived from a table, then you need not replacements subquery; Use your actual table.

Tags: Database

Similar Questions

  • InStr/substr logic to update the column in a table db 9i / 10g / 11g

    Hi all

    I have a table Test_table with email_address column.
    Please update the table and remove
    [email protected] and
    [email protected]
    email_address column.

    Current values of the Email_address column

    [email protected], ken. [email protected], [email protected], [email protected]
    2.Ken. [email protected], [email protected], [email protected]; [email protected]
    3 ken. [email protected], [email protected], [email protected], [email protected]

    The new value must be
    1 ken. [email protected], [email protected]
    Ken 2. [email protected], [email protected], [email protected]
    3 ken. [email protected], [email protected]


    If email_address to remove is the first email address in the column
    Then, remove the first comma too, otherwise delete the comma above and email address.

    I created a C1 cursor, but I know is not the logic to use to get the new value
    Any help will be greately appreciated.

    Declare
    Cursor c1 is select rowid, email_address
    From Test_table
    Where (at the top (email_address) like ('% [email protected]%'))
    GOLD (superior (email_address) like '% [email protected]%');
    V_new_email varchar2 (200);
    BEGIN
    FOR rec IN C1 LOOP
    -do not know how to handle V_new_email to be able to update the table with the current values.
    V_new_email: = - some function instr/substr here

    Update Test_table
    Define email_address = V_new_email
    Where rowid = rec.rowid;

    END OF LOOP
    END;

    Thank you

    You needn't PL/SQL for such a thing. A SQL should be sufficient.

    with data as
    (
      select '[email protected], [email protected], [email protected], [email protected]' col from dual union all
      select '[email protected], [email protected],[email protected]; [email protected]' from dual union all
      select '[email protected], [email protected], [email protected], [email protected]' from dual
    )
    select col, trim(replace(replace(replace(col, '[email protected],'), '[email protected]'), ', ,', ',')) rep_col
      from data;
    
    COL                                                            REP_COL
    -------------------------------------------------------------- --------------------------------------------------------------
    [email protected], [email protected], [email protected], [email protected]   [email protected], [email protected]
    [email protected], [email protected],[email protected]; [email protected] [email protected], [email protected],[email protected];
    [email protected], [email protected], [email protected], [email protected]   [email protected], [email protected], [email protected]
    
  • Need help to update the column 'TIMESTAMP '.

    Hello

    Here is my description of the table, I want to update the timestamp column, but I could not able to do, please help me with that.

    ID VARCHAR2 (4 BYTE),
    TYPE VARCHAR2 (1 BYTE),
    DATET TIMESTAMP (6).
    TYPE NUMBER

    Currently, I have value "01/05/2009 9:00:00.000000 AM" for the column DATET, now I want to update «9:00:00.000000 PM 01/05/2009» Please help me.

    Thank you.

    Hello

    Here's one way:

    UPDATE     table_x
    SET     datet     = datet + INTERVAL '12' HOUR
    WHERE     datet     = TO_TIMESTAMP ( '01/05/2009 09:00:00'
                          , 'DD/MM/YYYY HH24:MI:SS'     -- or whatever
                          );
    
  • Insert/update the column with the clob data type

    Hi all

    ORCL Version: 11g.

    I have a table with the clob data type.

    Test12

    (col1 clob);

    I'm trying to insert/update to update the column with more than 4000 characters.

    But due to the limitation of tank 4000, I could not Insert/Update.

    Need your help in resolving this issue.

    THX

    Rod.

    The limit of 4000 characters is incorrect.  That pertains only to the varchar2 data type.  A clob can hold more than 4 G.

    Here is an example that shows how to insert it, I found...

    Otherwise, here is a way 'dirty' to do.

    insert into your_table (COLA, COLB)

    values

    (PRIMARY_KEY, PART 1 OF DATA)

    ;

    Update your_table

    Define COLB = COLB | PART 2 OF BIG DATA

    where COLA = PRIMARY_KEY;

    Update your_table

    Define COLB = COLB | PART 3 OF BIG DATA

    where COLA = PRIMARY_KEY;

    .. and so on...

    I don't know that I personally recommend the second style...  But he could do the job.

  • How update the column in the table based on the value selected in apex4.1

    Hi all
    I have the following tables,
    leave_type table,it has the following fields,
    1.emp_name,
    2.sick
    3.casual
    and it has the values as follows,
    emp_name                  sick             casual
    guru                           10                10
    mishra                         10                10
    leave_master table and it includes the following fields
    1.emp_name,
    2.leave_type
    3.no_of_days
    I have the form based on the table "leave_master"
    Here, the leave_type has the LOV which includes.
    sick and casual.

    When the form is filled out and clicked on the button submit,
    I need to update the column leave_type in table leave_type,
    for example,.
    if 
    emp_name:guru
    leave_type:sick
    no_of_days:3
    then I want to update the leave_type column,
    sick sick = - no_of_days for the 'guru' of name
    That is to say, ill = 10-3 = 7

    then the leave_type of the table must be,
    emp_name                       sick             casual
    guru                                 7                10
    mishra                              10               10
    someone can such me what code or method I can use?
    Thank you.

    Published by: Gurujothi on May 24, 2012 21:54

    Published by: Gurujothi on May 24, 2012 21:54

    Try something like this...

    BEGIN
    IF: PXX_LEAVE_TYPE = "Sick" THEN
    UPDATE LEAVE_TYPE
    THE PATIENT VALUE = SICK -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    ON THE OTHER
    UPDATE LEAVE_TYPE
    DEFINE CASUAL = CASUAL -: PXX_NO_OF_DAYS
    WHERE EMP_NAME =: PXX_EMP_NAME;
    END IF;
    COMMIT;
    END;

  • How can I update the column 1st day of each month

    Hello
    I have an Emp table with the following columns
    1.Emp_name varchar2(50),
    2.Days number(3).
    now it has the following features,
    Emp_name              Days
    Mishra                     11
    David                      15
    Raju                       18
    Now I need to update the column 'Days' 20 for emp_name all whenever the date is the first day of the month
    IE June 1, 2012 July 1, 2012 and so on.
    How can we do?
    can someone help me.
    Thank you.

    Look for the DBMS_SCHEDULER package.

    Kind regards

  • Do not update the column if the source column is null

    Hi all
    I'm trying to update some columns on the target, I won't update the column if the source is NULL for the column (do not replace the old value if the new value is zero). How can I do this using OWB. I use 11,1 g.

    Any help will be greatly appreciated.

    Thank you
    Ravi

    There are a few ways to do this:

    First of all, you can add your target to the canvas a second time as a source, an outer join to the source of queries on the same fields that you use in your target match constraint, and then run the new value and the existing value in an expression to generate the control you need and send the existing value if the new value is null.

    Alternatively, you can use a splitter on the lines with a single stream going where your field is null in this case update you the target without updating this field and the other the field update stream. This means that the generated code will now be an update of re-encoding re - query the same sources for the second pass, and that any recovery strategy you are not dependent on each mapping succeeding or failing as a total unit will have to be reconsidered.

    Or, of course, you can just put a trigger on the table to check the: new.value and overwrite it with the: if old.value: new.value is null.

    Mike

  • Best way to update the individual rows of a Table?

    I took a quick glance at a few examples, but did not get a clarification on this.  I am looking to have something close to a listbox control or the table to where I can update just one column of values to line a 1 time per second pace.  I'm looking to display our acquisition of data values in a table or a listbox control.  The single list box seemed to work well for that, but I couldn't use the row headers to list the names of channel beside the channel values.  I thought to link the values of cursor in two areas of list to do this, but did not find any info on it for the single list box.

    I have a few questions:

    (1) I have a 1 d table to where I want to use this data to constantly update the first column (with a multitude of lines) of a table.  I'm looking for the best route to not take too much time for treatment by doing this.

    What is the best way to update the individual rows of a table?   Invoke the node "Value of the cell value"... or is there another method?

    (2) why is that, after each iteration else, row values are deleted?

    Also, for adding additional channels originally arrray... it is better to use the 'Array' subset then the function "Construct the table" or function "Subset of the table" and "insert table"?

    See the attached example.

    Thank you.

    Jeff· Þ· Bohrer says:

    (2) why is that, after each iteration else, row values are deleted?

    Classic race condition.  dump the loop and node-p and just wire the 2D table on the terminal Board. !

    I don't see the race condition.  What I see is the table once the last element has been written for it all run the oil.  I saw looked it with point culminating performance on.

    But I agree entirely with writing to the Terminal.  It is a 1 d array, so you will need to use an array of generation and convert a 2D array in order so that he could write correctly.

  • Need to write the cursor to update the column

    Hi all

    I want to write a cursor in the CALC_TAX of the PP_TAX of the UPDATE table column
    Currently I use following update instructions to update the CALC_TAX column.

    UPDATE PP_TAX P
    SET CALC_TAX = ROUND (((P.ACTV_AMT * 5)/100), 2)
    WHERE PROV_DEC_FOR_TAX ("AB", "NT", "YT", "NAKED", "NV");

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 5)/100), 2) + Round (((P.ACTV_AMT + Round (((P.ACTV_AMT * 5)/100), 2)) * 8.5) / 100), 2)
    WHERE PROV_DEC_FOR_TAX ("QC");

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 5)/100), 2) + (((P.ACTV_AMT * 7)/100), 2nd round)
    WHERE PROV_DEC_FOR_TAX IN ("MB");

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 5)/100), 2) + Round (((P.ACTV_AMT + (Tower (((P.ACTV_AMT * 5)/100), 2)) * 10) / 100), 2)
    WHERE PROV_DEC_FOR_TAX IN ('PE');

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 5)/100), 2) + (((P.ACTV_AMT * 5)/100), 2nd round)
    WHERE PROV_DEC_FOR_TAX ('SK');


    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 13)/100), 2)
    WHERE PROV_DEC_FOR_TAX IN ('WE', 'NB', 'NL', 'YY');

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 12)/100), 2)
    WHERE PROV_DEC_FOR_TAX IN ("BC");

    UPDATE PP_TAX P
    SET CALC_TAX = Round (((P.ACTV_AMT * 15)/100), 2)
    WHERE PROV_DEC_FOR_TAX IN ('NS');

    Kindly help.

    This is what it would look like for the first two,

    UPDATE pp_tax p
    SET    calc_tax =
             CASE
               WHEN prov_dec_for_tax IN ('AB', 'NT', 'YT', 'NU', 'NV') THEN
                 ROUND ( ( (p.actv_amt * 5) / 100), 2)
               WHEN prov_dec_for_tax IN ('QC') THEN
                 ROUND ( ( (p.actv_amt * 5) / 100), 2) + ROUND ( ( ( (p.actv_amt + ROUND ( ( (p.actv_amt * 5) / 100), 2)) * 8.5) / 100), 2)
             END
    WHERE  prov_dec_for_tax IN ('AB', 'NT', 'YT', 'NU', 'NV', 'QC');
    

    Just add several WHEN clauses and include in the list of in WHERE clause.

    Concerning
    Peter

  • Update updated the columns with null are excluded from the DB adapter

    Hi all

    My fusion system interacts with DB2 using the DB adapter.

    I have a script that I need to update a flag in the table after completing my bpel workflow. But by updating the value of indicator to "Processsed", there are other columns with a NULL value.

    How to solve this problem. I don't want to do, the other columns should not be alerted.

    Thank you

    Richa

    Hello

    The issue has been resolved. In fact, I've updated the update statement, excluding items that couldnot be updated top link mappings. I had to create a new adapter and it worked.

    Concerning

  • Automatically update the column in the table in OBIEE

    Hi people,

    I have a requirement to say I need to update a column of table based on a condition, but this update should happen on a daily basis (I mean that it would be held once per day) by checking if all the records in this column meets the condition then update

    example:-column = 'pending', then using the "approved". As records of transactions every day in the table lights. OBIEE should check and update the line so the next time it does not show this line as "pending".

    I thought of 2 approaches to this
    (1) through the write-back, it is possible to update but manually (the question is it can't be automated or on demand on daily basis and update multiple records on a go)
    (2) write a stored procedure or a function of update, but how can I perform this procedure either regular or run once daily.how to use it?

    Any thoughts on the above two points or any method you can think off the coast.

    Any help is appreciated!

    See you soon,.
    KK

    Murielle,

    This shud be easy...
    -Create a direct database... with the Update statement
    for example: Update table set col = "Approved" where col = 'pending '.
    -Create an ibot using the RFI above and plan on a daily basis.

    This will update the complete table with the new value on a daily basis based on the State

  • SQL help - Need help to rotate the columns to rows

    I have a HughesNet to divide the columns into multiple lines. For example:

    EMP_DEPT

    ROWID empid1 ename1 empid2 ename2 empid2 ename2 empid4 ename4 dept4 dep3 dep2 dept1
    100001 1 'SCOTT' 10 2 'DAVE' 20 3 10 4 20 SMITH "MILLER"
    100002 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER' 20

    Note: EMP_DEPT do not always have information about the 4 employees settled for example in info only 3 employees rank 2 are there

    I need to convert and insert it into the EMPLOYEE table as follows:

    EMPLOYEE

    EmpID ename dept
    1 SCOTT 10
    2 20 DAVE
    3 MILLER 10
    4 SMITH 20

    1 SCOTT 10
    2 20 DAVE
    3 MILLER 20

    Thank you
    KeV

    Hey Kevin,

    Here's one way:

    WITH t AS (
      SELECT level i FROM dual CONNECT BY level <= 4
    )
    SELECT enty_type, enty_name, enty_id
    FROM (
      SELECT case when mod(t.i,2) = 0 then 'DEPARTMENT'
                  else 'EMPLOYEE'
             end as enty_type
           , case t.i
               when 1 then emp_name1
               when 2 then dept_name1
               when 3 then emp_name2
               when 4 then dept_name2
             end as enty_name
           , case t.i
               when 1 then emp_id1
               when 2 then dept_id1
               when 3 then emp_id2
               when 4 then dept_id2
             end as enty_id
      FROM emp
           CROSS JOIN t
    )
    WHERE enty_id IS NOT NULL
    ;
    

    Another using the MODEL clause:

    SELECT *
    FROM (
      SELECT enty_id, enty_name, enty_type
      FROM emp
      MODEL
      RETURN UPDATED ROWS
      PARTITION BY (pk)
      DIMENSION BY (0 i)
      MEASURES(
         emp_id1, emp_name1
       , emp_id2, emp_name2
       , dept_id1, dept_name1
       , dept_id2, dept_name2
       , cast(null as number(10)) enty_id
       , cast(null as varchar2(200)) enty_name
       , cast(null as varchar2(30)) enty_type
      )
      RULES (
         enty_type[1] = 'EMPLOYEE' , enty_id[1] = emp_id1[0], enty_name[1] = emp_name1[0]
       , enty_type[2] = 'EMPLOYEE' , enty_id[2] = emp_id2[0], enty_name[2] = emp_name2[0]
       , enty_type[3] = 'DEPARTMENT' , enty_id[3] = dept_id1[0], enty_name[3] = dept_name1[0]
       , enty_type[4] = 'DEPARTMENT' , enty_id[4] = dept_id2[0], enty_name[4] = dept_name2[0]
      )
    )
    WHERE enty_id IS NOT NULL
    ;
    

    Published by: odie_63 on 8 Dec. 2010 21:00

  • Update the column values with the new user who has changed the data in the current line

    I have a table, the following structure.

    CREATE TABLE FILTERCALENDAR1
    (DATE OF THE "C_DATE',
    NUMBER (1,0) 'DAY_OF_WEEK ',.
    NUMBER (1.0) "WEEK_WINDOW."
    NUMBER (1.0) "MONTH_WINDOW."
    NUMBER (1.0) "YEAR_WINDOW."
    NUMBER (1.0) "DATE_YEAR_WINDOW."
    NUMBER (1.0) "ONCE_WINDOW."
    VARCHAR2 (25 BYTE) "USERNAME."
    "LASTUPDATED" DATE
    );

    Problem:
    If a user changes the value of one of the columns I want to write his name to user and sysdate in the 'USERNAME' and LASTUPDATED' columns.

    * Tried: *.
    I tried an update trigger for this problem, but I get an error table mutation.

    The one you suggest how can I achieve this.

    Concerning

    Use BEFORE the UPDATE trigger

    CREATE OR REPLACE TRIGGER myTrigger
    before UPDATE ON FILTERCALENDAR1 FOR EACH ROW
    BEGIN
    :new.USERNAME := user;
    :new.LASTUPDATED := sysdate;
    END;
    
  • Cannot update the column "last_update", please help

    I want to add a "last_update" column in all tables of database, and then add a Tigger to update "last_update" timestamp after the row is updated. However, Tigger let me update "last_update" field updated in line. The error is ORA-04091 table is changing. How can I solve the problem?

    Trigger body will be like:

    begin
         :new.last_update:=sysdate;
    end;
    

    Or, please provide us with the trigger code.

  • Need help to update the graphics drivers for my Intel HD 4400

    Hello. I have an Aspire V5-561-6607 Windows 8.1 running with a chart Intel HD Graphics 4400 card.

    I have the latest drivers OEM of the Acer Web site. However, they are NOT the latest Intel drivers for the 4400 HD.

    I can't upgrade any more than the Acer drivers, despite the Acer drivers being obsolete.

    Is there something I can do? I know HOW to update the drivers, I can't just - when I try to manually update the drivers through the utility Intel it seems to think that Acer drivers are the absolute latest. Period.

    It raises questions for the games should not be a problem with, and I want to solve this problem.

    check if all entries is on/features of the program, if there is no evidence of installation, go to Device Manager, right-click on the Intel VGA adapter and select uninstall, if he asks me to remove the software drivers, check out the options and uninstall.

Maybe you are looking for