Problems with the materialized view

Hello

I need help enforce data integrity using a materialized view. In my example, each system can consist of three types of components, and it is modeled using the supertype/subtype relationships. I'm trying to argue that, for a given system, a component cannot reside in more than one table of components. For example, given the system 1, if A component exists in the mobile_components table, it is impossible to insert into the table desktop_components for system 1. Rather than using triggers, I try to use views materialized with unique constraint to enforce this rule based on the example of "The trouble with triggers" article http://www.oracle.com/technetwork/issue-archive/2008/08-sep/o58asktom-101055.html of Tom Kyte. However, I can't seem to make it work because it gives me ORA-12054: cannot set the ON COMMIT refresh attribute.  I use UNION ALL and I know that can be difficult, but I can not understand what are the rules I'm breaking.  I have the necessary privileges.  Oracle 11g.  Can anyone help?

Thank you

Mark

create table systems (
sys_id number,
sys_name varchar2(100),
constraint sys_pk primary key (sys_id),
constraint sys_uk unique (sys_name));

insert into systems values (1,'System 1');
insert into systems values (2,'System 2');


create table mobile_components (
mo_comp_id number,
mo_comp_name varchar2(100),
mo_comp_sys_id number,
constraint mo_pk primary key (mo_comp_id),
constraint mo_uk unique (mo_comp_name, mo_comp_sys_id),
constraint mo_fk foreign key (mo_comp_sys_id) references systems (sys_id));

insert into mobile_components values (1,'Component A',1);
insert into mobile_components values (2,'Component A',2);


create table desktop_components (
de_comp_id number,
de_comp_name varchar2(100),
de_comp_sys_id number,
constraint de_pk primary key (de_comp_id),
constraint de_uk unique (de_comp_name, de_comp_sys_id),
constraint de_fk foreign key (de_comp_sys_id) references systems (sys_id));

insert into desktop_components values (1,'Component B',1);
insert into desktop_components values (2,'Component B',2);


create table internet_components (
in_comp_id number,
in_comp_name varchar2(100),
in_comp_sys_id number,
constraint in_pk primary key (in_comp_id),
constraint in_uk unique (in_comp_name, in_comp_sys_id),
constraint in_fk foreign key (in_comp_sys_id_ references systems (sys_id));

insert into internet_components values (1,'Component C',1);
insert into internet_components values (2,'Component C',2);


create materialized view log on mobile_components with rowid;
create materialized view log on desktop_components with rowid;
create materialized view log on internet_components with rowid;


create materialized view mv_components
refresh fast on commit with rowid as
select rowid as row_id, mo_comp_id as comp_id, mo_comp_name as comp_name
from mobile_components
union all
select rowid, de_comp_id, de_comp_name
from desktop_components
union all
select rowid, in_comp_id, in_comp_name
from internet_components;

alter table mv_components add constraint mv_comp_uk unique (comp_id, comp_name);


You need a column marker to distinguish which questions you Union, that the data are:

for example

Create materialized view mv_components

cool off quickly on commit with rowid as

Select 'a' marker, rowid as row_id, mo_comp_id as identifiant_composant mo_comp_name as comp_name

of mobile_components

Union of all the

Select 'b', rowid, de_comp_id, de_comp_name

of desktop_components

Union of all the

Select 'c', rowid, in_comp_id, in_comp_name

of internet_components;

Tags: Database

Similar Questions

  • Problem with the materialized view (ORA-02345)

    Hello

    I am trying to create a view materialized, based on the following function:

    CREATE OR REPLACE function RBS_USER.dynamic_pivot return sys_refcursor
    as
    sql_query varchar2(8000);
    p_cursor sys_refcursor;
    
    
    begin
        for x in (select distinct report_mm from UC_SOURCE_CUR_ACCT_CLASSIF order by 1)
        loop
            sql_query := sql_query || '''' || x.report_mm || ''' as "' || to_char(x.report_mm,'mm/dd/yyyy') || '", ';
        end loop;
    
    
        sql_query := 'select * from (
           select UC_BUSINESS_TYPE, PRODUCT_PORTFOLIO, REVENUE, REPORT_MM FROM UC_SOURCE_CUR_ACCT_CLASSIF
        )
        pivot
        (
           sum(revenue)
           for report_mm in (' || substr(sql_query,1,length(sql_query)-2) || '))';
    
    
        open p_cursor for sql_query;
        return p_cursor;
    end;
    
    

    I'm getting ORA-02345: cannot create a view with column based on CURSOR operator.

    How can I re - write the code in order to to use to generate a materialized view?

    Perhaps using a PIPELINED function? But the problem is that I don't know beforehand the return type that it can vary (based on a range of months in the UC_SOURCE_CUR_ACCT_CLASSIF table, which does not.

    Thank you

    M.R.

    I'm getting ORA-02345: cannot create a view with column based on CURSOR operator.

    How can I re - write the code in order to to use to generate a materialized view?

    You can't - a slider is PL/SQL, SQL not and has all the data.

    Perhaps using a PIPELINED function? But the problem is that I don't know beforehand the return type that it can vary (based on a range of months in the UC_SOURCE_CUR_ACCT_CLASSIF table, which does not.

    Then explain how a materialized view THAT REFRESH could possibly work if the return type could change after the MV was last refreshed?

    You should base a MV on real data such as returned by a SQL query.

  • Problem with the materialized view

    Hello

    I encountered a problem...

    I have a materialized view which I update via a button in my application. I used the following code to do this:
    DBMS_REFRESH. Refresh (the "SCHEME".) "MY_MV" ');

    As you can see the pattern, I have included in the appeal, and which worked fine until now.

    We have now 2 apps. in the same PB. Its actually the same app... Only for the development and the other for testing. The app development uses a different schema and this effect cannot use the call above, it seems.

    I offcause want to ommit using the schema in the call, because otherwise I would have to change every time I move to App Development to test the app. But when I ommit it I get the following error:

    ORA-23404: refresh, group "APEX_PUBLIC_USER". "' MY_MV ' does not exist

    How to solve this?

    And another thing... My selection around the application does not use the scheme, then how does apex know what sound scheme when his choice, but he does not know when its doing a dbms_refresh?

    Hope someone is smarter than me :)

    Bjarke

    Hello
    Try this way

    declare
    my_schema varchar2(10);
    begin
    select owner into my_schema from apex_applications where application_id=:APP_ID;
    dbms_refresh.refresh( my_schema || '.'|| 'MY_MV');
    end;
    

    CITY

  • Problem with the host view

    Hi all.

    I have a problem with the display of my physical host information. I installed FglAM on the server, deploy the cartridge of the OS, create agent. But when I access the dashboard of the hosts, I see that my host currently does not monitor.

    Agent log is good (logfile to join). I see same alarm of this host, but no performance and other information.

    Thank you

    Nikolai, I recommend that you should open a case of pension for later analysis.

    David Mendoza

  • Problem with the HD view import

    Importing videos that I made, first seems to like changing my sky or any background that is not physically there in an alpha, making my transparent background. When I play it in media player or quicktime, it doesn't do this, my heaven is there. I assumed it would be a problem with the click of a simple framework, but as you can see, the button should be far away because I'm on this forum before I find it. When I visited my avi in everything except HD, first does not. What is the problem?

    Ive been told that its because of my composition in lightwave that makes first to do this, but, shouldn't this just be a simple framework, I can't disable?

    The option ignore Alpha is in the dialog box interpret the film.

    I found that with this research.

  • Problem with the design view in Dreamweaver CS5

    Hi all

    I'm having a problem with my creation mode on a page I created in Dreamweaver CS5.

    The files can be found here as well as a jpeg file showing the issue I'm having.

    http://www.siltd.co.UK/PRB/

    Everything was fine until I added the three classes:

    {.crproductsrightpanelheading}

    Width: 186px;

    top of the margin: 25px;

    background-image: url (.. / images/crproductsrightpanelheadingbg.jpg);

    background-repeat: no-repeat;

    background-position: left;

    padding-left: 28px;

    do-family: Arial, Helvetica, without serif.

    color: #FFF;

    do-size: 14px;

    line-height: 27px;

    float: left;

    Clear: right;

    }

    {.crproductsrightpanellist}

    Width: 199px;

    top of the margin: 5px;

    padding-left: 5px;

    float: left;

    overflow: auto;

    }

    .crproductsrightpanellist li {}

    do-family: Arial, Helvetica, without serif.

    color: #FFF;

    do-size: 12px;

    list-style-image: url (.. / images/crdash.jpg);

    line-height: 18px;

    list-style-position: inside;

    }

    Now, I can hardly see what is happening.

    It's good in Live View mode and also when published, but design view is like having a steering wheel towards the bottom of my pants... It's driving me crazy!

    What it looks like when published can be seen here:

    http://www.siltd.co.UK/new%20SI%20Site/crproducts.html

    Any help telling me where I went so wrong would be appreciated.

    Thanks in advance.

    Andy

    Run your pages through this validator and clean up any errors...

    http://validator.w3.org/

    For now, you have a large number of errors that need to be addressed, about 90 altogether.

    While some browsers allow to better interpereting what you wanted to do than others (IE being the absolute worst), DW is a maniac, especially in Design view. It is still displayed incorrectly in DW after you fix all the problems, after return and we can take a closer look.

  • Problem with the 360 Viewer

    Hello

    I just downloaded the trial version of Indesign CS5.5 since I wanted to try the overlay creator feature. What I read online, 360 views can be created using the creator of overlay. Now, here's where the problem is. I don't see an option to create a 360 views inside. I can Hyperlink, slide show, image sequence, etc. but no 360 Viewer.

    Everyone knows about this problem as well?

    Help, please.

    Thank you.

    360 has been changed to the image sequence, given that most of the people he used to more than 360 in any case. It's only a name change.

    Bob

  • Problems with the Windows on Windows 7 Photo Viewer, cannot open the picture

    Good evening!

    I can't open a few photos that I downloaded from my digital camera's SD card.  They are all in the same folder, and they are all JPEG.  Some of them are open very well, but there are MANY who are not open and I get the message: 'Windows Photo Viewer cannot open this photo because Photo Viewer does not support this file format, or you do not have the latest updates for Photo Viewer. "  As I said, they are all JPEG, as well as the Windows Photo Viewer is already set as my default Photo Viewer.   When I opened the window of the picture viewer I have not been invited for updates.

    I don't understand why some of my photos to shoot to the top of fine and the rest don't pull up at all.   Where will ensure that I have the latest update?  You have any other suggestions?

    Thank you in advance for your help!

    Looks like there are probably good copies elsewhere then... I was worried, you might well have lost some of your photos, and it is always better to access the card and copy and paste the files (and then check that they are ok) before using the software download and the removal from the Board. If the files have been corrupted somehow during the transfer process, they can still be recoverable in respect of the SD card using something like the free version of "recuva" providing that the SD card has not been re-used and previous files overwritten by new material. However, if your sister still photos as well which should not be necessary.

    I don't think this is likely to be a problem with the photo viewer, but let us know when you received that email... all the best - Ric.

  • Problem with the shortage of pilots on Pavilion G6-2260su

    Hello

    I have some serious frustration due to problems with the material of this thing.

    I istalled windows 7 64 bit Ultimate edition with service pack 1

    However, much of the material is not recognized - in particular the NIC / wireless.

    I downloaded all the drivers/software from the hp support page but the following materials are still uninstalled:

    Bluetooth controller

    Ethernet controller

    Network controller

    PCI device

    SM Bus controller

    2 Bus USB controllers

    Unknown device

    When I try to install the driver for wireless network / on site he is saying that the material is not pluged and it closes.

    Help, please!

    Hello:

    You must install the driver for chipset on the link below. Download of Frist will take care of most of these devices.

    http://support.AMD.com/us/gpudownload/Windows/pages/raid_windows.aspx#2

    Video:

    http://h20000.www2.HP.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=us&swItem=ob-105905-1&mode=4&IDX=1&prodTypeId=321957&prodSeriesId=3688868

    Audio:

    http://h20000.www2.hp.com/bizsupport/TechSupport/SoftwareDescription.jsp?lang=en&cc=us&prodTypeId=321957&prodSeriesId=5212912&prodNameId=5212913&swEnvOID=4059&swLang=13&mode=2&taskId=135&swItem=ob-110838-1

    Ethernet:

    Download and install the 6th on the list.

    http://www.Realtek.com.tw/downloads/downloadsView.aspx?langid=1&PNid=14&PFID=7&level=5&Conn=4&DownTy...

    Card reader:

    http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?softwareitem=ob-102008-1&cc=us&DLC=en&LC=en&OS=4063&product=5199538&sw_lang

    Unknown is probably the following:

    http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?softwareitem=ob-82853-1&cc=us&DLC=en&LC=en

    For other devices, I need material ID to find the correct drivers.

    Please post them.

    If you don't know how to find the hardware ID, please read the info on the link below for advice.

    http://www.DeviceDriverFinder.com/blog/device-drivers/how-to-check-the-hardware-ID-for-a-Windows-device

    Paul

  • Error: "Canoe Photo window Viewer save the changes to this picture because there is a problem with the property of photo file" when trying to upload photos from the iPhone to the Windows Photo Viewer.

    Original title: saving photos and videos, common sense?

    JW why I can't save a picture to the top of the right way in my windows photo viewer and Media Player (same for video too) so when I download my pictures frim my iphone on the computer a few photos have been taken vertically, and when I go to put the image a gardener would come saying ' canoe photo window Viewer save the changes to this picture because there is a problem with the file of. properties of photos? What can I do to fix this?

    JW why I can't save a picture to the top of the right way in my windows photo viewer and Media Player (same for video too) so when I download my pictures frim my iphone on the computer a few photos have been taken vertically, and when I go to put the image a gardener would come saying ' canoe photo window Viewer save the changes to this picture because there is a problem with the file of. properties of photos? What can I do to fix this?

    =============================================
    I don't know if the following links answer your question, but
    they may be worth a visit:

    Good luck and * proceed at your own risk *.

    FWIW... There is a very long discussion (several pages) to the
    following link:

    Cannot change the imported iPhone 4S photo
    https://discussions.Apple.com/thread/3444951?start=0&TSTART=0

    More Discussion

    iPhone 4S image properties is not compartible with Windows?
    Editing can be done on the computer due to the error
    "Windows Photo Viewer cannot save changes to this picture.
    because there is a problem with the properties of the image file".
    Any help?
    https://discussions.Apple.com/message/17291884#17291884

    More Discussion:

    We cannot turn a few photos in Windows 7 (but can turn others)
    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-pictures/cant-rotate-some-photos-in-Windows-7-but-can/3a809845-9144-4BB1-9bb3-ab4f5b856524

    A simple solution is to open the photos in paint or most other
    digital image editor and modify it.

    Some people have reported success using the following free download
    to remove the metadata.

    Property restrictions stripper iphone 4S (JPEG & PNG Stripper)
    http://www.SteelBytes.com/?mid=30&cmd=download&PID=15

    Here's a way to turn...

    Easily turn locked iPhone 4 and 4 s Photos in Windows 7 with
    the rotator Lossless JPEG free
    http://www.daleisphere.com/easily-rotate-locked-iPhone-4-and-4S-photos-in-Windows-7-with-the-free-JPEG-lossless-Rotator/

    Free download JPEG Lossless rotating
    http://annystudio.com/software/jpeglosslessrotator/

  • Problems with the servers from Adobe in Germany (Workflow: InDesign-> Content Viewer)

    We had some problems with the download of our fact sheets on Adobe servers end of January / beginning of February. Also our iPads test often could not connect to the content viewer. There are outages of server in Germany during this period?

    Updates are always displayed at http://status.adobedps.com/. You can check messages to see if all coincides with when you download problems.

    Neil

  • error message 'there is a problem with the printer turn the printer off even more'

    I have a new 7525 HP photosmart HP printer, if it can find all the flashing lights with an error message on the screen "is there a problem with the printer. Turn the printer off on new"this does not solve the problem... Can't clear this error message!  Cannot use this printer!

    Hi sandrafranks,

    Thank you for your answer!

    In my view, it is unwanted material. Please contact our technical support at the 800-474-6836. If you do not live in the United States / Canada region, please click the link below to get help from your region number. Language-country selector.

    Hope this helps and have a great day!

  • Trigger on the materialized view

    Hello

    I have the scenario based (Database 11 g):

    There is a view materialized (PERSON), which contains the ID and NAME fields. This MV is update daily with a fast refresh.

    I have a second array (NAMES), with ID and NORM_NAME. This table contains the name of the person, without special characters.

    For example, for recording / * 1 BJORN * / in the PERSON table

    I would check * 1 BJORN * / in table NAMES.


    Problem is how to fill the NAME table after the filling of the materialized view.

    I used a trigger AFTER INSERT or update, as described below, but even if I update the master table (for this purpose, update the MV), I have only to trigger inserts.


    Is there a way to implement a trigger "after update" on a materialized view, or do I need another approach?


    /*


    create or replace TRIGGER TRG_TESTE_MV

    AFTER INSERT OR UPDATE ON THE PERSON

    REFERENCING OLD AS OLD AGAIN AS NEW

    FOR EACH LINE

    BEGIN

    IF THE INSERTION

    INSERT THE NAMES

    VALUES

    (: NEW.id,:NEW.NAME);

    END IF;

    IF THE UPDATE CAN

    UPDATE OF NAMES

    SET NAME =: NEW.NAME WHERE ID =: NEW.id;

    END IF;

    END;

    */

    Thanks for any help

    Your trigger fires, but I doubted that you will be satisfied with the results. You really need to understand how to refresh process works before you begin creating triggers of MV:

    SQL > create table emp1 in select * from EMP
    2.

    Table created.

    SQL > create materialized view emp1 with rowid journal
    2.

    Materialized view log that is created.

    SQL > create materialized view emp1_mv
    2 fast refresh
    3 on request
    4 with rowid
    5 as
    6 select * from emp1
    7.

    Materialized view created.

    SQL > create or replace
    trigger 2 emp1_mv_biudr
    3 before inserting
    4 or update
    5 or delete
    6 on emp1_mv
    7 for each line
    Start 8
    9 insert then dbms_output.put_line ('INSERT' |: new.ename); end if;
    10 if the deletion then dbms_output.put_line ('REMOVE' |: old.ename); end if;
    11 end;
    12.

    Trigger created.

    SQL > insert
    2 in emp1 (empno, ename, sal)
    3 values(1,'X',1000)
    4.

    1 line of creation.

    SQL > validation
    2.

    Validation complete.

    SQL > set serveroutput on
    SQL > exec dbms_mview.refresh ('emp1_mv', 'f');
    INSERTION OF X

    PL/SQL procedure successfully completed.

    SQL > update emp1
    2 set sal = sal + 1
    3 where ename ('King', 'JONES')
    4.

    2 lines to date.

    SQL > validation
    2.

    Validation complete.

    SQL > set serveroutput on
    SQL > exec dbms_mview.refresh ('emp1_mv', 'f');
    INSERTION OF JONES
    INSERTION OF KING

    PL/SQL procedure successfully completed.

    SQL > delete emp1
    2 where in ename ('ALLEN', 'SMITH')
    3.

    2 deleted rows.

    SQL > validation
    2.

    Validation complete.

    SQL > set serveroutput on
    SQL > exec dbms_mview.refresh ('emp1_mv', 'f');

    PL/SQL procedure successfully completed.

    SQL >

    As you can see, refresh MV updates ever. Results update underlying table to remove/insert in MV. That's why your trigger will not give the results that you expected.

    SY.

  • I get "failed to set the refresh attribute COMMIT for the materialized view" when I try to create a MV using a table and another MV

    Experts,

    I'm trying to create a YOUNG refreshable ON COMMIT MV (xyz) using a table (circuit) and quickly updateable on validation MV (abc), but get an error:

    SQL error: ORA-12054: cannot set the attribute ON COMMIT refresh for the materialized view

    12054 00000 - "cannot set the refresh attribute COMMIT for the materialized view.

    * Cause: The materialized view did not meet the requirements for update to

    moment of validation.

    * Action: Specify only valid options.

    1] MV abc
    = MV abc defined as below =.

    CREATE MATERIALIZED view abc_MV

    Immediate CONSTRUCTION

    REFRESH QUICKLY YOU COMMIT using constraints of trust

    WITH ROWID AS SELECT n.*,.

    n.ROWID noderowid

    node n

    where n.nodetype in (1610000069,1610007267);


    -Above works OK and MV connect you on table node is created successfully

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

    [ 2] Circuit Board

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

    CREATE MATERIALIZED VIEW LOG ON Cramer.Circuit WITH SEQUENCE, ROWID ( ) -all columns of table ofcircut parentheses

    INCLUDING THE NEW VALUES;

    -More top works OK and MV connect you on table circuit is created successfully

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



    [3] trying to create MV xyz

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

    CREATE MATERIALIZED VIEW LOG ON cramer.abc_MV WITH SEQUENCE, ROWID ( ) -all columns of abc_MV brackets

    INCLUDING THE NEW VALUES;

    -Above works OK and log on ABC MV MV gets created successfully

    -Problematic step below

    Xyz_MV CREATE MATERIALIZED VIEW

    IMMEDIATE CONSTRUCTION

    REFRESH QUICKLY YOU COMMIT using constraints of trust

    AS

    SELECT c., c.rowid circuit_rowid, n.rowid tr_rowid

    the circuit c, abc_mv n

    where circuit2startnode = n.nodeid

    and c.rpplanId = n.rpplanId;
    ==========================================================

    Clues on how to solve this problem and make quickly updatable ON Commit MV xyz

    Thanks in advance.

    Chanchal,

    If you can read my original post carefully you may have noticed that all these restrictions will not apply in my case.

    All,

    In any case I found the solution to my problem.

    There are a few additional restrictions for materialized views multilayer

    Additional Restrictions for master materialized views

    The following types of materialized views may not be masters of editable materialized views:

    • ROWIDmaterialized views
    • Complex materialized views
    • Read-only materialized views

    I've updated the underlying MV abc below and everything worked like a charm

    CREATE MATERIALIZED view abc_MV

    Immediate CONSTRUCTION

    REFRESH QUICKLY YOU COMMIT using constraints of trust

    IN SELECT

    n.*, n.rowid noderowid, nt.rowid nodetyperowid

    the node n, nodetype_m nt

    where n.node2nodetype = nt.nodetypeid

    and nt.nodetypeid in (1610000069,1610007267);

    Note: To ADD a join without which I was getting error below (although had primary key on the table of the node)

    SQL error: ORA-23415: materialized view log for "NODE" does not save the primary key

    23415 00000 - "view the log for materialized \"%s\".\"%s\"does not save the primary key.

    * Cause: A primary key materialized view is refreshed quickly, but the

    The materialized view log does not record the primary key information.

    * Action: Use CREATING MATERIALIZED VIEW LOG... Command to add a PRIMARY KEY to

    start recording of the primary key information in the materialized view

    Newspaper.

  • problem with the making of reference levels

    Hello!

    I have a problem with taking the basic lines - when the SQL is called from PL/SQL code...

    For example if I run in the SQL session * more

    ALTER session set optimizer_capture_sql_plan_baselines = true;

    exec dbms_mview.refresh ("VIEW_CLIENT_KONTO", "C");
    ...
    exec dbms_mview.refresh ("VIEW_CLIENT_KONTO", "C");


    nothing happens... I can't find the base line in dba_sql_plan_baselines...
    ========================================================

    optimizer_use_sql_plan_baselines = TRUE... of course and I can capture some baselines for SQL plain-not only if SQL is called from PL/SQL...

    Now, nowhere in documentation I could find that capture does not PL/SQL... in my opinion, would disadvantage-code so sderious in the database runs as PL/SQL...

    We habe Oracle Enterprise Edition 11.2.0.3

    optimizer_features_enable = 11.2.0.3

    What could be worng here... I forgot some settings or configuration. Thank you for your help in advance.

    Now, nowhere in the documentation I could find that capture does not PL/SQL... it would be, in my opinion.
    be sderious drawback-code so the database runs as PL/SQL...

    You're quite right. It would be a serious disadvantage.
    But it is not true that they are not captured in PLSQL.

    Installation program:

    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> select name, value from v$parameter where name like '%baseline%';
    
    NAME                                               VALUE
    -------------------------------------------------- ------------------------------
    optimizer_capture_sql_plan_baselines               FALSE
    optimizer_use_sql_plan_baselines                   TRUE
    
    SQL> create table t1
      2  (col1 number);
    
    Table created.
    
    SQL> INSERT /*+ domtest sql */ INTO t1 select 1 from dual;
    
    1 row created.
    
    SQL> begin
      2  INSERT /*+ domtest plsql */ INTO t1 select 1 from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id, substr(sql_text,1,30) sql_text, child_number c, to_char(force_matching_signature
    ) sig, sql_plan_baseline
      2  from   v$sql
      3  where  sql_text like 'INSERT /*+ domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    gmskus7sbgt5d INSERT /*+ domtest plsql */ IN          0 7407988653257810022
    64rzqgrt63wzu INSERT /*+ domtest sql */ INTO          0 17374141102446297863
    
    SQL> select to_char(b.signature) sig, b.created
      2  from   v$sql s
      3  ,      dba_sql_plan_baselines b
      4  where  s.sql_text like 'INSERT /*+ domtest%'
      5  and    b.signature = s.force_matching_signature;
    
    no rows selected
    
    SQL> alter session set optimizer_capture_sql_plan_baselines = true;
    
    Session altered.
    
    SQL> 
    

    Database created for the SQL statement:

    SQL> INSERT /*+ domtest sql */ INTO t1 select 1 from dual;
    
    1 row created.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,30) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT /*+ domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    gmskus7sbgt5d INSERT /*+ domtest plsql */ IN          0 7407988653257810022
    64rzqgrt63wzu INSERT /*+ domtest sql */ INTO          0 17374141102446297863
    64rzqgrt63wzu INSERT /*+ domtest sql */ INTO          1 17374141102446297863           SQL_PLAN_1ayk9a0wnr
    
    SQL> 
    

    Database created for PLSQL statement:

    SQL> begin
      2  INSERT /*+ domtest plsql */ INTO t1 select 1 from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,30) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT /*+ domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    gmskus7sbgt5d INSERT /*+ domtest plsql */ IN          0 7407988653257810022
    gmskus7sbgt5d INSERT /*+ domtest plsql */ IN          1 7407988653257810022            SQL_PLAN_5s3v02k7yx9
    64rzqgrt63wzu INSERT /*+ domtest sql */ INTO          0 17374141102446297863
    64rzqgrt63wzu INSERT /*+ domtest sql */ INTO          1 17374141102446297863           SQL_PLAN_1ayk9a0wnr
    
    SQL> 
    

    Cleaning guidelines:

    SQL> declare
      2   l_spm_op pls_integer;
      3  begin
      4   for x in (select sql_handle from dba_sql_plan_baselines b where created >= trunc(sysdate))
      5   loop
      6       l_spm_op :=
      7       dbms_spm.drop_sql_plan_baseline(x.sql_handle);
      8   end loop;
      9  end;
     10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    So I expect that this is related to the DBMS_MVIEW and a restriction on recursive, internal instructions.

    For example, if you capture base plan sql lines you don't capture baselines for sys and system statements, etc.

    Further investigation required.

    For example, we will build a MV:

    SQL> create materialized view mv1
      2  build immediate
      3  refresh on demand
      4  as
      5  select /*+ domtest mv */ col1 from t1;
    
    Materialized view created.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    We see two statements of the initial creation of the MV and the subsequent update (the latter is the one with the BYPASS_RECURSIVE_CHECK trick).

    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT %domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    ctyufr5b5yzfm INSERT INTO "RIMS"."MV1" selec          0 12798978218302414227
                  t /*+ domtest mv */
    
    gfa550uufmr34 INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872
                  ECK */ INTO "RIMS"."
    
    SQL> 
    

    Even if we repeat the update, we do not need to obtain a reference level:

    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT %domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    ctyufr5b5yzfm INSERT INTO "RIMS"."MV1" selec          0 12798978218302414227
                  t /*+ domtest mv */
    
    gfa550uufmr34 INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872
                  ECK */ INTO "RIMS"."
    
    SQL> 
    

    So... maybe BYPASS_RECURSIVE_CHECK have nothing to do with it?

    It is not likely to be relevant, but maybe we should just check?

    Let's see what happens if we return to our original plsql statement because we cannot insert a MV directly.

    SQL> begin
      2   INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO t1 select 1 from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  --,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT /*+ BYPASS_RECURSIVE_CHECK */%';
    
    SQL_ID        SQL_TEXT                                                    C SQL_PLAN_BASELINE
    ------------- -------------------------------------------------- ---------- ------------------------
    6kjvr1gu6v2pq INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO T1 SELEC          0
    
    SQL> begin
      2   INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO t1 select 1 from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  --,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT /*+ BYPASS_RECURSIVE_CHECK */%';
    
    SQL_ID        SQL_TEXT                                                    C SQL_PLAN_BASELINE
    ------------- -------------------------------------------------- ---------- ------------------------
    6kjvr1gu6v2pq INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO T1 SELEC          0
    
    SQL> begin
      2   INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO t1 select 1 from dual;
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  --,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  from   v$sql
      7  where  sql_text like 'INSERT /*+ BYPASS_RECURSIVE_CHECK */%';
    
    SQL_ID        SQL_TEXT                                                    C SQL_PLAN_BASELINE
    ------------- -------------------------------------------------- ---------- ------------------------
    6kjvr1gu6v2pq INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO T1 SELEC          0
    6kjvr1gu6v2pq INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO T1 SELEC          1 SQL_PLAN_aq62u7rqdfcs8125daea2
    
    SQL> 
    

    Yes, nothing to do with it.

    I would say it is because running via DBMS_MVIEW, he is special and bypasses the review of basic data.

    We can somehow get around this?
    Perhaps, the basic lines of being a flexible vehicle that work off SIGNATURE (and PLAN_HASH_2).

    We will check the hash of the signature and the plan must reproduce.

    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  ,      plan_hash_value
      7  from   v$sql
      8  where  sql_text like 'INSERT %domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    PLAN_HASH_VALUE
    ---------------
    ctyufr5b5yzfm INSERT INTO "RIMS"."MV1" selec          0 12798978218302414227
                  t /*+ domtest mv */
         3617692013
    
    gfa550uufmr34 INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872
                  ECK */ INTO "RIMS"."
         3617692013
    
    SQL> 
    

    And replace the materialized by a table view:

    SQL> drop materialized view mv1;
    
    Materialized view dropped.
    
    SQL> create table mv1
      2  (col1 number);
    
    Table created.
    
    SQL> 
    

    And try to get a statement with the same signature and plan that uses a reference database:

    SQL> begin
      2   INSERT /*+ BYPASS_RECURSIVE_CHECK */ INTO "RIMS"."MV1" select /*+ domtest mv */ col1 from t1 ;
    
      3  end;
      4  /
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  ,      plan_hash_value
      7  from   v$sql
      8  where  sql_text like 'INSERT %domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    PLAN_HASH_VALUE
    ---------------
    ctyufr5b5yzfm INSERT INTO "RIMS"."MV1" selec          0 12798978218302414227
                  t /*+ domtest mv */
         3617692013
    
    5n6auhnqpb258 INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872           SQL_PLAN_b6tnbps6tn
                  ECK */ INTO "RIMS".
         3617692013
    
    gfa550uufmr34 INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872
                  ECK */ INTO "RIMS"."
         3617692013
    
    SQL> 
    

    Now, if we remove and recreate the materialized view:

    SQL> create materialized view mv1
      2  build immediate
      3  refresh on demand
      4  as
      5  select /*+ domtest mv */ col1 from t1;
    
    Materialized view created.
    
    SQL> exec dbms_mview.refresh('MV1');
    
    PL/SQL procedure successfully completed.
    
    SQL> select sql_id
      2  ,      substr(sql_text,1,50) sql_text
      3  ,      child_number c
      4  ,      to_char(force_matching_signature) sig
      5  ,      sql_plan_baseline
      6  ,      plan_hash_value
      7  from   v$sql
      8  where  sql_text like 'INSERT %domtest%';
    
    SQL_ID        SQL_TEXT                                C SIG                            SQL_PLAN_BASELINE
    ------------- ------------------------------ ---------- ------------------------------ -------------
    PLAN_HASH_VALUE
    ---------------
    dac4d22mf0m6k INSERT INTO "RIMS"."MV1" selec          0 12798978218302414227
                  t /*+ domtest mv */
         3617692013
    
    cn4syqz9cxp3y INSERT /*+ BYPASS_RECURSIVE_CH          0 12927173360082366872           SQL_PLAN_b6tnbps6tn
                  ECK */ INTO "RIMS"."
         3617692013
    
    SQL> 
    

    And cleaning:

    SQL> drop table t1;
    
    Table dropped.
    
    SQL> drop materialized view mv1;
    
    Materialized view dropped.
    
    SQL> declare
      2   l_spm_op pls_integer;
      3  begin
      4   for x in (select sql_handle from dba_sql_plan_baselines b where created >= trunc(sysdate))
      5   loop
      6       l_spm_op :=
      7       dbms_spm.drop_sql_plan_baseline(x.sql_handle);
      8   end loop;
      9  end;
     10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Then...
    Baselines are created for the sql statements executed in PLSQL? Yes.
    Baselines are created for internal instructions of DBMS_MVIEW? N °
    Why? Don't know. But I think that this is the expected behavior.
    Is there a convoluted way to apply a basic strategy to the internal refresh statement? Yes.

Maybe you are looking for

  • How can I get rid of static noise on my 1.4 LifeChat

    I just bought and loaded my LifeChat 1.4 and the first five minutes were great... now, however, I get static noises.  What should I do to fix this?  I tried the volume reduction, plug it into another USB port and unroll the cord.  Don't know why its

  • are there any hard drive for the envy 15 3040

    I got ' a disk read error occurred "black screen. So I decided to replace my damaged disk.To do this, I'm looking for hard drive for my notebook. But no information for this on google.So I ask you what is the best drive for my solution? My hard drive

  • Beach file ALX parameter [)]

    Hello I have a file ALX for work with the following line ver_42 I think I understand, looking at the sample in the guide of development, is that this translates any device that is > = version 4.2.0 and IE say 4.2.0 thru 4.5.999 must use the code that

  • still problems with palm tx

    I'm really tired of this palm tx. I did a hard reset like 6 times. I even created a new user on this subject and has deleted all the programs and data from the old user. I even took the security lock. It turns on and everything but it never turns on

  • CC is separated just LR?

    I bought a new computer and cannot find a way to put my apps on it. no disk drive. also, do I need to move MY LR to another computer or LR folders simply download from the adobe site?confused