Update of a Base Table in a view with a UNPIVOT function.

Hello
I have a requirement to upgrade a Base Table in a view.
This view has the query by using a function of the UNPIVOT operator to display the columns in the tables of the basic of the lines.
I need to update/insert in / remove the Base Table by accessing the view (the user has access to the Base Table, so the DML on the view).

Here is the table I created:-
CREATE TABLE PERSON_DETAILS
(
  PID            VARCHAR2(10 BYTE),
  FIRSTNAME      VARCHAR2(1000 BYTE),
  LASTNAME       VARCHAR2(1000 BYTE),
  PHONENUMBER    VARCHAR2(1000 BYTE),
  ADDRESS1       VARCHAR2(1000 BYTE),
  ADDRESS2       VARCHAR2(1000 BYTE),
  COUNTRY_CODE   VARCHAR2(1000 BYTE),
  LANGUAGE_CODE  VARCHAR2(1000 BYTE),
  EMAIL          VARCHAR2(1000 BYTE)
)
The sample values are inserted in this table using the script below: -.
insert into person_details values ('1','XYZ','ABC','1234567890','India','Asia','IN','EN','[email protected]');
insert into person_details values ('2','XYZ2','ABC2','1234567890','India','Asia','IN','EN','[email protected]');
The code for the display is as below: -.
CREATE OR REPLACE FORCE VIEW PERSON_DETAILS_VIEW
(
   PID,
   CD_NAME,
   CD_VALUE
)
AS
   SELECT "PID", "CD_NAME", "CD_VALUE"
     FROM person_details UNPIVOT INCLUDE NULLS (cd_value
                         FOR cd_name
                         IN  (firstname AS 'First Name',
                             lastname AS 'Last Name',
                             phonenumber AS 'Phonenumber',
                             address1 AS 'address1',
                             address2 AS 'address2',
                             country_code AS 'Country Code',
                             language_code AS 'Language Code',
                             email AS 'Email') );
Here are the values of the view:-
PID CD_NAME         CD_VALUE
1    First Name       XYZ
1    Last Name       ABC
1    Phonenumber  1234567890 
1    address1         India
1    address2         Asia
1    Country Code   IN
1    Language Code EN
1    Email               [email protected]
2    First Name       XYZ2
2    Last Name       ABC2
2    Phonenumber  1234567890
2    address1         India
2    address2         Asia  
2    Country Code   IN
2    Language Code EN
2    Email               [email protected]
The user would fire any statement as below: -.
update person_details_view 
set cd_value = 'US' where CD_NAME = 'IN'
The statement above should update the PERSON_DETAILS database table.

I understand that I can write an INSTEAD OF trigger, but I don't know what logic to write in the trigger so that the condition is met.

My Version of Oracle
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE    11.1.0.7.0    Production
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
Any help would be much appreciated.

Thank you
Ankit Khare.

Published by: Ankit_Khare84 on June 28, 2012 14:47

It is definitely possible with an INSTEAD of trigger.

for example:

create or replace
TRIGGER ioft_person
INSTEAD OF UPDATE
ON person_details_view
FOR EACH ROW
declare
firstname1  person_details.firstname%type;
BEGIN

              SELECT firstname_new into firstname1
              FROM   (SELECT pid, cd_name, cd_value
                      FROM   

                          (
                              select * from person_details_view where (pid, cd_name) not in (select :new.pid, :new.cd_name from dual)
                              union all
                              select :new.pid, :new.cd_name, :new.cd_value from dual
                          )

                      )
              PIVOT  ( max(cd_value) AS new FOR (cd_name) IN
                                                      ('First Name' AS firstname,
                                                        'Last Name' as lastname,
                                                        'Phonenumber' as phonenumber,
                                                        'address1' as address1,
                                                        'address2' AS address2,
                                                        'Country Code' as country_code,
                                                        'Language Code' as language_code,
                                                        'Email' as email
                                                        )
              )  where pid = :old.pid;

  UPDATE person_details
  SET firstname = firstname1
  WHERE pid = :old.pid;
END ioft_role_perm;

and that run

update person_details_view
set cd_value = 'X|X' where cd_name = 'First Name' and pid=1

The logic is: you need to convert back the view through swivel

Tags: Database

Similar Questions

  • reason for updating a view rather than on the base table

    Can someone tell me what is the reasons that sometimes we would update a view rather than on the base table? I always thought that we cannot update a view, of course, I am wrong. Thank you

    Hi Welcome to the Forum

    Basically, a view is used to present the data, a different way. He can rely on more than one table and we cannot update a
    Discover directly that contains Sql functions, aggregate functions, a group of Clause and a view created excluding the required columns of the table.

    In all the cases mentioned Instead of trigger is very useful

    Published by: user10862473 on July 28, 2009 07:10

  • Create a trigger instead of update several tables in a view

    Dear everybody

    I am trying to create a trigger that updates instead of to day joined several tables in a view, but I can't get my trigger to work. The create view command was as follows:
    CREATE OR REPLACE VIEW VIEW_MI_JOIN_GC
    AS
    SELECT MAP_INDEX.mi_prinx,
           index_type_id,
           original_map_publication_id,
           original_map_sheet_number_id,
           name_of_feature,
           geog_coordinates_id,
           GEOG_COORDINATES.mi_prinx AS "mi_prinx_polygon",
           GEOG_COORDINATES.geographical_coordinates,
           GEOG_COORDINATES.mapinfo_style_row
     FROM MAP_INDEX
      JOIN GEOG_COORDINATES
       ON geog_coordinates_id=GEOG_COORDINATES.mi_prinx;
    The view above connects a polygon table to the table of function names which means that a polygon appears several times in a view, even though one version of the polygon exists in the base table. This means the direct update of view cannot take place, since 1 polygon can appear multiple times in a view. The two original base tables and their columns names are:
    MAP_INDEX
    ---------
    MI_PRINX
    INDEX_TYPE_ID
    ORIGINAL_MAP_PUBLICATION_ID
    ORIGINAL_MAP_SHEET_NUMBER_ID
    NAME_OF_FEATURE
    MAPINFO_STYLE_ROW
    GEOGRAPHICAL_COORDINATES
    GEOG_COORDINATES_ID
    
    GEOG_COORDINATES
    ----------------
    MI_PRINX
    GEOGRAPHICAL_COORDINATES
    MAPINFO_STYLE_ROW
    Relax, I created was as follows:
    CREATE OR REPLACE TRIGGER TRIG_VIEW_MI_JOIN_GC
       INSTEAD OF UPDATE ON VIEW_MI_JOIN_GC
          REFERENCING NEW AS NEW
     FOR EACH ROW
    BEGIN
     UPDATE MAP_INDEX
      SET mi_prinx = :NEW.mi_prinx,
          index_type_id = :NEW.index_type_id,
          original_map_publication_id = :NEW.original_map_publication_id,
          original_map_sheet_number_id = :NEW.original_map_sheet_number_id,
          name_of_feature = :NEW.name_of_feature,
          mapinfo_style_row = :NEW.mapinfo_style_row,
          geographical_coordinates = :NEW.geographical_coordinates,
          geog_coordinates_id = :NEW.geog_coordinates_id
       WHERE geog_coordinates_id = :OLD.geog_coordinates_id;
     UPDATE GEOG_COORDINATES
      SET mi_prinx = :NEW.mi_prinx,
          geographical_coordinates = :NEW.geographical_coordinates,
          mapinfo_style_row = :NEW.mapinfo_style_row
       WHERE mi_prinx = :OLD.mi_prinx;
    END;
    /
    The idea is that when I draw a new polygon in MapInfo and assign him a revised number geog_coordinates_id and the number of mi_prinx_polygon, which are the same, once I have save the view as then it updates the underlying tables. Geographical_coordinates and mapinfo_style_row of map_index table columns are columns with ancient polygon data which while not having currently new data inserted into them, are required for the previous data they contain. These data are currently being added to the geog_coordinates table with other scripts. The idea is that all the data is then read using a view and updates made to the view, triggering instead of relaxing, so data are not duplicated but still visible as if it were.

    When I created first the relaxation above in SQLdeveloper it seems to run constantly. Then my computer crashed, not related to this work, and I lost session because I did not commit it. I was not ready to commit it because I believe that something is wrong.

    I am in the trigger syntax correctly and I go about it in the right way? I want to only update the rows that have changed, that's why I was using: NEWS and: OLD.

    Kind regards

    Tim

    Published by: user467357 on November 18, 2008 18:07
    I modified my script a little because there were a few errors. for example. start and old as old and view name typo

    Something like this->

    satyaki>
    satyaki>select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    
    Elapsed: 00:00:01.78
    satyaki>
    satyaki>
    satyaki>create table MAP_INDEX
      2   (
      3        mi_prinx                    NUMBER(10) not null,
      4        index_type_id                NUMBER(6) not null,
      5        original_map_publication_id  NUMBER(6) not null,
      6        original_map_sheet_number_id NUMBER(6) not null,
      7        name_of_feature              VARCHAR2(80) not null,
      8        mapinfo_style_row            VARCHAR2(80),
      9        geographical_coordinates    SDO_GEOMETRY,
     10        geog_coordinates_id          NUMBER(10),
     11        constraints pk_mi_prinx primary key(mi_prinx)
     12   );
    
    Table created.
    
    Elapsed: 00:00:04.39
    satyaki>
    satyaki>create table GEOG_COORINDATES
      2   (
      3     mi_prinx NUMBER(10) not null,
      4     geographical_coordinates SDO_GEOMETRY,
      5     mapinfo_style_row VARCHAR2(80),
      6     constraints pk_mi_prinx_n primary key(mi_prinx)
      7   );
    
    Table created.
    
    Elapsed: 00:00:00.30
    satyaki>
    satyaki>
    satyaki>CREATE OR REPLACE VIEW VIEW_MI_JOIN_GC
      2  AS
      3  SELECT MAP_INDEX.mi_prinx,
      4         MAP_INDEX.index_type_id,
      5         MAP_INDEX.original_map_publication_id,
      6         MAP_INDEX.original_map_sheet_number_id,
      7         MAP_INDEX.name_of_feature,
      8         MAP_INDEX.geog_coordinates_id,
      9         GEOG_COORINDATES.mi_prinx AS "mi_prinx_polygon",
     10         GEOG_COORINDATES.geographical_coordinates,
     11         GEOG_COORINDATES.mapinfo_style_row
     12   FROM MAP_INDEX , GEOG_COORINDATES
     13   WHERE MAP_INDEX.geog_coordinates_id=GEOG_COORINDATES.mi_prinx;
    
    View created.
    
    Elapsed: 00:00:00.32
    satyaki>
    satyaki>
    satyaki>insert into MAP_INDEX values(
      2                                 &mi_prinx,
      3                                 &index_type_id,
      4                                 &original_map_publication_id,
      5                                 &original_map_sheet_number_id,
      6                                 '&name_of_feature',
      7                                 '&mapinfo_style_row',
      8                                 null,
      9                                 &geog_coordinates_id);
    Enter value for mi_prinx: 1
    old   2:                                &mi_prinx,
    new   2:                                1,
    Enter value for index_type_id: 44
    old   3:                                &index_type_id,
    new   3:                                44,
    Enter value for original_map_publication_id: 5678
    old   4:                                &original_map_publication_id,
    new   4:                                5678,
    Enter value for original_map_sheet_number_id: 356
    old   5:                                &original_map_sheet_number_id,
    new   5:                                356,
    Enter value for name_of_feature: AA
    old   6:                                '&name_of_feature',
    new   6:                                'AA',
    Enter value for mapinfo_style_row: GG
    old   7:                                '&mapinfo_style_row',
    new   7:                                'GG',
    Enter value for geog_coordinates_id: 9
    old   9:                                &geog_coordinates_id)
    new   9:                                9)
    
    1 row created.
    
    Elapsed: 00:00:00.16
    satyaki>/
    Enter value for mi_prinx: 2
    old   2:                                &mi_prinx,
    new   2:                                2,
    Enter value for index_type_id: 55
    old   3:                                &index_type_id,
    new   3:                                55,
    Enter value for original_map_publication_id: 6789
    old   4:                                &original_map_publication_id,
    new   4:                                6789,
    Enter value for original_map_sheet_number_id: 357
    old   5:                                &original_map_sheet_number_id,
    new   5:                                357,
    Enter value for name_of_feature: BB
    old   6:                                '&name_of_feature',
    new   6:                                'BB',
    Enter value for mapinfo_style_row: 10
    old   7:                                '&mapinfo_style_row',
    new   7:                                '10',
    Enter value for geog_coordinates_id: 8
    old   9:                                &geog_coordinates_id)
    new   9:                                8)
    
    1 row created.
    
    Elapsed: 00:00:00.04
    satyaki>
    satyaki>commit;
    
    Commit complete.
    
    Elapsed: 00:00:00.03
    satyaki>
    satyaki>
    satyaki>insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row');
    Enter value for mi_prinx: 9
    Enter value for mapinfo_style_row: FFG
    old   1: insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row')
    new   1: insert into GEOG_COORINDATES values(9,null,'FFG')
    
    1 row created.
    
    Elapsed: 00:00:00.07
    satyaki>/
    Enter value for mi_prinx: 8
    Enter value for mapinfo_style_row: GGT
    old   1: insert into GEOG_COORINDATES values(&mi_prinx,null,'&mapinfo_style_row')
    new   1: insert into GEOG_COORINDATES values(8,null,'GGT')
    
    1 row created.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>commit;
    
    Commit complete.
    
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 AA                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.09
    satyaki>
    satyaki>
    satyaki>CREATE OR REPLACE TRIGGER TRIG_VIEW_MI_JOIN_GC
      2  INSTEAD OF UPDATE ON VIEW_MI_JOIN_GC
      3  FOR EACH ROW
      4  DECLARE
      5   m_info_svw  varchar2(80);
      6  BEGIN
      7   m_info_svw :=  :NEW.mapinfo_style_row;
      8
      9   UPDATE MAP_INDEX
     10    SET mi_prinx = :NEW.mi_prinx,
     11        index_type_id = :NEW.index_type_id,
     12        original_map_publication_id = :NEW.original_map_publication_id,
     13        original_map_sheet_number_id = :NEW.original_map_sheet_number_id,
     14        name_of_feature = :NEW.name_of_feature,
     15        mapinfo_style_row = m_info_svw,
     16        geographical_coordinates = :NEW.geographical_coordinates,
     17        geog_coordinates_id = :NEW.geog_coordinates_id
     18     WHERE geog_coordinates_id = :OLD.geog_coordinates_id;
     19   UPDATE GEOG_COORINDATES
     20    SET mi_prinx = :NEW.geog_coordinates_id,
     21        geographical_coordinates = :NEW.geographical_coordinates,
     22        mapinfo_style_row = m_info_svw
     23     WHERE mi_prinx = :OLD.geog_coordinates_id;
     24  END;
     25  /
    
    Trigger created.
    
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 CC                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.09
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 FFG
             8 GGT
    
    Elapsed: 00:00:00.07
    satyaki>select * from MAP_INDEX;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  MAPINFO_STYLE_ROW                                                                GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), S
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------
             1            44                        5678                          356 CC                                                                               HHH
             2            55                        6789                          357 BB                                                                               HHH                                                                                                                                                  
    
    Elapsed: 00:00:00.12
    satyaki>
    satyaki>update VIEW_MI_JOIN_GC
      2    set name_of_feature = 'DD'
      3  where mi_prinx = 1;
    
    1 row updated.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>select * from VIEW_MI_JOIN_GC;
    
      MI_PRINX INDEX_TYPE_ID ORIGINAL_MAP_PUBLICATION_ID ORIGINAL_MAP_SHEET_NUMBER_ID NAME_OF_FEATURE                                                                  GEOG_COORDINATES_ID mi_prinx_polygon GEOGRAPHICAL_COORDINATES(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    ---------- ------------- --------------------------- ---------------------------- -------------------------------------------------------------------------------- ------------------- ---------------- ---------------------------------------------------------------------------------------------------------------
             1            44                        5678                          356 DD                                                                                                 9                9
             2            55                        6789                          357 BB                                                                                                 8                8                                                                                                                 
    
    Elapsed: 00:00:00.08
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 FFG
             8 GGT
    
    Elapsed: 00:00:00.06
    satyaki>
    satyaki>update VIEW_MI_JOIN_GC
      2     set mapinfo_style_row = 'OOOO'
      3     where mi_prinx = 1;
    
    1 row updated.
    
    Elapsed: 00:00:00.05
    satyaki>
    satyaki>select mi_prinx,mapinfo_style_row from GEOG_COORINDATES;
    
      MI_PRINX MAPINFO_STYLE_ROW
    ---------- --------------------------------------------------------------------------------
             9 OOOO
             8 GGT
    
    Elapsed: 00:00:00.06
    satyaki>
    satyaki>select mapinfo_style_row from MAP_INDEX;
    
    MAPINFO_STYLE_ROW
    --------------------------------------------------------------------------------
    OOOO
    HHH
    
    Elapsed: 00:00:00.06
    satyaki>
    

    Hope this will help you.

    Kind regards.

    LOULOU.

  • Drop the materialized view's base table

    HI please let me know what happens if I drop from the base table of a materialized view? the MV remains valid with the data?

    Hello

    Well, it's easy to test yourself.

    SQL> select count(*) from t1;
    
      COUNT(*)
    ----------
           100
    
    SQL> desc t1
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                                 NUMBER(10)
    
    SQL> create materialized view t1_mv as select * from t1;
    
    Materialized view created.
    
    SQL> select count(*) from t1_mv;
    
      COUNT(*)
    ----------
           100
    
    SQL> drop table t1 purge;
    
    Table dropped.
    
    SQL> select count(*) from t1_mv;
    
      COUNT(*)
    ----------
           100
    
    SQL> desc t1_mv
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     ID                                                 NUMBER(10)
    
    SQL> select object_type, status from user_objects where object_name = 'T1_MV';
    
    OBJECT_TYPE         STATUS
    ------------------- -------
    TABLE               VALID
    MATERIALIZED VIEW   INVALID
    
    SQL> select * from t1_mv where rownum < 5;
    
            ID
    ----------
             1
             2
             3
             4
    
    SQL>
    

    I think the answer is very clear.

    Asif Momen
    http://momendba.blogspot.com

  • create view materized without constraint primary key on the base table?

    Hello

    I tried to create a materized view, but I got this error:

    SQL > CREATE MATERIALIZED VIEW FAST REFRESH TABLE1_MV
    START BY
    TO_DATE (April 25, 2009 03:00:13 ',' DD-MM-YYYY hh24:mi:ss')
    NEXT
    SYSDATE + 1
    AS
    Select * from TABLE1@remote_db
    SQL > /.
    CREATE MATERIALIZED VIEW FAST REFRESH TABLE1_MV
    *
    ERROR on line 1:
    ORA-12014: table 'TABLE1' does not contain a primary key constraint.

    Table1 in remote_db is not a primary key constraint. Is there anyway that I can create a view materized on a base table that is not a primary key constraint?

    Thank you
    Liz

    Make sure user name used in remote_db database link has select privileges on Journal of MV. On the issue of db source:

    SELECT LOG_TABLE FROM DBA_MVIEW_LOGS WHERE LOG_OWNER = 'TABLE1-owner' AND MASTER = "TABLE1";

    This will give you MV table the journal name. On the issue of target side:

    SELECT * from MV-LOG-NAME@remote_db;

    And after your version.

    SY.

  • How to speed up sqlldr import of a materialized view's base table

    Hi all

    We have a large base on a warehouse system table.

    We charge this table periodically by using SQL * Loader.

    The charges are generally 30 minutes and its supported. Recently, we have created a materialized view using this table as a table base (and his newspaper correspondents materialized view) mode to REFRESH FAST .

    Now we see that expenses will take much longer muuuch.

    We created the view as the ISC documentation, using COUNT (*) columns and refresh mode seems to work. BUT, why is it so slow? Is it possible to speed it up?

    Thank you in advance.


    Mariano
    Spain

    Hello

    You have all the nonunique indexes or indexes on base tables bitmap? If Yes, you can consider disabling or setting their USUSABLE, and rebuild them after charge, you can also consider using PARALLEL INDICATOR your query mview to speed up, but you need to test this on your system with suitable parallel degrees (No. = 2 CPU, parallel = 2).

    The amount of data you load?
    Is the partitioned table, if so, then what system is used?
    Have you considered materialized view partitioning and using PCT (track changes of partition) to refresh loaded recently loaded partition? the amount of data you have in this table?

    Concerning

  • Difference between the table and Materialized View

    Is there an advantage outside automatic synchronization (founded refresh selected type) using Materialized View?

    I came across this question as table and MV both store values, and we can also update table using the code what is the need of MV? Why not create a table instead of MV with the same definition and same charly?

    I need some explanation to force someone to convince himself.

    Thank you

    http://docs.Oracle.com/CD/B19306_01/server.102/b14223/basicmv.htm

    Sections that highlight its strengths:

    1. materialized views for data warehouses

    2. materialized views for distributed computing

    Query, re - write, features as Materialized view log files that can be used for replication between databases, etc...

  • Base Table vs table of master...

    Hello Experts;

    Advised to start the new thread

    Re: Append hint hint Vs Pareall


    According to materialized, any difference between the TABLE of BASE of MASTER TABLE Vs LOCAL?

    -I know it's a question very very basic but get confused by referring to some articles from oracle.

    ********************************

    SQL > CREATE VIEW MATERIALISEE TEST_QUERY
    REFRESH THE COMMIT
    Did YOU SELECT COLUMN_1, COLUMN_2 from emp;

    Here, the EMP is BASE TABLE... A query from clause containing is the main table.
    So I think that master table is another name of the local base table / base table. but some links saying something different.
    Please provide details...

    Thanks in advance...

    >
    Thanks for the reply... what you mentioned in your response... I read the official documentation... I'm clear with the OFFICIAL DOCS
    >
    Then you should be clear that the official docs use the term of "old masters" as this quote from doc, I give to the States.
    >
    This reference uses tables of masters"for consistency
    >
    Who should explain that statement you just do it too
    >
    It is not explained any information on "basic tables".
    >
    Because the official docs do not use the term "base table" when discussing the materialized views.
    >
    Remember, I said to get confused when it comes to some blogs of oracle.
    >
    That's why I ask you to provide the links you were talking about. Because you have only provided a link is all I can comment on.
    >
    The START WITH clause indicates the database when performing the first replication of the main table of the local base table.
    >
    In this particular quote the author refers to the table that represents the materialized view (MV) itself. A MV defines a table and this author refers to this table (the table that contains the data of MV) as 'the table in the local database.

    The author uses the same term "base table" in other places in the article to view the tables in the source of the MV. There is nothing wrong with that as long as we don't know what table is mentioned but the Oracle documentation uses the term "master tables.
    >
    I need some information on 'base/local table base table' - what?
    >
    Often, these terms are used to designate the 'masters' paintings of a MV. A MV can be based on a "remote" Server tables these tables would be called 'remote master paintings' by the docs of the Oracle, but may be referred to as 'remote base tables' by other authors. Means of "remote" on another data base; means "local" on the same database.

    Oracle docs use the term "basic tables" to refer to the normal shooting, but not for materialized views source tables.

    See the doc of database Concepts
    http://docs.Oracle.com/CD/B28359_01/server.111/b28318/schema.htm
    >
    How the views are stored

    Unlike a table, a view is not attributed to any storage space, nor a view contains it actually given. On the contrary, a view is defined by a query that retrieves or derived tables that refer to the data view. These tables are called base tables. Base tables can be in turn the actual tables or can be seen themselves (including materialized views). Because a view is based on other items, a view requires no storage other than storage for the definition of the view (stored query) in the data dictionary.

  • update multiple columns in table B of table based on the corresponding pass.

    Hello

    Will have two tables as below,
    create table billing_info 
    (MS number,
    RT_ID number,
    BILL_NO number)
    
    create table mu 
    (MS number,
    RT_ID number,
    BILL_NO number)
    
    insert into billing_info (MS,RT_ID,BILL_NO) values (1,99,635);
    insert into billing_info (MS,RT_ID,BILL_NO) values (2,99,635);
    insert into billing_info (MS,RT_ID,BILL_NO) values (3,999,1635);
    insert into billing_info (MS,RT_ID,BILL_NO) values (4,599,7635);
    
    insert into mu(MS) values (1);
    insert into mu(MS) values (2);
    insert into mu(MS) values (3);
    insert into mu(MS) values (4);
    Here the table mu got nullability for columns RT_ID, BILL_NO. I need to update this coulmns in the mu of table with the RT_ID, BILL_NO of billing_info of table corresponding to the value of MS.

    How to on this subject.

    I tried the follwing examples

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:43440209618042

    and

    http://decipherinfosys.WordPress.com/2007/01/31/update-data-in-one-table-with-data-from-another-table/

    but without hope...

    It throws errors like ora-01779...
    UPDATE mu
       SET rt_id = (
          SELECT rt_id
            FROM billing_info
           WHERE billing_info.ms = mu.ms )
     WHERE EXISTS (
          SELECT 1
            FROM billing_info
           WHERE billing_info.ms = mu.ms )
    

    updates all lines of MU with the RT_ID of the line in BILLING_INFO where there is a MS value assuming that such a line exists in BILLING_INFO. This assumes that MU is unique in both tables. If there are duplicates, you will need to explain how to know which line of BILLING_INFO corresponds to a particular line of MU.

    Of course, from the point of view of standardization, two tables with the same key and the same nonkey column should be extremely unusual.

    Justin

  • How to compare the length of the data to a staging table with the definition of the base table

    Hello
    I have two tables: staging of the table and the base table.
    I get flatfiles data in the staging of the table, depending on the structure of the requirement of staging of the table and the base table (length of each column in the staging table is 25% more data dump without errors) are different for ex: If we have the city long varchar 40 column in table staging there 25 in the base table. Once data are discharged into the intermediate table that I want to compare the actual length of the data for each column in the staging table with the database table definition (data_length for each column of all_tab_columns) and if no column is different length that I need to update the corresponding line in the intermediate table which also has an indicator called err_length.

    so for that I use the cursor c1 is select length (a.id), length (b.SID) of staging_table;
    c2 (name varchar2) cursor is select data_length all_tab_columns where table_name = 'BASE_TABLE' and column_name = name;
    But we get atonce data in the first query while the second slider, I need to get for each column and then compare with the first?
    Can someone tell me how to get the desired results?

    Thank you
    Manoi.

    Hey, Marco.

    Of course, you can set src.err_length in the USING clause (where you can reference all_tab_columns) and use this value in the SET clause.
    It is:

    MERGE INTO  staging_table   dst
    USING  (
           WITH     got_lengths     AS
                     (
              SELECT  MAX (CASE WHEN column_name = 'ENAME' THEN data_length END)     AS ename_len
              ,     MAX (CASE WHEN column_name = 'JOB'   THEN data_length END)     AS job_len
              FROM     all_tab_columns
              WHERE     owner          = 'SCOTT'
              AND     table_name     = 'EMP'
              )
         SELECT     s.ename
         ,     s.job
         ,     CASE WHEN LENGTH (s.ename) > l.ename_len THEN 'ENAME ' END     ||
              CASE WHEN LENGTH (s.job)   > l.job_len   THEN 'JOB '   END     AS err_length
         FROM     staging_table     s
         JOIN     got_lengths     l     ON     LENGTH (s.ename)     > l.ename_len
                             OR     LENGTH (s.job)          > l.job_len
         )     src
    ON     (src.ename     = dst.ename)
    WHEN MATCHED THEN UPDATE
         SET     dst.err_length     = src.err_length
    ;
    

    As you can see, you have to hardcode the names of the columns common to several places. I swam () to simplify that, but I found an interesting (at least for me) alternative grouping function involving the STRAGG user_defined.
    As you can see, only the subquery USING is changed.

    MERGE INTO  staging_table   dst
    USING  (
           SELECT       s.ename
           ,       s.job
           ,       STRAGG (l.column_name)     AS err_length
           FROM       staging_table          s
           JOIN       all_tab_columns     l
          ON       l.data_length  < LENGTH ( CASE  l.column_name
                                              WHEN  'ENAME'
                                    THEN      ename
                                    WHEN  'JOB'
                                    THEN      job
                                       END
                               )
           WHERE     l.owner      = 'SCOTT'
           AND      l.table_name     = 'EMP'
           AND      l.data_type     = 'VARCHAR2'
           GROUP BY      s.ename
           ,           s.job
           )     src
    ON     (src.ename     = dst.ename)
    WHEN MATCHED THEN UPDATE
         SET     dst.err_length     = src.err_length
    ;
    

    Instead of the user-defined STRAGG (that you can copy from AskTom), you can also use the undocumented, or from Oracle 11.2, WM_CONCAT LISTAGG built-in function.

  • trigger for update field in a table with the sum of the fields to another table

    My experience in creation of triggers and pl/sql in general can be described in terms of oracle with the null value. I practiced by creating arrays and applications on my personal server at home to help me with some of my work related tasks. Right now I am creating a trigger which will, after insert, update, delete on the update of the table assignment_time_track the area of the time_spent on the table of assignments with the sum of the time_spent on the assignment_time_track table fields. I hope that run on the sentence it is clear to the people other than me. I tried this script on my own using the tool of creation of trigger for Oracle Database Express Edition, but I get the following error:

    Create a trigger failed, for the following reason:
    ORA-06552: PL/SQL: ORA-06553 finished Compilation unit analysis: PLS-320: the declaration of the type of the expression is incomplete or incorrect

    Here is my attempt to create the trigger on my own.

    create or replace trigger "ASSIGNMENT_TIME_TRACK_T1".
    AFTER
    INSERT or update or delete on 'ASSIGNMENT_TIME_TRACK '.
    for each line
    Start
    update assignments
    Set time_spent = (select sum (time_spent)
    of assignment_time_track
    where assignment_time_track.name = assignments.name);

    end;
    /


    If what I posted is not clear or more detail is needed, let me know and I will respond with a full description of tables and my goals for each table. Thanks in advance for any help. I also gladly accepts links to tutorials or lessons that explain how to do this kind of thing.

    Published by: bobonthenet on March 9, 2009 14:01

    I think I understand what you mean :)

    Rather than use a trigger to keep the master table (assignments) in sync with the time spent on the details, it would be much easier to use a query to do this, maybe creating a view.

    Something along the lines of

    SQL> create table assignments
      2  (id number primary key
      3  ,name varchar2(10)
      4  );
    
    Table created.
    
    SQL>
    SQL> create table assignment_time_tbl
      2  (id number primary key
      3  ,assid number references assignments
      4  ,time_spent number
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into assignments
      2  select rownum
      3       , 'a'
      4    from all_objects
      5   where rownum < 5
      6  /
    
    4 rows created.
    
    SQL>
    SQL> insert into assignment_time_tbl
      2  select rownum
      3       , rownum
      4       , rownum * 3
      5    from all_objects
      6   where rownum < 5
      7  /
    
    4 rows created.
    
    SQL>
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL>
    SQL> select a.id
      2       , a.name
      3       , (select sum (time_spent)
      4            from assignment_time_tbl
      5           where assid = a.id
      6         )
      7    from assignments a
      8  /
    
            ID NAME       (SELECTSUM(TIME_SPENT)FROMASSIGNMENT_TIME_TBLWHEREASSID=A.ID)
    ---------- ---------- -------------------------------------------------------------
             1 a                                                                      3
             2 a                                                                      6
             3 a                                                                      9
             4 a                                                                     12
    
  • Add FK between a table and a view?

    Is this possible in 4.1 to add a FK between a table and a view (off of course)?

    If I'm in a view, it seems that I can define a FK to another view or a table, but if I start with a table, some views appear in the list. The view already has a defined PK.

    Is it normal?

    Use case: I have a table of generic code, so I'm set up views on the code for each type of code table. Then, I want at least diagram CF from specific code view of the code typed column on a table for the sub.

    Hello Kent,

    Is this possible in 4.1 to add a FK between a table and a view (off of course)?

    Yes.  You can do this by clicking on the icon of the new foreign key above the diagram, then by selecting the view first, then the table.

    I connected an enhancement request to allow a foreign key to a view to be added using the table properties dialog box.

    Thanks for pointing it.

    David

  • How can I update query joining multiple tables.

    Hi team,

    I want to update a column of TABLE 1, but it should rally with TABLE 2. Under certain conditions, that it should be updated.

    I created as below. But it does not work.

    Can you please suggest me how can I do?

    UPDATE Table1
    SET Table1.Column1 = 'name'
    FROM Table1 T1, Table2 T2
    WHERE T1.id = T2.id
    and T1.name  = T2.Name
    And T1.id = UPDATE Table1
      SET Table1.Column1 = 'name'
    FROM Table1 T1, Table2 T2
    WHERE T1.id = T2.id
    and T1.id = '100';
    
    


    Hello

    Your update statement is not at all clear.

    Something like below:

    UPDATE Table1 T1

    THE T1 VALUE. Column1 = 'name '.

    WHERE EXISTS (SELECT 1 FROM Table2 T2 WHERE)

    T1.ID = T2.id and T1.name = T2. (Name);

    (Or)

    UPDATE Table1 T1

    THE T1 VALUE. Column1 = 'name '.

    WHERE EXISTS (SELECT 1 FROM Table2 T2 WHERE)

    T1.ID = T2.id and T1.name = T2. The name) and T1.id = '100';

  • name of the dynamic table in a view

    How can I create a view of a table whose name is dynamically determined?

    for example, I have tables for each month table_2010401, the table_201402, the 201403 table and so on. I need to extract the data from the last table. This is more or less what I want to do:

    CREATE OR REPLACE VIEW VW_TABLE

    AS

    SELECT * FROM

    (SELECT TRIM (MAX (TABLE_NAME)) FROM ALL_TABLES WHERE TABLE_NAME LIKE 'POL_LINK %' AND OWNER = 'ACTUARYD')

    );

    Can anyone help? Thank you in advance.

    Most approach simple and straight forward it would be to recreate every month a CURRENT_TABLE view or a synonym that points to a table 'current' - table_2010401 or table_20140301.

    You can recreate this view, or synonym every month just after creating the table current.

    Another approach would be to create a view based on a function of pipeline that derives from a necessary table name and uses dynamic SQL statements to get the lines of him to channel them in the view.

  • Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside

    Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside the Jquery page. In the future I would also be able to add, to remove the DB records. Any help, tutorial... Thanks TG

    I would like to connect with the database instead of "writing" all the tables in the bearings inside the Jquery page

    This is usually done with a CMS (content management system). There are commercial products CMS like WordPress, Joomla and perch. You create one or several layouts and then create pages of these page layouts using the CMS. In this way, it is possible to have hundreds of pages, each with unique content, but a page layout that can be managed in a place of sharing.

    CMSs on shelf don't require programming skills. Otherwise, some of us write our own CMS with custom functions, but this requires back-end, as with PHP programming.

Maybe you are looking for