Cannot create Materialized View using the PL/SQL procedure

Hello

I have a question related to the creation of materialized view.
I have a stored procedure that creates the materialized view. When you try to perform this procedure, I get not enough privileges error: ORA-01031.

When I run the content of this procedure as a PL/SQL block anonymous their materialized view is created without any complications.
Can you please advice me on this subject?
It is even possible to create a materialized view in the stored procedure as I found no info on this subject.

Thank you
Petr

Hi chudapet,

Whenever you make in procedure, you must have direct subsidies and not through a role.

Most likely the grant to create a materialized view is available via a role to your username.
Assign a direct grant to the user:

grant create materialized view to scott;
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Tags: Database

Similar Questions

  • Creating a fichierXML using the pl/sql procedure.

    Hello

    I have a scenario here. I need to create an XML file, in a format of perticular. Since this is not a well-formed XML format, I am facing questions during the creation of the file.

    The XML file format is as below.

    ARTICLE <>10-B < / SECTION >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < name >
    < first > CBA < / first >
    BCD < middle > < / Middle >
    < Lastt > CBA < / last >
    <>brands
    < > 89 Subj1 < / Subj1 >
    < Subj2 > 89 < / Subj2 >
    < Subj3 > 89 < / Subj3 >
    < / brands >
    < / name >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < name >
    < first > CBA < / first >
    BCD < middle > < / Middle >
    < Lastt > CBA < / last >
    <>brands
    < > 89 Subj1 < / Subj1 >
    < Subj2 > 89 < / Subj2 >
    < Subj3 > 89 < / Subj3 >
    < / brands >
    < / name >
    --
    --
    --
    < SECTIONCNT > 6 < / SECTIONCNT >

    I tried to create the file using the utl functions, but it did not work. I would like to know is there any other approach?


    -Anu

    This should keep you in suspense:

    DECLARE
    
      xml_prolog    clob := '';
      xml_header    clob;
      xml_trailer   clob;
      tmp_xml       clob;
      tmp_file      clob;
    
      cursor c_invoice is
        select xmlelement ("ABCD",
                 xmlelement ("BankSvcRq",
                   ...
                 )
               ).getclobval() as invoice_xml
        from ap_invoices_all ai
        where batch_id = :c_batch_id
        and org_id = :c_ord_id;
    
    BEGIN
    
      -- create the temporary clob :
      dbms_lob.createtemporary(tmp_file, true);
    
      -- fetch the header :
      select xmlelement ("BATCHHEADER", batch_name).getclobval()
      into xml_header
      from ap_batches_all ab
      where ab.batch_id = :c_batch_id
      and ab.org_id = :c_org_id;
    
      -- fetch the trailer :
      select xmlelement ("BATCHTRAILER", count(*)).getclobval()
      into xml_trailer
      from ap_invoices_all ai
      where ai.invoice_id = nvl (:c_invoice_id, ai.invoice_id)
      and ai.batch_id = :c_batch_id
      and ai.org_id = :c_org_id;
    
      -- append header
      dbms_lob.append(tmp_file, xml_header);
    
      -- fetch the invoices and append :
      for r in c_invoice loop
        dbms_lob.append(tmp_file, xml_prolog);
        dbms_lob.append(tmp_file, r.invoice_xml);
      end loop;
    
      -- append trailer :
      dbms_lob.append(tmp_file, xml_trailer);
    
      -- write file to directory :
      dbms_xslprocessor.clob2file(tmp_file, 'TEST_DIR', 'test.dat', nls_charset_id('AL32UTF8'));
      dbms_lob.freetemporary(tmp_file);
    
    END;
    /
    
  • Bug: Cannot create materialized view log on XE 11 G

    Hello

    I connect as try and HR user create materialized view log
    CREATE MATERIALIZED VIEW LOG ON HR.EMPLOYEES;
    I get the error
    >
    Error from the 1 in the command line:
    CREATE LOG VIEW MATERIALIZED ON HUMAN RESOURCES. EMPLOYEES
    Error in the command line: 1 column: 0
    Error report:
    SQL error: ORA-00439: feature not enabled not: Advanced replication
    00439 00000 - "function not enabled: %s."
    * Cause: The specified feature is not enabled.
    * Action: Try not to use this feature.
    >

    You can create a materialized view log on 10G XE with no problems.

    Kind regards
    Jari

    http://dbswh.webhop.NET/dbswh/f?p=blog:Home:0

    Is this a bug in 11g or 10g?

    It was reported earlier in the beta forum now archived. {: identifier of the thread = 2214092}

    The current doc lists the MV sites only (and 'No' to the function of replication advanced):
    http://download.Oracle.com/docs/CD/E17781_01/license.112/e18068/TOC.htm#BABDFDAI

  • With as subquery block in create MATERIALIZED view or bulk pl/sql

    Hi all

    Can I use the with as subquery block in create MATERIALIZED view?

    or in pl/sql



    -Thank you

    Published by: xwo0owx on March 31, 2011 11:23

    Published by: xwo0owx on March 31, 2011 11:23

    Have you tried to test it? :)

    SQL > SELECT * FROM V$VERSION;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    
    SQL > CREATE VIEW TEST_VIEW
      2  AS
      3  WITH d AS
      4  (
      5          SELECT * FROM DUAL
      6  )
      7  SELECT *
      8  FROM   d
      9  ;
    
    View created.
    
    SQL > SELECT * FROM test_view;
    
    D
    -
    X
    
    SQL > DECLARE
      2          x DUAL.DUMMY%TYPE;
      3  BEGIN
      4          WITH d AS
      5          (
      6                  SELECT * FROM DUAL
      7          )
      8          SELECT dummy
      9          INTO   x
     10          FROM   d
     11          ;
     12
     13          DBMS_OUTPUT.PUT_LINE(x);
     14  END;
     15  /
    X
    
    PL/SQL procedure successfully completed.
    
  • Create materialized view at the trigger.

    Hello

    I use version below:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    I created a materialized view query below:

    CREATE THE FSG1_FUND000 MATERIALIZED VIEW

    PCTUSED, PCTFREE 5 70

    Users TABLESPACE

    STORAGE (INITIAL 500K NEXT 500K)

    Refresh a start fast with (sysdate) next (sysdate + (1 / 1440))

    WITH rowid

    AS

    SELECT * FROM ABNDEV_T24. FSG1_FUND000@abndev;

    This Mview if any insert or update only (WITHOUT DELETING) are coming which should be copy to another table. But in mView trigger does not work.

    So pls advice me no alternative.

    Querys trigger:

    create or replace trigger trg_dummy

    after insert or update on FSG1_FUND000

    for each line

    Start

    If the insertion

    insert into FSG1_FUND001 (RECID, XMLRECORD) values (: new.) RECID,: new. XMLRECORD);

    elsif update then

    insert into FSG1_FUND001 (RECID, XMLRECORD) values (: new.) RECID,: new. XMLRECORD);

    end if;

    end;

    /

    Kind regards

    Villa

    Hello

    I learned and referred website as much as we can not able to create a trigger in MView (sorry we create trigger but none use of creation because in view no insert and update happened). So I drop completely the materialized view concepts and relaxation.

    Instead of, I have using the procedure to insert records in a table and then I created one by dbms_scheduler job.

    This discussion will be useful for any future reference.

    -procedure-

    create or replace procedure p2

    as

    Start

    INSERT / * + APPEND * / INTO FSG1_FUND000 SELECT * FROM FSG1_FUND000@remote;

    End; BluShadow

    /

    -----------------job--------------------

    Begin

    DBMS_SCHEDULER. () CREATE_JOB

    job_name-online "JOB4."

    job_type-online "PLSQL_BLOCK."

    JOB_ACTION => ' BEGIN p2; END;',

    start_date => SYSDATE,

    repeat_interval => ' FREQ = MINUTELY; INTERVAL = 5;',

    End_date => NULL,

    -Online TRUE, enabled

    comments => "Inserting a record in a table");

    end;

    /

  • Create a view using the table

    Hi all

    I am beginner in Oracle.

    I have a two-column table that I use to create a view documents/statement once it meets the qualification.

    The table has fields. 1 number and 2. Group. If there is more than 3 records found on this table with the same NUMBER and the GROUP he should create this table view.

    Thank you

    Pramod Devkate

    The training is therefore two lines for a ticket and the agent. When the third row is added, create a line in the summary table. Later a fourth line is added to the table of training for this ticket and the agent, but we do not update the line in the summary table. We only touch the summary table when the third row is added to the training table, then it is only updated by the application. Very well

    INSERT INTO summary (ticket, agent, total_travel, total_mtts)

    Select ticket agent, sum (travel), sum (mtts)

    training

    where (ticket, agent) not in

    (select the ticket agent summary)

    Group ticket, agent

    having count (*) > 2.

    This inserts in the table only notes and agent ID that do not exist already.

  • Need to check delays in update of 1000 lines using the PL/SQL procedure.

    Hi all

    I'm new to PL/SQL. I need your help to build a procedure that executes the following statement and follows the time of update of 1000 rows. This is to check the performance of the database. I need to print the timestamp of start before the update and end timestamp after update. I need to do for the 1000 lines. The statement that will be used in the procedure is:

    SELECT

    'UPDATE XXAFL_MON_FACTS_F SET TASK_WID =' | NVL (TO_CHAR (TASK_WID), 'NULL') |', EXECUTION_PLAN_WID =' | NVL (TO_CHAR (EXECUTION_PLAN_WID), 'NULL').

    ', DETAILS_WID =' | NVL (TO_CHAR (DETAILS_WID), 'NULL') |', SOURCE_WID =' | NVL (TO_CHAR (SOURCE_WID), 'NULL') |', TARGET_WID = ' | NVL (TO_CHAR (TARGET_WID), 'NULL').

    ', RUN_STATUS_WID =' | NVL (TO_CHAR (RUN_STATUS_WID), 'NULL') |', SEQ_NUM =' | NVL (TO_CHAR (SEQ_NUM), 'NULL') |', NAME = "' | NVL (TO_CHAR (NAME), 'NULL').

    "', NO_POSITION =" ' | NVL (TO_CHAR (INSTANCE_NUM), e ') | " ', INSTANCE_NAME = "' | NVL (TO_CHAR (INSTANCE_NAME), 'NULL').

    "', TYPE_CD =" ' | NVL (TO_CHAR (TYPE_CD), e ') | " ', STATUS_CD = "' | NVL (TO_CHAR (STATUS_CD), e ') | " ', START_TS =' | NVL (TO_CHAR (START_TS), 'NULL').

    ', END_TS =' | NVL (TO_CHAR (END_TS), 'NULL') |', DURATION = ' | NVL (TO_CHAR (DURATION), 'NULL') |', STATUS_DESC = "' | NVL (TO_CHAR (STATUS_DESC), 'NULL').

    "', DBCONN_NAME =" ' | NVL (TO_CHAR (DBCONN_NAME), e ') | " ', SUCESS_ROWS =' | NVL (TO_CHAR (SUCESS_ROWS), 'NULL').

    ', FAILED_ROWS =' | NVL (TO_CHAR (FAILED_ROWS), 'NULL') |', ERROR_CODE = ' | NVL (TO_CHAR (ERROR_CODE), 'NULL') |', NUM_RETRIES =' | NVL (TO_CHAR (NUM_RETRIES), 'NULL').

    ', READ_THRUPUT =' | NVL (TO_CHAR (READ_THRUPUT), 'NULL') |', LAST_UPD = ' | NVL (TO_CHAR (LAST_UPD), 'NULL') |', RUN_STEP_WID = "' | NVL (TO_CHAR (RUN_STEP_WID), 'NULL').

    "', W_INSERT_DT = ' | NVL (TO_CHAR (W_INSERT_DT), 'NULL') |', W_UPDATE_DT = ' | NVL (TO_CHAR (W_UPDATE_DT), 'NULL').

    ', START_DATE_WID =' | NVL (TO_CHAR (START_DATE_WID), 'NULL') |', END_DATE_WID = ' | NVL (TO_CHAR (END_DATE_WID), 'NULL') |', START_TIME =' |

    NVL (TO_CHAR (START_TIME), 'NULL') |', END_TIME =' | NVL (TO_CHAR (END_TIME), 'NULL'). "WHERE INTEGRATION_ID ="' | INTEGRATION_ID | " « ; »  OF XXAFL_MON_FACTS_F;

    The above query creates instructions of update that must be executed 1000 times and the time required to update the 1000 lines should be followed.

    Thanks in advance!

    Code horribly wrong!

    Why this approach?

    Dynamic SQL is almost NEVER needed in PL/SQL. And if you think it's necessary and taking into account what is displayed as being problems here, you have a 99% chance of being wrong.

    This 1% where dynamic SQL is necessary, he will WITH bind variables to create shareable SQL, decrease memory requests, decrease the likelihood of a fragmented shared reel and decrease the burning CPU cycles on hard analysis.

    An example below. Your approach is the 1st. One that is slower than the correct approach to 37 (x_!) ...

    SQL> create table t ( n number );
    
    Table created.
    
    SQL>
    SQL> var ITERATIONS number;
    SQL> exec :ITERATIONS := 100000;
    
    PL/SQL procedure successfully completed.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using Hard Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ('||i||')';
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Hard Parsing
    Elapsed: 00:02:00.33
    SQL>
    SQL> TIMING START "INSERTs using Soft Parsing"
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  execute immediate 'insert into t values ( :1 )' using i;
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using Soft Parsing
    Elapsed: 00:00:06.06
    SQL> drop table t;
    
    Table dropped.
    
    SQL> create table t( n number );
    
    Table created.
    
    SQL>
    SQL>
    SQL> TIMING START "INSERTs using a single parse and repeatable statement handle "
    SQL> declare
      2          i      integer;
      3  begin
      4          for i in 1..:ITERATIONS
      5          loop
      6                  insert into t values ( i );
      7          end loop;
      8          commit;
      9  end;
    10  /
    
    PL/SQL procedure successfully completed.
    
    SQL> TIMING SHOW
    timing for: INSERTs using a single parse and repeatable statement handle
    Elapsed: 00:00:04.81
    SQL>
    
  • How to use the pl/sql procedure

    Hi all,

    How to use pl/sql packages and especially in what situations we are pl/sql, which is the cause of the procedure. Please explain with precision using small example.

    Thanks and greetings

    RAM

    I could tell this at a very high level.

    PL/SQL's procedural extension to SQL. SQL (structured query language) has no procedural capacity. They are executed as a stand-alone statement. When you want to generate a process flow with several SQL statement that you need to have a procedural language that could accommodate your SQL. PL/SQL is something similar to Java and Dot Net in this aspect. Said that PL/SQL is Oracle DB. This has some advantages. The most important thing is that when you have your SQL in PL/SQL oracle maintains its reliance on the object. Any database oracle related so you want to build, then you can consider to PL/SQL as the best way to use process flows.

    PL/SQL provides various methods such as the PROCEDURE, FUNCTION and the PACKAGE. The only thing that race stands is in its ability to modularize your code. So, using the package you can create process workflows that is modular and easy to understand.

  • create materialized view log on the table without a primary key

    Hi all
    CREATE TABLE client_months 
    (
      SUBJ_CODE         NUMBER(4),
      SERV_CODE         NUMBER(4),
      DEBIT_CODE        NUMBER(4),
      PERIOD_NUM        NUMBER(2),
      PERIOD_NAME       VARCHAR2(40 CHAR),
      FIRST_MON_DAY     DATE,
      LAST_MON_DAY      DATE,
      VALUE_MON_DAY     DATE,
      MONTHES           NUMBER(4,2),
      GARDENING_WEIGHT  NUMBER(5,4),
      REASON_CODE       NUMBER(5),
      STAMP_ACTION      VARCHAR2(1 CHAR),
      STAMP_CDATE       DATE                        DEFAULT SYSDATE,
      STAMP_DATE        DATE,
      STAMP_USER        VARCHAR2(15 CHAR),
      REGION_CODE       NUMBER(9)
    )
    table created.
    
    CREATE UNIQUE INDEX client_months_UK  ON client_months 
    (SUBJ_CODE, SERV_CODE, DEBIT_CODE, PERIOD_NUM, REGION_CODE)
    index created.
    
    CREATE MATERIALIZED VIEW LOG ON client_months with rowid;
    
    CREATE MATERIALIZED VIEW client_months_mv 
    BUILD immediate 
    REFRESH FAST ON COMMIT 
    AS 
    SELECT * FROM client_months;
    
    ORA-12014: table 'CLIENT_MONTHS' does not contain a primary key constraint
    I don't want to refresh the mview when validation is performed on the base table.
    And I don't want to change the base table by adding a primary key.

    is it possible to create the mview journal using the unique index? or another solution?
    Please help
    Thanks in advance
    Naama

    Naamas wrote:
    No,
    I already read this post!

    Then you read wrong:

    SQL> CREATE TABLE client_months
      2  (
      3    SUBJ_CODE         NUMBER(4),
      4    SERV_CODE         NUMBER(4),
      5    DEBIT_CODE        NUMBER(4),
      6    PERIOD_NUM        NUMBER(2),
      7    PERIOD_NAME       VARCHAR2(40 CHAR),
      8    FIRST_MON_DAY     DATE,
      9    LAST_MON_DAY      DATE,
     10    VALUE_MON_DAY     DATE,
     11    MONTHES           NUMBER(4,2),
     12    GARDENING_WEIGHT  NUMBER(5,4),
     13    REASON_CODE       NUMBER(5),
     14    STAMP_ACTION      VARCHAR2(1 CHAR),
     15    STAMP_CDATE       DATE                        DEFAULT SYSDATE,
     16    STAMP_DATE        DATE,
     17    STAMP_USER        VARCHAR2(15 CHAR),
     18    REGION_CODE       NUMBER(9)
     19  )
     20  /
    
    Table created.
    
    SQL> CREATE UNIQUE INDEX client_months_UK  ON client_months
      2  (SUBJ_CODE, SERV_CODE, DEBIT_CODE, PERIOD_NUM, REGION_CODE)
      3  /
    
    Index created.
    
    SQL> CREATE MATERIALIZED VIEW LOG ON client_months with rowid
      2  /
    
    Materialized view log created.
    
    SQL> CREATE MATERIALIZED VIEW client_months_mv
      2  BUILD immediate
      3  REFRESH FAST WITH ROWID ON COMMIT -- pay attention to WITH ROWID
      4  AS
      5  SELECT * FROM client_months
      6  /
    
    Materialized view created.
    
    SQL>
    

    SY.

  • Moving all the newspapers and Materialized View at the schema level using the data pump in

    Hi Experts,

    Please help me on how I can exp/imp all materialized views andMV logs (as are some MVs) only the full scheme of other databases. I want to exclude everything else.

    Concerning
    -Samar-

    Using DBMS_METADATA. Create the following SQL script:

    SET FEEDBACK OFF
    SET SERVEROUTPUT ON FORMAT WORD_WRAPPED
    SET TERMOUT OFF
    SPOOL C:\TEMP\MVIEW.SQL
    DECLARE
        CURSOR V_MLOG_CUR
          IS
            SELECT  DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW_LOG',LOG_TABLE) DDL
              FROM  USER_MVIEW_LOGS;
        CURSOR V_MVIEW_CUR
          IS
            SELECT  DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW',MVIEW_NAME) DDL
              FROM  USER_MVIEWS;
    BEGIN
        DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
        FOR V_REC IN V_MLOG_CUR LOOP
          DBMS_OUTPUT.PUT_LINE(V_REC.DDL);
        END LOOP;
        FOR V_REC IN V_MVIEW_CUR LOOP
          DBMS_OUTPUT.PUT_LINE(V_REC.DDL);
        END LOOP;
    END;
    /
    SPOOL OFF
    

    In my case the script is saved as C:\TEMP\MVIEW_GEN. SQL. Now I will create a journal mview and mview in schema SCOTT and run the script above:

    SQL> CREATE MATERIALIZED VIEW LOG ON EMP
      2  /
    
    Materialized view log created.
    
    SQL> CREATE MATERIALIZED VIEW EMP_MV
      2  AS SELECT * FROM EMP
      3  /
    
    Materialized view created.
    
    SQL> @C:\TEMP\MVIEW_GEN
    SQL> 
    

    Run the C:\TEMP\MVIEW_GEN script. SQL generated a C:\TEMP\MVIEW queue. SQL:

      CREATE MATERIALIZED VIEW LOG ON "SCOTT"."EMP"
     PCTFREE 10 PCTUSED 30 INITRANS
    1 MAXTRANS 255 LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1
    MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL
    DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "USERS" 
    
    WITH PRIMARY KEY EXCLUDING NEW VALUES;
    
      CREATE MATERIALIZED VIEW "SCOTT"."EMP_MV" ("EMPNO", "ENAME", "JOB", "MGR",
    "HIREDATE", "SAL", "COMM", "DEPTNO")
      ORGANIZATION HEAP PCTFREE 10 PCTUSED 40
    INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
      STORAGE(INITIAL 65536 NEXT 1048576
    MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE
    "USERS"
      BUILD IMMEDIATE
      USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
    
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE
    DEFAULT CELL_FLASH_CACHE DEFAULT)
      TABLESPACE "USERS"
      REFRESH FORCE ON
    DEMAND
      WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
      USING ENFORCED
    CONSTRAINTS DISABLE QUERY REWRITE
      AS SELECT "EMP"."EMPNO"
    "EMPNO","EMP"."ENAME" "ENAME","EMP"."JOB" "JOB","EMP"."MGR"
    "MGR","EMP"."HIREDATE" "HIREDATE","EMP"."SAL" "SAL","EMP"."COMM"
    "COMM","EMP"."DEPTNO" "DEPTNO" FROM "EMP" "EMP";
                                   
    

    Now, you can run this on the database. You may need to adjust the tablespace and storage clauses. Or you can add more DBMS_METADATA. SET_TRANSFORM_PARAM calls to C:\TEMP\MVIEW_GEN. SQL to force DBMS_METADATA not to include the tablespace or / and the terms of storage.

    SY.

  • Creating a view using multiple joins - by reducing the number of output lines

    It is difficult to put into words exactly what I want to implement, so I'll just use an example. Let's say I have the following database:

    game (id, time, place)

    Reader (game_id, name)

    Referee (game_id, name)

    Foreign keys:
    Player (game_id) references game (id)
    Referee (game_id) references game (id)

    It is a very special match, in which:
    A game can have 1 to many players
    A game can have from 1 to several arbitrators

    I want to create the following view:

    Game_overview (Game_id, time, player, referee)

    It's easy to create this view with the following output:

    Game1, 15:00, player1, Referee1
    Game1, 15:00, player1, Referee2
    Game1, 15:00, player2, Referee1
    Game1, 15:00, player2, Referee2
    Game1, 15:00, Joueur3, null
    08:00, player1, Referee1, GaMe2
    GaMe2, 08:00, player1, Referee2

    HOWEVER, I want it to look like this:

    Game1, 15:00, player1, Referee1
    Game1, 15:00, player2, Referee2
    Game1, 15:00, Joueur3, null
    08:00, player1, Referee1, GaMe2
    GaMe2, 08:00, null, Referee2

    I think that this should not be TOO difficult to solve, but I can't really get my head around it.

    Welcome to the forum!

    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data. Sinve it's your first post, I'll do it for you:

    CREATE TABLE     game
    (       id          VARCHAR2 (10)     PRIMARY KEY
    ,     time          VARCHAR2 (10)
    --,     location     VARCHAR2 (10)     -- No need to include columns that play no role in this problem
    );
    
    INSERT INTO game (id, time) VALUES ('Game 1',  '3PM');
    INSERT INTO game (id, time) VALUES ('Game 2',  '8AM');
    
    CREATE TABLE     player
    (       game_id          VARCHAR2 (10)
    ,     name          VARCHAR2 (10)
    );
    
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 1');
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 2');
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 3');
    INSERT INTO  player (game_id, name) VALUES ('Game 2',  'Player 1');
    
    CREATE TABLE     referee
    (       game_id          VARCHAR2 (10)
    ,     name          VARCHAR2 (10)
    );
    
    INSERT INTO  referee (game_id, name) VALUES ('Game 1',  'Referee 1');
    INSERT INTO  referee (game_id, name) VALUES ('Game 1',  'Referee 2');
    INSERT INTO  referee (game_id, name) VALUES ('Game 2',  'Referee 1');
    INSERT INTO  referee (game_id, name) VALUES ('Game 2',  'Referee 2');
    

    In this way, people who want to help you can recreate the problem and test their ideas.

    In addition, to say what version of Oracle you are using. The following query will work in Oracle 9.1 or more.

    What you asked is what I call a Query, fixed-price , and this is a way to do it:

    WITH     player_plus     AS
    (
         SELECT     game_id
         ,     name
         ,     ROW_NUMBER () OVER ( PARTITION BY  game_id
                                   ORDER BY          name
                           )         AS r_num
         FROM    player
    )
    ,     referee_plus     AS
    (
         SELECT     game_id
         ,     name
         ,     ROW_NUMBER () OVER ( PARTITION BY  game_id
                                   ORDER BY          name
                           )         AS r_num
         FROM    referee
    )
    SELECT       g.id
    ,       g.time
    ,       p.name     AS player_name
    ,       r.name     AS referee_name
    FROM             player_plus     p
    FULL OUTER JOIN  referee_plus   r  ON   p.game_id     = r.game_id
                                    AND     p.r_num          = r.r_num
    JOIN           game          g  ON     g.id          = COALESCE (p.game_id, r.game_id)
    ORDER BY  g.id
    ,         COALESCE (p.r_num, r.r_num)
    ;
    

    Output:

    ID         TIME       PLAYER_NAM REFEREE_NA
    ---------- ---------- ---------- ----------
    Game 1     3PM        Player 1   Referee 1
    Game 1     3PM        Player 2   Referee 2
    Game 1     3PM        Player 3
    Game 2     8AM        Player 1   Referee 1
    Game 2     8AM                   Referee 2
    

    I see that you have more arbitrators than players in a game. If such was not the case, then you might make it a bit more efficient using a LEFT OUTER JOIN between p and r, rather than a FULL OUTER JOIN, and you can also use only the columns of p where I use COALESCE.

    Published by: Frank Kulash, March 9, 2012 18:15
    Fixed spelling

  • Cannot create an instance of the java virtual machine

    Hi when I try to launch my sql developer get this error

    Cannot create an instance of the java virtual machine located in the path C:\Program Files\Java\jdk1.6.0_38\jre\bin\client\jvm.dll, but I do not have the file in the location

    I'm trying to do

    BI CHAOS: SQL Developer: cannot create an instance of the Virtual Machine Java

    Cannot create an instance of the Virtual Machine Java

    but am not able to locate file product.conf in my machine

    OK, we lost time because you said never explicitly release of SQL Developer in use, and then, when I deduced this wrong, you went right with it, rather than correct me.  Remember the line from Blade Runner when Harrison Ford hits Rutger Hauer in the head with a pipe?  Than hurt!

    Anyway, since the last post (because of the osgi references in the file ide.conf) I see that you are using a version 4.0.x of SQL Developer.  You must update the file product.conf with the smallest Xmx value in order to create an instance of the JVM.  If you have not yet found the product.conf file on your system, this might help: http://www.thatjeffsmith.com/archive/2013/12/oracle-sql-developer-4-windows-and-the-jdk/

    Otherwise, ask someone in your organization COMPUTER help - keep in mind that AppData is one of those hidden Windows directories, so you'll have to tell explore to make it visible by the organize > Folder Options > view > hidden files and folders parameters.  In addition, you should use Java 7, not Java 6 - try to get that upgrade to the latest version of jdk1.7.0_xx (currently 60, I think).  Since you never said if your JDK is 32-bit or 64-bit, I can not say to use an AddVMOption, Add32VMOption or Add64VMOption.

    Best wishes

    Gary

    Post edited by: Gary Graham

  • is missing a closing parenthesis in create materialized view statement

    Hi, I am using oracle 10g R2 and try to create a view of materalized with the following statement:
    CREATE MATERIALIZED VIEW MVT_DEC_TAB USING INDEX REFRESH FAST ON COMMIT AS 
    select i.rowid as ind_rowid,c.rowid as indc_rowid,r.rowid as r_rowid,b.rowid as b_rowid,brk.rowid as brk_rowid,
    i.name,i.sname,i.address,i.tel,i.fax,i.email,
    DECODE(c.BRKNO,null,0,1) AS DEC_BRK,
    TO_TIMESTAMP(NVL(VEKDOV,'2001/01/01')||' 12:00:00','YYYY/MM/DD HH:MI:SS'),
    DECODE(c.brkno,null,DECODE(c.ncmpcode,null,c.vekdov,b.bcarddov),brk.validitydov)
    from indiv i,indivcoding c
    LEFT OUTER JOIN BROKER brk ON brk.brkno = c.brkno
    LEFT OUTER JOIN CORPORAT r
    ON c.ncmpcode=r.cmpcode INNER JOIN BCARD b ON b.bcardno=r.bcardno
    where c.typeact=2  
    and c.natcode=i.natcode
    and c.brkno is not null or c.ncmpcode is not null or c.nnatcode is not null
    but I get an error message:
    where c.typeact = 2
    ERROR on line 11:
    ORA-00907: lack of right parenthesis

    which makes no sense because if I run the sql code of the materialized view, it runs normally.
    I need to know what the causing this can someone help?

    Do not use the "LEFT OUTER JOIN" ANSI syntax in your CREATE MATERIALIZED VIEW definition.
    Specify

    FROM indiv i,indivcoding c, broker brk, corporat r
    WHERE brk.brkno(+) = c.brkno
    AND c.ncmpcode(+) = r.cmpcode
    

    OR

    FROM indiv i,indivcoding c, broker brk, corporat r
    WHERE c.brkno = brk.brkno(+)
    AND r.ncmpcode = c.cmpcode(+)
    

    (I find it more readable).

    Hemant K Collette

  • SDO_NN cannot be assessed without using the index when put inside subquery

    Hi all

    I met a problem when you use the function sdo_nn to find the nearest neighbor. Here is my scenario:

    _ I have 2 customer and store tables.

    Customer table _ a client_ID and a 2D sdo_geom point

    _ Store table has store_ID and a 2D polygon sdo_geom.

    In the beginning, I have this query to find the nearest store to each customer as below:

    Select s.STORE_ID, c.CLIENT_ID

    store customer, s c

    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE";

    _It works as expected when it returns a table showing the nearest store each customer.

    _Now I want to count the number of customers who have the same nearest store:

    Select / * + INDEX (store store_spatial_idx, client_spatial_idx client) * / count (nearest_store. CLIENT_ID)
    from (select s.STORE_ID, c.CLIENT_ID
    store customer, s c
    where sdo_nn (s.MYPOLYGON, c.MYPOINT, 'sdo_num_res = 1', 1) = "TRUE") nearest_store
    Group of nearest_store. STORE_ID;

    This query generates the following error:

    Error report-
    SQL error: ORA-13249: SDO_NN cannot be assessed without using the index
    ORA-06512: at the 'MDSYS. MD", line 1723
    ORA-06512: at the 'MDSYS. MDERR", line 17
    ORA-06512: at the 'MDSYS. PRVT_IDX', line 9
    13249 00000 - '%s '.

    I'm pretty new to spatial databases and hope get help to go further. Thank you in advance!

    Hello Pinball,

    Oracle space tends to be a quite complex with many variables and moving parts.  We chatted about the group to a sort of FAQ or guidelines to help people like you submit questions that actually answers.  First of all, you really have to tell us the version of Oracle you are using.  Particularly the problems involving the optimizer, version down to the exact defined patch number is a good idea.  Secondly, you took the time to submit the question so I guess you want a response.  If you really want to see the answer and then providing an example is one of the most important things that you can do.  I'm going to do here for you, but in general people on this forum come and go and are often pushed into lurkitude, so if you want the coax to provide you with an example of work is the key.

    DROP TABLE store1 PURGE;
    CREATE TABLE store1(
        store_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(store_id)
    );
    
    DROP TABLE client2 PURGE;
    CREATE TABLE client2(
        client_id INTEGER NOT NULL
       ,shape    MDSYS.SDO_GEOMETRY
       ,PRIMARY KEY(client_id)
    );
    
    CREATE OR REPLACE PROCEDURE seeder(
        p_client_count IN NUMBER
       ,p_store_count IN NUMBER
    )
    AS
      sdo_foo MDSYS.SDO_GEOMETRY;
      int_counter NUMBER;
      FUNCTION random_point
      RETURN MDSYS.SDO_GEOMETRY
      AS
          num_x1 NUMBER;
          num_y1 NUMBER;
    
      BEGIN
          num_x1 := dbms_random.value(-179,179);
          num_y1 := dbms_random.value(-89,89);
    
          RETURN MDSYS.SDO_GEOMETRY(
              2001
             ,8265
             ,MDSYS.SDO_POINT_TYPE(
                  num_x1
                 ,num_y1
                 ,NULL
              )
             ,NULL
             ,NULL
          );
    
      END random_point;
    
    BEGIN
      int_counter := 1;
      FOR i IN 1 .. p_client_count
      LOOP
          -- Create a client point
          sdo_foo := random_point();
          INSERT INTO client2
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      int_counter := 1;
      FOR i IN 1 .. p_store_count
      LOOP
          -- Create a store polygon of some kind
          sdo_foo := MDSYS.SDO_GEOM.SDO_ARC_DENSIFY(
              MDSYS.SDO_GEOM.SDO_BUFFER(
                  random_point()
                 ,5000
                 ,0.05
              )
             ,0.05
             ,'arc_tolerance=0.05'
          );
          INSERT INTO store1
          VALUES (
              int_counter
             ,sdo_foo
          );
          int_counter := int_counter + 1;
    
      END LOOP;
    
      COMMIT;
    
    END seeder;
    /
    
    BEGIN
      seeder(10000,200);
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'STORE1'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
          NULL;
    
    END;
    /
    
    BEGIN
      INSERT INTO user_sdo_geom_metadata(
          table_name
         ,column_name
         ,diminfo
         ,srid
      ) VALUES (
          'CLIENT2'
         ,'SHAPE'
         ,MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,.05),MDSYS.SDO_DIM_ELEMENT('Y',-90,90,.05))
         ,8265
      );
    
      COMMIT;
    
    EXCEPTION
      WHEN OTHERS
      THEN
         NULL;
    
    END;
    /
    
    CREATE INDEX store1_spx ON store1
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    CREATE INDEX client2_spx ON client2
    (shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX
    NOPARALLEL;
    
    /* Works as expected */
    SELECT
    s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
    store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    /* No worky? Works for me */
    SELECT
    ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
        s.store_id
       ,c.client_id
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I wrote this about 12 c (12.1.0.2.0) and everything works fine for me.  Then I moved back from 11 GR 2 (11.2.0.4.0) and of course, there are questions.  So I guess that you don't use flavor of 11g.  So at this point we can look at the docs and see for 11g, have you often need to specify which table is the head and that is the one that has the spatial index to use.
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e11830/sdo_operat.htm#SPATL1032

    Its rather interesting that the optimizer of 12 c knows what you want, when I had to squint myself at your request and to play a little with the refining.  Note that SDO_NN is sensitive, because the geometry of the main table should come second in the operator.  I did not know that on the top of my head.

    
    SELECT
    /*+ LEADING(c) INDEX(s store1_spx)  */
     s.store_id
    ,c.client_id
    ,MDSYS.SDO_NN_DISTANCE(1)
    FROM
     store1 s
    ,client2 c
    WHERE
    MDSYS.SDO_NN(
        s.shape
       ,c.shape
       ,'sdo_num_res=1'
       ,1
    ) = 'TRUE';
    
    SELECT
     ns.store_id
    ,COUNT(ns.client_id)
    FROM (
       SELECT
       /*+ LEADING(c) INDEX(s store1_spx)  */
        s.store_id
       ,c.client_id
       ,MDSYS.SDO_NN_DISTANCE(1)
       FROM
        store1 s
       ,client2 c
       WHERE
       MDSYS.SDO_NN(
           s.shape
          ,c.shape
          ,'sdo_num_res=1'
          ,1
       ) = 'TRUE'
    ) ns
    GROUP BY
    ns.store_id
    ORDER BY
    ns.store_id;
    

    So I think that is your answer.  Give it a shot and see if this fits the Bill.  Of course, moving to 12 c would be useful for such things.  It would be interesting to collect more examples of this kind of space thing where 12 c is the answer. Also, would be nice if we could mark somehow this discussion as applying only to 11g and earlier versions.

    See you soon,.

    Paul

  • Create Materialized view and Materialized view log.

    I wanted to create a materialized view with option "REFRESH QUICKLY YOU COMMIT".

    (1) table 1 - it is partitioned range + list - added primary key

    (2) View1 - having primary keys on the base table of view

    Steps to follow:

    (1) create the materialized on Table1; view journal -primary key by default

    (2) create the materialized on view1 view log.  -It gives below error.

    ORA-00942: table or view does not exist

    I wanted to create Materialized view as below

    create a materialized view

    Quickly REFRESH ON validation

    as

    Select...

    ........

    ... from table1

    where c1 (select c1 from View1 which...);


    Question:

    (1) because I am getting above error when creating journal of MV on the view. Can one create log view MV or we create a MV newspaper on the base table of view?

    (2) to create the MV with "REFRESH QUICKLY YOU COMMIT' option, we need to have the primary key on the main tables?


    Pointers on this will be really useful.


    Thank you

    Prasad

    "When a materialized view is maintained by the ON COMMIT method, the time required to perform the validation can be slightly longer than usual." This is because the refresh operation is performed as part of the validation process. This is why this method may not be suitable if many users at the same time change the tables on which is based the materialized view. »

    See: basis of materialized views (refreshment options) for all the other options and how they work.

Maybe you are looking for

  • Change stationery in mail

    I can find where are the models of stationery & I could open the file appropriate if I know enough, but all I want to do is to use the model of holiday but wider papermaking. If you know your way around HTML would be grateful for the help.

  • third-party firewall

    How to temporarily disable third-party firewalls

  • Extremely low disk space

    Hello Is someone can you please tell me what should I do to free up more disk space?  I have VERY VERY small footprint and can't seem to many to the top using the diskette when clean tool free. I even tried to cross and remove all of the programs tha

  • The G550 hard drive upgrade

    I have a G550 with a hard drive Hitachi HTS543232l9A300. It is a SATA or ATA drive? Can I replace it with a SATA II? Thank you.

  • I deleted some software by accident - now I can't read my files of windows (like word). Should what software I download?

    All of my windows files now are not recognized - as I do not have good software? I deleted it, try to free up space on my hard drive - but I indeed need this software: while my computer said I have no... I think that the software was called: windows