UPDATE the list of columns

Hi, need help with the following:
CREATE TABLE tbl_1 (
    rec_id NUMBER(9),
    col1 NUMBER(9),
    col2 NUMBER(9),
    col3 NUMBER(9),
    col4 NUMBER(9))
/
CREATE TABLE tbl_2 (
    rec_id NUMBER(9),
    col1 NUMBER(9),
    col2 NUMBER(9),
    col3 NUMBER(9),
    col4 NUMBER(9),
    col5 NUMBER(9),
    col6 NUMBER(9))
/
INSERT INTO tbl_1
     VALUES (101, 11, 21, 31, 41);
INSERT INTO tbl_1
     VALUES (102, 12, 22, 32, 42);
INSERT INTO tbl_1
     VALUES (103, 13, 23, 33, 43);
INSERT INTO tbl_1
     VALUES (104, 14, 24, 34, 44);



INSERT INTO tbl_2
     VALUES (101, 1, 1, 1, 1, 1, 1);
INSERT INTO tbl_2
     VALUES (102, 1, 1, 1, 1, 1, 1);
INSERT INTO tbl_2
     VALUES (103, 1, 1, 1, 1, 1, 1);
INSERT INTO tbl_2
     VALUES (104, 1, 1, 1, 1, 1, 1);
INSERT INTO tbl_2
     VALUES (105, 1, 1, 1, 1, 1, 1);


COMMIT ;

--Create procedure pr_upd(col_list) passing list of columns which has to be updated in TBL_2 with values from TBL_1
--for example if pr_upd ('col1,col3' ) called then only col1 and col3 updated in tbl_2 (with values from TBL_1)

--After procedure pr_upd ('col1,col3' ) called:
SELECT * FROM TBL_2 

REC_ID    COL1      COL2      COL3      COL4      COL5      COL6      
101       11        1         31        1         1         1         
102       12        1         32        1         1         1         
103       13        1         33        1         1         1         
104       14        1         34        1         1         1         
105        1        1          1        1         1         1

You will need to use dynamic SQL statements. Something like

CREATE OR REPLACE PROCEDURE pr_upd( p_col_list in  varchar2 )
AS
  l_sql varchar2(1000);
BEGIN
  l_sql :=
    'UPDATE tbl_2 ' ||
    '   SET (' || p_col_list || ') = ' ||
    '     (SELECT ' || p_col_list ||
    '        FROM tbl_1 ' ||
    '       WHERE tbl_1.rec_id = tbl_2.rec_id )' ||
    ' WHERE EXISTS ( ' ||
    '      SELECT 1 ' ||
    '        FROM tbl_1 ' ||
    '       WHERE tbl_1.rec_id = tbl_2.rec_id )' ;
  EXECUTE IMMEDIATE l_sql;
END;

which product

SQL> CREATE OR REPLACE PROCEDURE pr_upd( p_col_list in  varchar2 )
  2  AS
  3    l_sql varchar2(1000);
  4  BEGIN
  5    l_sql :=
  6      'UPDATE tbl_2 ' ||
  7      '   SET (' || p_col_list || ') = ' ||
  8      '     (SELECT ' || p_col_list ||
  9      '        FROM tbl_1 ' ||
 10      '       WHERE tbl_1.rec_id = tbl_2.rec_id )' ||
 11      ' WHERE EXISTS ( ' ||
 12      '      SELECT 1 ' ||
 13      '        FROM tbl_1 ' ||
 14      '       WHERE tbl_1.rec_id = tbl_2.rec_id )' ;
 15    EXECUTE IMMEDIATE l_sql;
 16  END;
 17  /

Procedure created.

SQL> exec pr_upd ('col1,col3' );

PL/SQL procedure successfully completed.

SQL> select * from tbl_2;

    REC_ID       COL1       COL2       COL3       COL4       COL5       COL6
---------- ---------- ---------- ---------- ---------- ---------- ----------
       101         11          1         31          1          1          1
       102         12          1         32          1          1          1
       103         13          1         33          1          1          1
       104         14          1         34          1          1          1
       105          1          1          1          1          1          1

SQL>

Justin

Tags: Database

Similar Questions

  • Windows Media Center has stopped updating the lists Guide for Windows 7

    Windows 10 will go out the next Wednesday July 29, 2015. I have Windows 7 and I have technical problems with the Guide in Windows Media Center lists. This isn't updated Guide lists and I wonder if this problem is related to the upgrade of Windows 10?

    I called a technician to answer Microsoft desktop and the technician fixed my computer errors. Unfortunately, he could not fix this problem. Even though I always reset and auto update of listings in the Guide, the result will prove be the same with "no data."

    Windows Media Center has given me many error messages:

    Windows Media Center

    "Windows Media Center has corrected a problem with your registration data and will download the Guide even once. You should review your records to make sure they are always planned properly. »

    Failed to download

    "The new TV configuration data could not be downloaded. Existing data, if any, will be used as you continue by configuring the TV signal. »

    Downloadable guide is not available

    "Downloadable TV Program Guide listings are not available due to previous failures of download. For more information, right-click on the Windows Media Center system tray icon and open Windows Media Center update log. Select back to try again. You may be able to get the TV show lists, if they are available. »

    Guide download error

    "The Guide could not be downloaded. For more information, then Windows Media Center system tray icon right-click and open Windows Media Center update log. »

    I can watch TV on the computer using Windows Media Center and manually record TV shows, but it is difficult for me to record TV shows without ads Guide on Windows Media Center.

    Note to update (as of August 2, 2015):

    The Electronic Program Guide (EPG) for Windows Media Center Guide ads was already programmed by zap2it until July 21. After July 21, zap2it is no longer can update the lists Guide for Windows Media Center.

    July 23, Rovi Corporation's new Electronic Program Guide (EPG) for Windows Media Center Guide ads.

    From 23 July, listings in Windows Media Center Guide is running back to normal for Windows 7 users.

    My Guide Panel is equipped with a selector more [on the listings in the Guide] where is the expiration date. I hope that Microsoft does not support Windows 7 WMC.

    Please don't waste your time trying to solve the WMC, it is the expiration of the license that is causing the problem. I know it's frustrating.

    On the other hand, is - can anyone say with certainty that WMC is available on Windows 10? No charge for the upgrade to Windows 7?

    The way I see it, not providing the function of key in W7 WMC guide is motivation upgrading to W10, assuming that WMC is available.

    Hopefully Microsoft will give us the fix for WMC in W7.

  • Classic generic column report - update the list column

    Consider a dynamic pivot statement as follows (as described by the AMIS) which

    select * from table( pivot(  'select deptno,  job, count(*) c from scott.emp group by deptno,job' ) )
    
    
    
    

    I used this as a SQL source for the classic report, by selecting "use generic column names.

    The report looks like

    dp_full.png

    I can set up the data displayed with a selection list and including a clause where clause

    where job =v(''P39_JOB'') or v(''P39_JOB'') is null
    
    
    
    

    List select not PPR on the region,demonstrated here:

    https://Apex.Oracle.com/pls/Apex/f?p=73000:39:

    Note: , and all swivel jobs are still visible in the form of columns, data is limited

    -other jobs are empty

    -departments with no clerks are not shown

    dp_clerk.png

    Let's say you have another list of selection than the work of groups, say the "Présidents" and "close".

    How can you update the region to exclude certain jobs?

    Reload the page with the value of P39_JOB already set will not affect the result, while including a literal string made.

    It seems maybe ODCI function analyzes the query on Lees null, and then fills with actual results.

    Does anyone have any suggestions?

    Update: it seems a workaround is to inject the value as a substitution string, for example:

    and employment as ' & P39_CEO. »

    where P39_CEO is lacking in session state %

    I've only had this concept works in my client application (4.2, 11 2 GR), not my demo (5.0, 12 c), to even try to meet the relevant quotes and when null. I kept getting

    error report: ORA-1403: no data found

    I could not work how to correctly apply sys.dbms_assert.enquote_literal)

    Scott

    Hi Scott

    What approach I described in this post: matrix report?

    It eliminates the need for any dynamic SQL and I think filtering options might be implemented using SQL/XML features.

  • Windows Update empty list updates the list (w / updates)

    I have a weird problem with Windows Update on the Windows 7 x 64 (which obviously appeared after a while - not straight out-of-the-installation).
    The problem is this: I have open Windows Update, click "Find updates", it tells me there are 3 optional updates available, click on "3 optional updates available" to make me choose which install, opens the list of updates, but... it is empty! And on the left, he continues to say "Optional (3)" (screenshot to http://img109.imageshack.us/img109/4839/wufail.png )
    This happens also with the important updates, that they however to settle as they are selected by default, I guess.
    Needless to say, without hidden updates are present...

    Suggestions?

    Thanks in advance

    Giulio

    Sorry, as the problem appeared, now he's gone... no idea how that happened (other than a BSOD forcing _another_ reboot...)! So... Detective Conan!

  • The Task Manager, update the list of tasks and processes, but removes them from the list, the next second.

    It was fine a few days ago, the list of tasks and processes will not be updated until I open/close something. Now, it refreshes the list every second. I tried to change the speed of update, but makes no difference. An answer by tomorrow would be the best.

    More information:
    Windows 7 x 64
    Home Premium Service Pack 1
    Using AVG anti-virus

    Hello

    Thank you for your response.

    Keep the computer in a clean boot and check the status of the issue.

    How to perform a clean boot for a problem in Windows Vista, Windows 7 or Windows 8.

    http://support.Microsoft.com/kb/929135

    Note: please go through the section: How to reset the computer to start as usual after a clean boot troubleshooting section of Kb to start the computer to a normal startup after you fix the problem.

    I would like to aslso season allows you to check the status of the question in a new user account.

    Create a user account:
    http://Windows.Microsoft.com/en-us/Windows7/create-a-user-account

    If it works in a new user account, then you will need to fix the corrupted user profile. You can visit this link for the steps:

    http://Windows.Microsoft.com/en-us/Windows7/fix-a-corrupted-user-profile

    I hope this helps.

  • Can someone help me with an 'easy to update the list of products?

    I'm doing a site for a client who are selling second hand machines and want to have a page with products that are for sale.

    This page should be easy to update because my client is going to do it himself.

    The problem is that if the list's container 10 products and, for example, the number 4 is sold, we do not want a gap in the list when my client is made number 4 on...

    We want a nice and smooth list that, when a product is sold and removed, there will be a nice list of 9 products.

    It should be really easy to update with editing in the browser... Anyone with an idea how to solve this problem?

    Thank you!

    Through IBE, your customer can change the image and publish the modified image/text. But to change the list itself with the same design, you would need for that of Muse.

    Another idea would be to show the item as "unavailable" once it is sold out to keep the list in the same format without modification.

    Thank you

    Sanjit

  • need help to trigger to update the change of columns of a table

    Hi all
    I need help in the manufacture of change update trigger in the columns from one table to another table.
    For example, table (col1 col 2 col 3 col 4 col 5 samplea
    .. .Col 20

    Now if I do any change in one of the data column must be changed to
    sample_copya... table that contains duplicate column

    So for this I thought to create a trigger with the following logic



    If updating (col1) then
    Update sample_copya set col1: =: new.col1 where n ° 1 =: new.no1;
    Otherwise, if the update (col2) then
    Update sample_copya set col2: =: new.col2 where n ° 1 =: new.no1;
    Otherwise, if the update (col3) then
    Update sample_copya set col3: =: new.col3 where n ° 1 =: new.no1;

    end if;
    But how doi handle if all columns are changed or say 2 columns record the number of columns is more than 20...
    I would like to know if there is a simpler method to achieve...
    Thank you

    susf wrote:
    Hi all
    I need help in the manufacture of change update trigger in the columns from one table to another table.
    For example, table (col1 col 2 col 3 col 4 col 5 samplea
    .. .Col 20

    Now if I do any change in one of the data column must be changed to
    sample_copya... table that contains duplicate column

    So for this I thought to create a trigger with the following logic

    If updating (col1) then
    Update sample_copya set col1: =: new.col1 where n ° 1 =: new.no1;
    Otherwise, if the update (col2) then
    Update sample_copya set col2: =: new.col2 where n ° 1 =: new.no1;
    Otherwise, if the update (col3) then
    Update sample_copya set col3: =: new.col3 where n ° 1 =: new.no1;

    end if;
    But how doi handle if all columns are changed or say 2 columns record the number of columns is more than 20...
    I would like to know if there is a simpler method to achieve...
    Thank you

    What is the purpose of this trigger?
    How can you be sure that ' where n ° 1 =: new.no1 "is true?
    How does line in the SAMPLE_COPYA table at the start?
    only the last modified value will lie in SAMPLE_COPYA than the previous values is written more

  • Update the list of features supported

    I suggest that you update the guide for help on the supported features.

    Recently I was wrong due to this list on the supported features, horizontal sliding, flattened articles on Android devices.

    The list shows that its not supported on Android, but in fact it is.

    http://helpx.Adobe.com/Digital-Publishing-Suite/help/supported-feature-list.html

    Sorry, I missed that one. I've updated the help article. Thanks for reporting the error.

  • How can I update the list of lenses for Nikon 500 mm F4.0 and Nikon 35-70 mm f 2.8?

    In the development phase can corrective lenses for lenses known according to the manufacturer.

    However, the above mentioned 2 lenses are not in the list.

    How can you include in the list?

    Thank you

    Ofer

    You must locate the profiles of boards or create profiles for the lenses. There is a utility, Adobe Lens profile Downloader:

    Adobe - Ado be Lens profile Downloader: For Windows: Adobe Lens profile Downloader 1.0.1

    Adobe - Adobe Lens profile Downloader: for Macintosh: Adobe Lens profile Downloader 1.0.1: thank you

    If you do not find one available, you can then use the lens profile creator:

    Adobe - Adobe Lens profile creator: for Macintosh: Adobe Lens profile creator 1.0.4

    Adobe - Adobe Lens profile creator: for Windows

  • When I right click on the list box column Multi that I should get the custom options

    Hi all

    In my application, I want to display the custom user menu when it right-click on the Multi column list box. I want to know is - it possible to do like this. Please can someone help me on this?

    in abow picture I get "reset default value, cut, copy the data, past data" so I need to set other options.

    Kind regards

    Santhosh M

    Hi santosh,.

    This one is much better.

  • Cost of updating the lists of filters for Forefront TMG

    Through our MS schools agreement (Volume License), we have purchased a license for Forefront TMG, which is installed and works very well. Would soar, as to clarify cost/licensing of the filtering side of this product different staff members have found different information (some contradictory) on this approval.

    The main request is the access to updates for filters (lists updated groups or sites etc.) so that, for example, if block us access to the category of games that list URLS within the category is up to date and will continue to be updated by MRS. Is there any additional cost to do it this way?

    Hi Murray has,

    I suggest you to see the link below:

    http://www.Microsoft.com/forefront/en/us/suite-pricing-licensing.aspx

    You can also contact TechNet for more information on Forefront for Microsoft Exchange:

    http://social.technet.Microsoft.com/forums/en-us/categories/

  • How can I update the primary key column

    Hello
    Can you suggest me best workaround/algorithm for task below:

    (Oracle 10g, Solaris OS.)
    Location:
    Table a primary key column P 'Code', tables children F1, F2,..., reference to F15 "Code_P' foreign key column"P.Code"column, and we do not know which of the child tables data available for a particular value"P.Code.
    Task:
    Change the value "P.Code" from 100 to 200. So that the result would be that record P [Code = 100] should be updated:
    update P set
    Code = 200
    where Code = 100;
    And child tables 'Code_P' column should be updated as:
    update F1, F2, .., F15 set
    P_code = 200
    where P_code = 100;
    The best solution would be that you can easily repeat this task.

    Edited by: CharlesRoos the 28.12.2010 12:10

    Will there be FK constraints in place?
    If so, you may need to modify them so that their application may be temporarily deferred.

    The gameplan would be something like this:

    -Making of CF can be deferred, immediate departure.
    -Alter FK set delay.
    -Update of Parent table.
    -Update of the children tables.
    -Immediate constraints set
    s ' engage;

  • Windows will not update the list of printers

    When I select Add Printer witout a CD (ie. windows update) it fails and says try again

    See: http://windows.microsoft.com/en-US/windows7/Install-a-printer

    and http://windows.microsoft.com/en-US/windows7/Automatically-get-recommended-drivers-and-updates-for-your-hardware

    It is always recommended that get you the drivers for your hardware from the manufacturer site, in this way, you get the right driver and the updated driver.

    So, if you try to install a printer without the CD, go to the manufacturer site rather than trying to do it through Windows Update.

  • type in the list of columns SCRIPTUI

    Hi guys,.

    I have a terminology database that I created and I would like to add a feature that allows users to type in the edittext field to search for items in col1.

    Here is my code for the columns and the edittext field:

    var column = w.add('group{multiselect:true}');
    Columns.Spacing = 0;

    CGEM var = [0,0,200,600];

    var col1 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Trans-tibiale", "Trans-fémorale"]);
    var col2 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Party", "Transfémoral"]);        French
    var col3 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Trans-tibiale", "Trans-fémorale"]);      German
    var col4 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Transtibial", "Transfemorale"]);     Italian
    var col5 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Party", "Security"]);        Spanish
    var col6 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Trans-tibiale", "Trans-fémorale"]);      Norwegian
    col7 var = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Trans-tibiale", "Trans-fémorale"]);      Russian
    var col8 = columns.add ("listbox", CGEM, ["Dorsiflexion", "Field", "Trans-tibiale", "Trans-fémorale"]);      Turkish


    col1. Selection = 0;

    {col1. OnDoubleClick = Function ()}
    entry. Text = col1. Selection;
    };
    {col2. OnDoubleClick = Function ()}
    entry. Text = col2. Selection;
    };
    {Col3.OnDoubleClick = Function ()}
    entry. Text = Col3.Selection;
    };
    {Col4.OnDoubleClick = Function ()}
    entry. Text = Col4.Selection;
    };
    {col5. OnDoubleClick = Function ()}
    entry. Text = col5. Selection;
    };
    {col6. OnDoubleClick = Function ()}
    entry. Text = col6. Selection;
    };
    {col7. OnDoubleClick = Function ()}
    entry. Text = col7. Selection;
    };
    {COL8. OnDoubleClick = Function ()}
    entry. Text = COL8. Selection;
    };

    var user_input = w.add ('group')
    entry var = user_input.add ("'edittext', dimH, ' click on the button to the right to convert lowercase");
    entry. Characters = 30;
    entry. Alignment = 'left';
    entry.active = true;


    converting the vars = user_input.add ('button', undefined, "Convert to lowercase");
    convert.onClick = function () {entry.text = entry.text.toLowerCase () ;}
    user_input.orientation = 'row';
    user_input. Alignment = 'left';

    Everyone here is so helpful.

    Thank you

    Jake

    There are some examples of upcoming type here:

    https://INDD.Adobe.com/view/a0207571-ff5b-4bbf-A540-07079bd21d75

    Moreover, the group object is the multiselect property.

    Peter

  • the list of columns separated by commas of a dictionary table table

    I use the following question.

    CONNECT_BY_ROOT SELECT table_name TopLevel, level,
    connect_by_isleaf IS_Node_leaf,
    substr (SYS_CONNECT_BY_PATH (column_name, ','), 2) column_name
    Of all_tab_cols
    where connect_by_isleaf = 1
    and column_id < (select max (column_id) + 1 all_tab_cols
    where table_name = 'Table_test')
    and column_id > (select min (column_id) - all_tab_cols 1
    where table_name = 'Table_test')
    START WITH table_name = "Table_test."
    CONNECT BY PRIOR column_id = nocycle (column_id - 1).
    AND table_name = "Table_test."

    The only problem with this query is that it goes into infinite loop. Can someone suggest a better solution?

    Why you ask all_tab_cols, I think will realize you that it will pull all tables in your database.

    If you want to retrieve the name of the table and the columns (separated by commas) your schema, you must query user_tab_cols.

    and here is the sql code

    select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names
    from
    (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn
    from user_tab_cols)
    where connect_by_isleaf = 1
    start with rn=1
    connect by prior rn=rn-1 and prior table_name = table_name
    /
    

    Or, you can use all_tab_cols to query a specific table by passing the name of the table and the name of the owner

    PRAZY@11gR1> desc test
     Name
     -------------------------------------------
     NUM
     NUM2
    
    PRAZY@11gR1>
    select table_name,ltrim(sys_Connect_by_path(column_name,','),',') column_names
    from
    (select table_name,column_name,row_number() over (partition by table_name order by column_id) rn
    from all_tab_cols
    where owner='PRAZY' and
    table_name = 'TEST')
    where connect_by_isleaf = 1
    start with rn=1
    connect by prior rn=rn-1 and prior table_name = table_name
    /
    PRAZY@11gR1> /
    
    TABLE_NAME                     COLUMN_NAMES
    ------------------------------ ----------------------------------------
    TEST                           NUM,NUM2
    
    Elapsed: 00:00:00.01
    

    HTH,
    Prazy

    Published by: Prazy on April 28, 2010 10:23

Maybe you are looking for