Mark from a table where the column value is a colon-delimited list

Version: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

Hello

This is a new query of a query Frank helped me with: https://community.oracle.com/message/12506306#12506306

Demand is all users to restrict the report based on a multiple selection on the front-end server (application APEX) filter.

The filter returns that a colon-delimited list and the data in the table can be saved in a delimited by a colon list too. There may be 1 to n values (up to 4000 characters).

I need a WHERE clause that will allow a match, if it exists, between the data in the column of the Table and the Mult-selection list filter.

The abbreviated for this post query would be something like:

SELECT slt_id, slt_item, slt_owner

OF slt_dashboard

WHERE slt_owner IN (colon delimited page list);

The Create Table and Insert statements:

CREATE TABLE slt_dashboard
(
  dashboard_id  NUMBER,
  slt_id        VARCHAR2(10),
  slt_item      VARCHAR2(2500),
  slt_owner     VARCHAR2(4000),
  slt_type      VARCHAR2(25),
  slt_year      NUMBER,
  parent_id     NUMBER
);

--Insert slt_dashboard
INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id)
VALUES (12,'1.1','Implement revenue enhancement initiatives','E15889:JPARISI:BDUR63','Business Commitment',2014,6);

INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id)
VALUES (13,'1.2','Strengthen our Energy position','KVROMAN','Business Commitment',2014,6);


I have a function to separate the list delimited by two points in a table for the IN clause, but because these values can be saved in a delimited list of Colon in the column of the Table, I have a problem, being able to analyze the data in the column, AND the filter data.

The function is:

CREATE OR REPLACE FUNCTION get_list( p_string IN VARCHAR2
                                    ,p_delimiter IN VARCHAR2 DEFAULT ':'
                                   )
    RETURN vc_array_1
    PIPELINED
IS
    l_string VARCHAR2( 32000 );
    l_array wwv_flow_global.vc_arr2;
BEGIN
    l_array     :=
        APEX_UTIL.string_to_table( p_string
                                  ,p_delimiter
                                 );

    FOR i IN l_array.FIRST .. l_array.LAST
    LOOP
        PIPE ROW ( TRIM( l_array( i ) ) );
    END LOOP;

    RETURN;
END;


The function called in the query in the form (it's just for reference in case someone wanted to know):

SELECT ...
FROM ...
WHERE slt_owner IN (SELECT * FROM TABLE( get_list( :P115_SLT_OWNER ) ));

But I can't use this approach because the data in the Table can be saved in a delimited list of Colon too.

Desired output:

If the Mult-Select list filter contains: E15889:JPARISI then

1.1 implementation of the E15889 revenue improvement initiatives; JPARISI (it's a semicolon between the names)

If the multiple-selection list filter contains: KVROMAN then

1.2 strengthen our position of energy KVROMAN

If the multiple-selection list filter contains: BDUR63:KVROMAN then

1.1 implementation of the BDUR63 revenue improvement initiatives

1.2 strengthen our position of energy KVROMAN

Please let me know if something is not clear.

Thank you

Joe

I went to approach the Table and the Page works perfectly.

Thank you to everyone!

Thank you

Joe

Tags: Database

Similar Questions

  • Select only records where the column values are not all equal to zero

    Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
    with mytable as (
    select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all
    select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all
    select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all
    select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all
    
    select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual
    )
    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    order by itemtype
    I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.

    In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.

    Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?

    Thanks in advance!
    Mark

    Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
    {code}
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype

    less

    Select
    ItemType,
    Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
    de)
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype
    )
    where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
    apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
    )
    order of itemtype
    {code}

    Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...

    {code}
    WITH mainquery as (select all)
    Select * from mainquery
    less
    Select * from mainquery where (oct = 0, nov = 0, etc...)
    {code}

    Thanks again!
    Mark

    Published by: user455268 on March 1, 2012 19:13

    Published by: user455268 on March 1, 2012 19:16

    Hello

    You can do it with a HAVING clause:

    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    HAVING      MIN (theval)     != 0
    OR      MAX (theval)     != 0
    order by itemtype
    ;
    

    If the values are all 0, then the MIN and MAX will be 0.
    If the MIN or MAX is not 0, the values are all 0.

    This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
    If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique.

  • SQL join on the two tables where the column as another column

    Hi all


    tried to get the results of a join between two tables where only one column is like another.

    Table1 (nameA) examples: black2, green1

    Table2 (Name) example: black2.location.uk.com, green1.location.uk.com

    so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!

    My sql up to now:
    select * from  schema.table1 a
    join schema.table2 b 
    on a.nameA like concat('%', b.nameB, '%'); 
    but it errors:

    ORA-00909: invalid number of arguments
    00909 00000 - "invalid number of arguments.

    Any help or advice would be greatly appreciated, thank you!

    Or any of them should do...

    select * from  schema.table1 a
    join schema.table2 b on a.nameA like '%'||b.nameB||'%';
    

    or

    select * from  schema.table1 a
    join schema.table2 b on instr(b.nameB,a.nameA) > 0
    
  • Is it possible to create a table where the month series is represented as columns?

    Anyone know if it is possible to create a table view where the columns contain dates?  I have not seen something like this in Foglight, so I think that it is not possible currently.  Here is an approximate example of what I mean:

    The 2011 monthly average of JVM heap utilization %

    Server Jan Feb Mar Apr May Jun Jul Aug Ms Oct Nov Dec
    WebSphereServer_1 67 87 45 65 67 78 56 78 88 45 67 77
    WebSphereServer_2 45 56 45 68 89 90 99 34 45 67 78 78
    WebSphereServer_3 67 78 56 34 35 57 7 68 99 78 45 56

    Yes, it is possible.

    You can see examples of that in the out-of-the-box reports / canned reports / group, including "physical host - CPU Utilization monthly summary" and "physical host - memory usage monthly summary.

    You can set this in a Row-Oriented table by specifying the column property 'Iterate Over'.

    You would typically set the value of the "Iterate Over" property to the result of the construction in the query "N consecutive time the beaches."

    Review the definition of "reports / canned reports/memory usage Table" for details.

    Kind regards

    Brian Wheeldon

  • Where the das value the FQDN in OME Alert Message comes from

    If I place an alert Action to OME, OME provids the details of the alert Message to the script that I defined. In the alert Message, there are several types of information, such as Service number, alert and FULL domain name.

    Now, at one customer site OME reports for appliance name and domain FULL of different values. I was wondering where the FQDN value is taken. It is something of DNS or has he just iDRAC? If it comes to the iDRAC, I can configure it? Is this something I can configue on OME or iDRAC?

    OME performs a reverse DNS lookup.

    This is a list of name resolution that OME crosses top down

    1. If the inventoried by OMSA server then the FQDN DNS name servers
    2. iDRAC name DNS (Reverse DNS lookup)
    3. iDRAC (iDRAC host name parameter) host name
    4. IP address

    If you let the iDRAC registers in the system DNS enable this check mark.

  • Returns all duplicate rows, where the columns correspond

    Dear members,

    I have a table that contains duplicates, and the query should return only the rows where the columns correspond...

    create master table (varchar2 (10) firstname, lastname varchar2 (10), code VARCHAR2 (3), place varchar2 (10));

    insert into Master values ('bob', 'John', '1', 'atlanta');
    insert into Master values ('bob', 'John', '1', 'atlanta');
    insert into Master values ('bob', 'John', '1', 'atlanta');

    insert into Master values ('test', 'John', '1', 'atlanta');

    Insert into master values('bob','john','1','bank');


    The application should we 3 rows.

    Bob-john-1-atlanta
    Bob-john-1-atlanta
    Bob-john-1-atlanta


    I tried a few changes to query such as select * from master M, mater n where m.firstname = n.firstname and...

    Is there another way to do this...

    Thanks in advance...
    select  firstname,
            lastname,
            code,
            place
      from  (
             select  m.*,
                     count(*) over(partition by firstname,lastname,code,place) cnt
               from  master m
            )
      where cnt > 1
      order by firstname,
               lastname,
               code,
               place
    /
    
    FIRSTNAME  LASTNAME   COD PLACE
    ---------- ---------- --- ----------
    bob        john       1   atlanta
    bob        john       1   atlanta
    bob        john       1   atlanta
    
    SQL> 
    

    SY.

  • convert the column values to a single line...

    I have to return the column values to a single line separated by commas.
    If the nulls in the column just ignore without a comma.
    Here is one for example. There are three values and two NULL values in the table
    SQL> select ID from temp_fa;
    ID
    -----
    
             1
             2
    
             3
    
             5
    
    6 rows selected.
    
    
    I am expecting an output as 1,2,3,5
    Help, please

    There is always more than one title in the Oracle world ;)
    You can use the TRIM, for example (same configuration as your example):

    hoek&XE>  create table t as select level col  from dual connect by level <= 6;
    
    Tabel is aangemaakt.
    
    hoek&XE> update t set col = null where col in (1,3,5);
    
    3 rijen zijn bijgewerkt.
    
    hoek&XE> select * from t;
    
           COL
    ----------
    
             2
    
             4
    
             6
    
    6 rijen zijn geselecteerd.
    
    hoek&XE> select ltrim(sys_connect_by_path(col, ','), ',') output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1
      7  start with rn=1
      8  connect by rn = prior rn+1;
    
    OUTPUT
    -------------------------------------------------------------------------------------------------------------
    2,4,6,,,
    
    1 rij is geselecteerd.
    
    hoek&XE> select trim ( both ',' from sys_connect_by_path(col, ',')) output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1
      7  start with rn=1
      8  connect by rn = prior rn+1;
    
    OUTPUT
    -------------------------------------------------------------------------------------------------------------
    2,4,6
    
    1 rij is geselecteerd.
    
  • Problem: Build a VI to display a string in the table of the lights. Each letter must be posted in a separate table and letters must move from one table to the other in the direction from left to right.

    Hi all

    Problem: Build a VI to display a string in the table of the lights. Each letter must be posted in a separate table and letters must move from one table to the other in the direction from left to right.

    I did program mentioned above but it does not work. Can you tell me what is the problem?

    There is no error is indicated in the program. If someone knows about it please try to find solutions and help me out of this problem.

    I have attached my program with this message.

    Thank you in advance!

    (1) FOR loops are your friend here.  You can make a slight restructuring using loops, and then you will have less mess to deal with, the inner loop through tunnels of autoindexing to make it even simpler.

    (2) I would only treat the numeric values of the characters.  So go terminal of control of the chain, the capital letters and byte array to before the outer loop.  You can use a size of Board over there to tell how many times the outer loop to iterate.

    (3) the Index table is extensible.  So you only need over the index of the first, and it will increment itself, as it develops.

    (4) you need to finish the lookup table (table 3D)

  • Can hyperic agents collect metrics from a server where the 'root' FS went to ' read-only '?

    Hello

    Can agent hyperic able to collect measures from a server where the 'root' FS went to ' read-only '?

    IE will be hyperic monitoring work if 'root' FS managed server went to fashion 'read only '?

    Thank you

    The agent record metric data in the local server in the data directory.

    These data will be sent to the Hyperic server.

    As a result, the agent must write permissions on local storage.

  • Where the parameter value RepriceOrderChainId as repriceOrder in ExpressCheckoutF

    Guys,

    Do you have any ideas on below concern. Please share with us.

    PurchaseProcessFormHandler is an abstract class.

    ATG OOTB:
    ExpressCheckoutFormHandler extends PurchaseProcessFormHandler {}
    handleExpressCheckout () {}
    runRepricingProcess();
    }
    }

    RepriceOrderChainId property has getters and setters to PurchaseProcessFormHandler.

    No RepriceOrderChainId value in the PurchaseProcessFormHandler and ExpressCheckoutFormHandler component.

    But when I logdebug, RepriceOrderChainId values shows "repriceOrder".
    Here, I have a problem where the RepriceOrderChainId value defined as repriceOrder in the flow of
    ExpressCheckoutFormHandler - > PurchaseProcessFormHandler.

    Thank you

    Yes, because PurchaseProcessFormHandler is initialized to repriceOrder of the PurchaseProcessConfiguration.repriceOrderChainId. This happens in his doStartService(). PurchaseProcessConfiguration is located in ExpressCheckoutFormHandler.properties

    If you want to change the mechanism, change it in PurchaseProcessConfiguration and it will reflect PurchaseProcessFormHandler and therefore ExpressCheckoutFormHandler.

    -Kiss

  • Convert the column values into buckets

    Hello

    Please help me to convert the column values into buckets.
    I have the values of the columns in the following way.


    Age of Orderdate * 9 10 12 14 15 18 19 20 21 22 26 27 28 29 33 34 40 45 * and so on



    But the requirement is the column values should be displayed in form

    Age by order date * 15 1 2 3 4 5 6 7 8 9 10 11 - 16-20 21-25, 26-30 30 + *.


    Please someone give me the solution.

    Thanks in advance.

    Hervé Rama

    Hi Richard,

    Just to double check, you have Setup buckets for 1, 2, 3, 4, 5, 6, 7 and 8 individually (each with a fair value). The problem is that you simply do not have all data fall into buckets above, correct?

    If this is the case, it looks like has been answered your original question. If so, the label would assign 'Proper' points by clicking on the button label correct next to the appropriate response and open a new thread with your new question. The reason why I say this is it will help other people who have a similar bucket question to your solution, without complicating the issue with subsequent questions.

    If you can post a separate thread, I'd be more than happy to help you with your secondary problem.

    Best regards

    -Joe

  • Need help to build the query/pl-sql block to get the query result and the name of column from DB table in the form of key-value pairs.

    Hi Experts,

    I have a DB table has columns of more than 50.

    I question this table, it should only return one line at any time. as sqldeveloper below image.

    here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.

    Eg:     Key                         -  Value

    TASK_EVENT_ID - 1765

    EVENT_TYPE - ASR_UPDATE

    ... etc until all of the columns in my table.

    Experts please comment on that point, appreciate your help on this.

    Thank you

    -Vincent.

    Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)

    create or replace procedure (task_expired)

    v_store_id in full,

    v_task_action_id in full,

    v_job_id in full

    )

    as

    -[SNIP code...]

    v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123';  -Your SQL here!

    v_v_val VARCHAR2 (4000);

    v_n_val NUMBER;

    v_d_val DATE;

    v_ret NUMBER;

    c NUMBER;

    d NUMBER;

    col_cnt INTEGER.

    f BOOLEAN;

    rec_tab DBMS_SQL. DESC_TAB;

    col_num NUMBER;

    vAsString VARCHAR2 (4000);

    BEGIN

    -[SNIP code...]

    Message_properties. CORRELATION: = "EDF_EVENT";

    MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();

    Msg.set_string_property ('queueName', ' shipping/csi_cth');

    Msg.set_string_property ('MODE', 'CR8');

    c: = DBMS_SQL. OPEN_CURSOR;

    DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);

    d: = DBMS_SQL. Execute (c);

    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);

    1.col_cnt J

    LOOP

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val);      -Number

    WHEN 12 CAN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val);      -Date

    ON THE OTHER

    DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000);   -Else treat as varchar2

    END CASE;

    END LOOP;

    LOOP

    v_ret: = DBMS_SQL. FETCH_ROWS (c);

    WHEN OUTPUT v_ret = 0;

    1.col_cnt J

    LOOP

    -Fetch each column to the correct data type based on coltype

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);

    vAsString: = to_char (v_n_val);

    WHEN 12 CAN

    DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);

    vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');

    ON THE OTHER

    DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    vAsString: = v_v_val;

    END CASE;

    Msg.set_string_property (rec_tab (j) .col_name, vAsString);

    END LOOP;

    END LOOP;

    DBMS_SQL. CLOSE_CURSOR (c);

    DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',

    Enqueue_options => Enqueue_options,

    Message_properties => Message_properties,

    Payload-online msg,

    Msgid => Message_handle);

    dbms_output.put_line ('00 Msgid =' |) Message_handle);

    dbms_output.put_line('===Done=');

    -[SNIP code...]

    END;

    /

  • update to column values (false) in a copy of the same table with the correct values

    Database is 10gr 2 - had a situation last night where someone changed inadvertently values of column on a couple of hundred thousand records with an incorrect value first thing in the morning and never let me know later in the day. My undo retention was not large enough to create a copy of the table as it was 7 hours comes back with a "insert in table_2 select * from table_1 to timestamp...» "query, so I restored the backup previous nights to another machine and it picked up at 07:00 (just before the hour, he made the change), created a dblink since the production database and created a copy of the table of the restored database.

    My first thought was to simply update the table of production with the correct values of the correct copy, using something like this:


    Update mnt.workorders
    Set approvalstat = (select b.approvalstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi)
    where exists (select *)
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi)

    It wasn't the exact syntax, but you get the idea, I wanted to put the incorrect values in x columns in the tables of production with the correct values of the copy of the table of the restored backup. Anyway, it was (or seem to) works, but I look at the process through OEM it was estimated 100 + hours with full table scans, so I killed him. I found myself just inserting (copy) the lines added to the production since the table copy by doing a select statement of the production table where < col_with_datestamp > is > = 07:00, truncate the table of production, then re insert the rows from now to correct the copy.

    Do a post-mortem today, I replay the scenario on the copy that I restored, trying to figure out a cleaner, a quicker way to do it, if the need arise again. I went and randomly changed some values in a column number (called "comappstat") in a copy of the table of production, and then thought that I would try the following resets the values of the correct table:

    Update (select a.comappstat, b.comappstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi - this is a PK column
    and a.comappstat! = b.comappstat)
    Set b.comappstat = a.comappstat

    Although I thought that the syntax is correct, I get an "ORA-00904: 'A'. '. ' COMAPPSTAT': invalid identifier ' to run this, I was trying to guess where the syntax was wrong here, then thought that perhaps having the subquery returns a single line would be cleaner and faster anyway, so I gave up on that and instead tried this:

    Update mnt.workorders_copy
    Set comappstat = (select distinct)
    a.comappstat
    mnt.workorders a, mnt.workorders_copy b
    where a.workordersoi = b.workordersoi
    and a.comappstat! = b.comappstat)
    where a.comappstat! = b.comappstat
    and a.workordersoi = b.workordersoi

    The subquery executed on its own returns a single value 9, which is the correct value of the column in the table of the prod, and I want to replace the incorrect a '12' (I've updated the copy to change the value of the column comappstat to 12 everywhere where it was 9) However when I run the query again I get this error :

    ERROR on line 8:
    ORA-00904: "B". "" WORKORDERSOI ": invalid identifier

    First of all, I don't see why the update statement does not work (it's probably obvious, but I'm not)

    Secondly, it is the best approach for updating a column (or columns) that are incorrect, with the columns in the same table which are correct, or is there a better way?

    I would sooner update the table rather than delete or truncate then re insert, as it was a trigger for insert/update I had to disable it on the notice re and truncate the table unusable a demand so I was re insert.

    Thank you

    Hello

    First of all, after post 79, you need to know how to format your code.

    Your last request reads as follows:

    UPDATE
      mnt.workorders_copy
    SET
      comappstat =
      (
        SELECT DISTINCT
          a.comappstat
        FROM
          mnt.workorders a
        , mnt.workorders_copy b
        WHERE
          a.workordersoi    = b.workordersoi
          AND a.comappstat != b.comappstat
      )
    WHERE
      a.comappstat      != b.comappstat
      AND a.workordersoi = b.workordersoi
    

    This will not work for several reasons:
    The sub query allows you to define a and b and outside the breakets you can't refer to a or b.
    There is no link between the mnt.workorders_copy and the the update and the request of void.

    If you do this you should have something like this:

    UPDATE
      mnt.workorders     A      -- THIS IS THE TABLE YOU WANT TO UPDATE
    SET
      A.comappstat =
      (
        SELECT
          B.comappstat
        FROM
          mnt.workorders_copy B   -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      )
    WHERE
      EXISTS
      (
        SELECT
          B.comappstat
        FROM
          mnt.workorders_copy B
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      )
    

    Speed is not so good that you run the query to sub for each row in mnt.workorders
    Note it is condition in where. You need other wise, you will update the unchanged to null values.

    I wouold do it like this:

    UPDATE
      (
        SELECT
          A.workordersoi
          ,A.comappstat
          ,B.comappstat           comappstat_OLD
    
        FROM
          mnt.workorders        A      -- THIS IS THE TABLE YOU WANT TO UPDATE
          ,mnt.workorders_copy  B      -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES
    
        WHERE
          a.workordersoi    = b.workordersoi      -- THIS MUST BE THE KEY
          AND a.comappstat != b.comappstat
      ) C
    
    SET
      C.comappstat = comappstat_OLD
    ;
    

    This way you can test the subquery first and know exectly what will be updated.
    This was not a sub query that is executed for each line preformance should be better.

    Kind regards

    Peter

  • How to find the name of the table where the paricular column is common to all the tables...

    Hi all

    any help please...

    I have a lot of tables in the diagram

    Select * from tab; show all tables...

    Now, there is a single table called has columns as name like this, dept, empno, joindate, sal...
    now the description column in table present in so many other tables in the schema above...

    How can I know the names of tables where this 'Description' column shows.

    Note: I use the 10 g version and I do not have DBA privilege on the diagram...

    Thanks in advance
    ASP.

    Are you logged in as owner of these tables? Otherwise (and it seems that you're not), you have privileges on these table? If you do, use:

    SELECT  OWNER,
            TABLE_NAME
      FROM  ALL_TAB_COLUMNS
      WHERE COLUMN_NAME = 'DESIGNATION'
    / 
    

    If you don't have privileges, but you can choose from DBA_TAB_COLUMNS, use:

    SELECT  OWNER,
            TABLE_NAME
      FROM  DBA_TAB_COLUMNS
      WHERE COLUMN_NAME = 'DESIGNATION'
    / 
    

    Otherwise ask your DBA to run it.

    SY.

  • Delete rows in a table when the columns from two tables match

    Hello

    I have following two tables.

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

    create the table empbooth as

    (

    Select 1 empid, 1 double cabin Union all the

    Select option 2, Union 1 double all the

    Select 3, Union 1 double all the

    Select option 4, Union 2 double all the

    Select option 5, 2 double

    );

    create the table attsht as

    (

    Select 1 empid, 240 reg, 0 unpaid all double union

    Select option 2, reg 200, 0 unpaid of all the double union

    Select 3, 240 reg, 0 unpaid all double them union

    Select 4 480 reg, 0 unpaid all double union

    Select 5 240 reg, unpaid double 0

    );

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

    I want to remove rows from attsht where corresponding booth (which is stored in the empbooth table) is 1.

    The condition is 'where attsht.empid = empbooth.empid and empbooth.booth = 1 '.

    I use oracle 10g.

    Help, please

    delete from attsht where a.empid in (select b.empid from empbooth b where b.booth = 1)

    or

    remove from attsht a

    where exists (select null

    of empbooth b

    where b.booth = 1

    and b.empid = a.empid)

Maybe you are looking for