Creating collection vs. materialized view - better performance?
Hi, I am trying to improve the performance of our application and am looking at everything possible. I am wondering if the use of multiple, complex collections is slowing down our application. Would the use of materialized views, as opposed to collections improve things? thanks Karen
to provide more info....
here is the process which creates the list of species based on favorite species identified (and followed by the query to select from this collection)
declare
yes_are NUMBER;
pCount NUMBER;
l_seq_id NUMBER;
yes_hms NUMBER;
found_area NUMBER;
found_unit NUMBER;
unitmeasure VARCHAR2(2);
pbCount NUMBER;
pbPrice NUMBER;
begin
--create license collection so that if error on a submit the information retains
if apex_collection.collection_exists('LICENSE_COLLECTION') then
apex_collection.delete_collection('LICENSE_COLLECTION');
end if;
--create vessel collection so that if error on a submit the information retains
if apex_collection.collection_exists('SUPVES_COLLECTION') then
apex_collection.delete_collection('SUPVES_COLLECTION');
end if;
apex_collection.create_or_truncate_collection('FP_COLLECTION');
--create collection to save landings
apex_collection.create_or_truncate_collection('SPECIES_COLLECTION');
--loop through the favorite species and populate with pre-existing data
for rec IN (select *
from frequent_species
where permit_id = :G_PERMIT_ID
order by fav_order)
LOOP
-- check to see if there is a priceboard entry for the favorite species
select count(*) into pbCount
from price_board
where permit_id = :G_PERMIT_ID and
species_itis = rec.species_itis and
grade_code = rec.grade_code and
market_code = rec.market_code and
unit_of_measure = rec.unit_measure and
price is not null;
-- if there is a price board entry
if pbCount = 1 then
--get the default price for that species combination
select price into pbPrice
from price_board
where permit_id = :G_PERMIT_ID and
species_itis = rec.species_itis and
grade_code = rec.grade_code and
market_code = rec.market_code and
unit_of_measure = rec.unit_measure and
price is not null;
--add landings row with price board data
l_seq_id := apex_collection.add_member('SPECIES_COLLECTION',
null,
null,
null,
rec.species_itis,
rec.grade_code,
rec.market_code,
rec.unit_measure,
nvl(rec.disposition_code,:G_FIRST_DISPOSITION),
0, null,pbPrice,null);
-- no price board entry
else
-- add landings row without any priceboard data
l_seq_id := apex_collection.add_member('SPECIES_COLLECTION',
null,
null,
null,
rec.species_itis,
rec.grade_code,
rec.market_code,
rec.unit_measure,
nvl(rec.disposition_code,:G_FIRST_DISPOSITION),
0, null,null,null);
end if;
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>14,
p_attr_value => 'ERROR');
--set first disposition
:G_FIRST_DISPOSITION := nvl(rec.disposition_code,:G_FIRST_DISPOSITION);
found_area:=0;
-- All rows need to be checked to determine if additional info is needed based on partner_options table
-- check if AREA will be needed
select count(*) into found_area
from partner_options
where partner_id = :G_ISSUING_AGENCY and
substr(species_itis,1,6) = rec.species_itis and
option_type = 'ARE' and
nvl(inactivate_option_date, sysdate) >= sysdate;
-- landing row requires AREA data
if found_area > 0 then
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>13,
p_attr_value => 'Y');
-- landing row does NOT require AREA data
else
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>13,
p_attr_value => 'N');
end if;
found_unit := 0;
-- check if COUNT will be needed
select count(*) into found_unit
from partner_options
where partner_id = :G_ISSUING_AGENCY and
substr(species_itis,1,6) = rec.species_itis and
option_type = 'LBC' and
nvl(inactivate_option_date, sysdate) >= sysdate;
-- landing row requires UNIT data
if found_unit > 0 then
select unit_measure into unitmeasure
from partner_options
where partner_id = :G_ISSUING_AGENCY and
substr(species_itis,1,6) = rec.species_itis and
option_type = 'LBC' and nvl(inactivate_option_date, sysdate) >= sysdate;
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>17,
p_attr_value => 'Y');
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>19,
p_attr_value => unitmeasure);
--landing row does NOT require UNIT data
else
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq => l_seq_id,
p_attr_number =>17,
p_attr_value => 'N');
end if;
-- check if HMS
SELECT count(*) into yes_hms
FROM HMSSpecies a
where hmsspeciesitis = rec.species_itis;
-- landing row requires HMS data
if yes_hms > 0 and rec.grade_code = '10' then
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq=> l_seq_id,
p_attr_number=>20,
p_attr_value=>'Y');
else
-- landing row does NOT require HMS data
apex_collection.update_member_attribute(p_collection_name=>'SPECIES_COLLECTION',
p_seq=> l_seq_id,
p_attr_number=>20,
p_attr_value=>'N');
end if;
end loop;
end;
and the query for the region:
SELECT
apex_item.text(1,seq_id,'','','id="f01_#ROWNUM#"','','') "DeleteRow",
apex_item.text_from_LOV(c004,'SPECIES')||'-'||apex_item.text_from_LOV(c005,'GRADE')||'-'||apex_item.text_from_LOV(c006,'MARKETCODE')||'-'||apex_item.text_from_LOV_query(c007,'select unit_of_measure d, unit_of_measure r from species_qc') unit,
apex_item.select_list_from_LOV(6,c008,'DISPOSITIONS','onchange="getAllDisposition(#ROWNUM#)"','YES','0',' -- Select Favorite -- ','f06_#ROWNUM#','') Disposition,
apex_item.select_list_from_LOV(7,c009,'GEARS','style="background-color:#FBEC5D; "onFocus="checkGearPreviousFocus(#ROWNUM#);"onchange="getAllGears(#ROWNUM#)"','YES','0','-- Select Favorite --','f07_#ROWNUM#','') Gear,
apex_item.text(8,TO_NUMBER(c010),5,null,'onchange="setTotal(#ROWNUM#)"','f08_#ROWNUM#','') Quantity,
apex_item.text(9,TO_NUMBER(c011),5,null,'onchange="getPriceBoundaries(#ROWNUM#)"','f09_#ROWNUM#','') Price,
apex_item.text(10, TO_NUMBER(c012),5,null, 'onchange="changePrice(#ROWNUM#)" onKeyPress="selectDollarsFocus(#ROWNUM#);"','f10_#ROWNUM#','') Dollars,
apex_item.select_list_from_LOV_XL(11, c014,'AREAFISHED','style="background-color:#FBEC5D; "onchange="getAllAreaFished(#ROWNUM#)"','YES','ERROR','-- Select Area Fished --','f11_#ROWNUM#','') Area_Fished,
apex_item.text(12, c018,4,null,'style="background-color:#FBEC5D; "onBlur="setUnitQuantity(#ROWNUM#)"','f12_#ROWNUM#','') UNIT_QUANTITY,
apex_item.text(13, 'CN',3,null,'readOnly=readOnly','f13_#ROWNUM#','') UNIT_COUNT,
apex_item.checkbox(14,'Y','id="f14_#ROWNUM#" style="background-color:#FBEC5D; " onClick="alterYes(#ROWNUM#);" onKeyPress="alterYes(#ROWNUM#);"',c021) FinsAttached,
apex_item.checkbox(15,'N','id="f15_#ROWNUM#" style="background-color:#FBEC5D; " onClick="alterNo(#ROWNUM#);" onKeyPress="alterNo(#ROWNUM#);"',c022) FinsNotAttached,
apex_item.checkbox(16,'U','id="f16_#ROWNUM#" style="background-color:#FBEC5D; " onClick="alterUnk(#ROWNUM#);" onKeyPress="alterUnk(#ROWNUM#);"',c023) FinsUnknown
from apex_collections
where collection_name = 'SPECIES_COLLECTION' order by seq_id
/
Similar Messages
-
Error While Creating Fast Refresh Materialized view.
Table Scripts:
CREATE TABLE CONTRACT_MASTER
CONTRACT_SEQ NUMBER(10) NOT NULL,
PDN CHAR(5) NOT NULL,
APPID NUMBER(10) NOT NULL,
CONTRACT_LOB_DESC VARCHAR2(20) NOT NULL,
CUSTOMER_NAME VARCHAR2(57) NOT NULL,
CONTRACT_DT DATE NOT NULL,
CONTRACT_RECD_DT DATE NOT NULL,
HELD_OFFERING_DT DATE NOT NULL,
DRAFT_AMT NUMBER(15,2) NOT NULL,
STATUS_DESC VARCHAR2(20) NOT NULL,
GIF_UPLOAD_TM TIMESTAMP NOT NULL
CREATE table CONTRACT_COMMENTS
CONTRACT_COMMENTS_SEQ NUMBER(10) NOT NULL,
APPID NUMBER(10) NOT NULL,
COMMENTS VARCHAR2(1000) NOT NULL,
GIF_UPLOAD_TM TIMESTAMP NOT NULL
Constraints on tables
ALTER TABLE CONTRACT_MASTER ADD
CONSTRAINT XPKCONTRACT_MASTER PRIMARY KEY (CONTRACT_SEQ) USING INDEX ;
ALTER TABLE CONTRACT_COMMENTS ADD
CONSTRAINT XPKCONTRACT_COMMENTS PRIMARY KEY (CONTRACT_COMMENTS_SEQ) USING INDEX ;
alter table CONTRACT_MASTER add CONSTRAINT XUIAPPCONTRACT_MASTER UNIQUE (APPID) USING INDEX;
CREATE INDEX XUIAPPCONTRACT_COMMENTS ON
CONTRACT_COMMENTS(APPID) ;
Materialized View Creation:
CREATE MATERIALIZED VIEW LOG ON CONTRACT_MASTER WITH PRIMARY KEY,ROWID;
CREATE MATERIALIZED VIEW LOG ON CONTRACT_COMMENTS WITH PRIMARY KEY, ROWID;
CREATE MATERIALIZED VIEW MV_CONTRACT_COMMENTS_HELDOFFERING
REFRESH FAST
ENABLE QUERY REWRITE AS
SELECT APPID,COMMENTS FROM CONTRACT_COMMENTS WHERE APPID IN (
SELECT APPID FROM CONTRACT_MASTER WHERE STATUS_DESC = 'Held Offering' )
Errors generated:
ERROR at line 4:
ORA-12015: cannot create a fast refresh materialized view from a complex query
_*Afer That I have changed the query but still it was not created like:*_
CREATE MATERIALIZED VIEW MV_CONT_COMMNTS_HELDOFFERNG
REFRESH FAST
ENABLE QUERY REWRITE AS
SELECT CONTRACT_COMMENTS_SEQ,c.APPID,COMMENTS
FROM CONTRACT_COMMENTS c,CONTRACT_MASTER m
WHERE m.APPID = c.APPID and m.STATUS_DESC = 'Held Offering'
*even though error displayed:
SQL> CREATE MATERIALIZED VIEW MV_CONT_COMMNTS_HELDOFFERNG*
2 REFRESH FAST
3 ENABLE QUERY REWRITE AS
4 SELECT CONTRACT_COMMENTS_SEQ,c.APPID,COMMENTS
5 FROM CONTRACT_COMMENTS c,CONTRACT_MASTER m
6 WHERE m.APPID = c.APPID and m.STATUS_DESC = 'Held Offering';
FROM CONTRACT_COMMENTS c,CONTRACT_MASTER m
ERROR at line 5:
ORA-12052: cannot fast refresh materialized view GSSIO.MV_CONT_COMMNTS_HELDOFFERNG
*Again I have done "Analyzing Materialized Views for Fast Refresh" as follows:*
1: exec dbms_mview.explain_mview('MV_CONT_COMMNTS_HELDOFFERNG');
2: SELECT capability_name, possible, SUBSTR(msgtxt,1,60) AS msgtxt
FROM mv_capabilities_table
WHERE capability_name like '%FAST%';
Output is :
CAPABILITY_NAME P MSGTXT
REFRESH_FAST N
REFRESH_FAST_AFTER_INSERT N the SELECT list does not have the rowids of all the detail t
REFRESH_FAST_AFTER_ONETAB_DML N see the reason why REFRESH_FAST_AFTER_INSERT is disabled
REFRESH_FAST_AFTER_ANY_DML N see the reason why REFRESH_FAST_AFTER_ONETAB_DML is disabled
REFRESH_FAST_PCT N PCT is not possible on any of the detail tables in the mater
Please suggest what to do to implement fast refresh materialized view for same.Edited by: dba on Sep 20, 2010 12:00 AMIf the two MVs have to be consistent with each other as of a specific time, put them into a Refresh Group and refresh them with DBMS_MVIEW.REFRESH
If an MV is dependent on another, use DBMS_MVIEW.REFRESH_DEPENDENT
See the "Oracle® Database PL/SQL Packages and Types Reference" documentation pages for DBMS_MVIEW.
Hemant K Chitale
http://hemantoracledba.blogspot.com --- this is NOT a documentation site.
Edited by: Hemant K Chitale on Sep 20, 2010 5:19 PM -
Can I create index on Materialized view log
Hello
The ADDM suggest me to create index on some fields of my materialized view log , I don't know does it cause any problem ? Is it safe ? have you done it before ?
thanksActually you can do it since materialized view log is in fact a table.
SQL> create table t(x int primary key);
Table created.
SQL> create materialized view log on t;
Materialized view log created.
SQL> select segment_name, segment_type from user_segments;
SEGMENT_NAME
SEGMENT_TYPE
MLOG$_T
TABLE
T
TABLE
SYS_C004857
INDEX
SQL> desc mlog$_t;
Name Null? Type
X NUMBER
SNAPTIME$$ DATE
DMLTYPE$$ VARCHAR2(1)
OLD_NEW$$ VARCHAR2(1)
CHANGE_VECTOR$$ RAW(255)
SQL> create index i on mlog$_t(x);
Index created.However I don't know if this is really supported and makes sense. -
How to create types of materialized views
Hi
Can you please tell me how to create vaious types of materialized view.Also please tell me differences among them.Oracle docs at tahiti.oracle.com contain exactly the info you need as said previous poster. You can look into SQL reference about MV create statement that contains a brief overview of all types as well as data warehousing guide which contains at least 4 chapters that are about MVs - Basic MV, Advanced MV, Basic query rewrite and Advanced query rewrite.
Gints Plivna
http://www.gplivna.eu -
Unable to create a Materialized View
I have this query to generate continous dates for the given number of months (12 in this case).
(SELECT ADD_MONTHS(TO_DATE('2007-01-01', 'yyyy-mm-dd'), rownum - 1) Transaction_Date_Month
FROM DUAL
CONNECT BY level <= 12)I am using this query alongside with another query to get some results. I want to put the whole query what i have in a "Materialized View". But it is not allowing me to create the materialized view becuase of using "rownum". So how can i avoid "rownum" for getting all the dates and also use it in Materialized View.Why do you want to create this a materialized view?
I presume the date changes dynamically somehow otherwise you'd want to use a table
What is the actual date range you want to use?
Would you be better off using a materialized subquery using WITH?
WITH subq_months AS
(SELECT /*+materialize */ADD_MONTHS(TO_DATE('2007-01-01', 'yyyy-mm-dd'), rownum - 1) Transaction_Date_Month FROM DUAL CONNECT BY level <= 12)
SELECT -- use months here somehow --
FROM subq_months -
Performance difference between tables and materialized views
hi ,
I created a materialized view on a query that involves partition table in it.
When i used the same query and created a table out of it <create table xyz as select * from (the query)> ,the table got created quickly.
So does that mean performance wise creating table is faster than creating/refreshing the materialized view ?or is that due to the refresh method i use ?Currently i use a complete refreshI created a materialized view on a query that involves partition table in it.
When i used the same query and created a table out of it <create table xyz as select * from (the query)> ,the table got created quickly.
So does that mean performance wise creating table is faster than creating/refreshing the materialized view ?or is that due to the refresh method i use ?Currently i use a complete refresh Well, for starters, if you created the materialized view first and then the standard table, the data for the second one has already been fetched recently and so will reduce your I/O due to caching, and will therefore be quicker. There are also other factors such as the materialized view creating other internal bits that are required to allow for refreshes to be done quickly, such as the primary key etc which you haven't created on your second creation.
What you have shown is that two completely different statements running at different times, appear to operate with different speed. It is not a comparison of whether the materialized view is slower or quicker than the create table statement. -
How can I create a materialized view based on hierarchical cube query?
Hi,
database version 10gR2.
When i try to create MV for sql below, i got error .
I tried creating MV log in several ways, but still, keep getting the same error.
SQL Error: ORA-12015: cannot create a fast refresh materialized view from a complex query
12015. 00000 - "cannot create a fast refresh materialized view from a complex query"
*Cause: Neither ROWIDs and nor primary key constraints are supported for
complex queries.
*Action: Reissue the command with the REFRESH FORCE or REFRESH COMPLETE
option or create a simple materialized view.So, I wonder if it is possible to create MV based on sql below?
if yes, how should I do it?
if no, what is the alternative?
select
coalesce(UP_ORG_ID_6, UP_ORG_ID_5, UP_ORG_ID_4, UP_ORG_ID_3, UP_ORG_ID_2, UP_ORG_ID_1) as ORG_ID,
a.day_id as day_id,
a.TRADE_TYPE_ID as TRADE_TYPE_ID,
a.CUST_ID,
coalesce(UP_CODE_6, UP_CODE_5, UP_CODE_4, UP_CODE_3, UP_CODE_2, UP_CODE_1) as product_id,
QUANTITY_UNIT,
COST_UNIT,
A.SOURCE_ID as SOURCE_ID,
SUM(CONTRACT_AMOUNT) as CONTRACT_AMOUNT,
SUM(CONTRACT_COST) as CONTRACT_COST,
SUM(SALE_AMOUNT) as SALE_AMOUNT,
SUM(SALE_COST) as SALE_COST,
SUM(ACTUAL_AMOUNT) as ACTUAL_AMOUNT,
SUM(ACTUAL_COST) as ACTUAL_COST,
SUM(TRADE_COUNT) as TRADE_COUNT
from DM_F_LO_SALE_DAY a, DM_D_ALL_ORG_FLAT B, DM_D_ALL_PROD_FLAT D
where a.ORG_ID=B.ORG_ID
and a.PRODUCT_ID=D.CODE
and a.day_id=20110201
group by rollup(UP_ORG_ID_1, UP_ORG_ID_2, UP_ORG_ID_3, UP_ORG_ID_4, UP_ORG_ID_5, UP_ORG_ID_6),
a.TRADE_TYPE_ID,
a.day_id,
A.CUST_ID,
rollup(UP_CODE_1, UP_CODE_2, UP_CODE_3, UP_CODE_4, UP_CODE_5, UP_CODE_6),
a.QUANTITY_UNIT,
a.COST_UNIT,
a.SOURCE_ID;Thanks in advance.Rob vanWjik has an excellent series of fast refresh materialized views starting here:
http://rwijk.blogspot.com/2009/05/fast-refreshable-materialized-view.html
Part three specifically on aggregate MVs is here:
http://rwijk.blogspot.com/2009/06/fast-refreshable-materialized-view.html -
How to create a Complex Organization Index Materialized View Example
Hi
I have a 11g database that I'm trying to create a complex Materialized View that I would like to make Organization Index? How do I specify what I want for a primary Key?
CREATE MATERIALIZED VIEW RCS_STG.MV_NEXT_HOP_iot
ORGANIZATION INDEX
AS
SELECT r2.resource_key, r1.resource_key resource_key2, r2.resource_full_path_name, device_name, device_model,
service_telephone_number, service_package_name, telephone_number.telephone_number_key, c1.created_on
FROM network_resource PARTITION (network_resource_subinterface) r1,
connection c1,
network_resource PARTITION (network_resource_subinterface) r2,
device d1,
tn_network_resource,
telephone_number
WHERE r1.resource_key = c1.resource1_key
AND c1.resource2_key = r2.resource_key
AND d1.device_key = r2.device_key
AND tn_network_resource.resource_key(+) = r2.resource_key
AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
UNION ALL
SELECT r1.resource_key, r2.resource_key resource_key2, r1.resource_full_path_name, device_name, device_model,
service_telephone_number, service_package_name, telephone_number.telephone_number_key, c1.created_on
FROM network_resource PARTITION (network_resource_subinterface) r1,
connection c1,
network_resource PARTITION (network_resource_subinterface) r2,
device d1,
tn_network_resource,
telephone_number
WHERE r1.resource_key = c1.resource1_key
AND c1.resource2_key = r2.resource_key
AND d1.device_key = r1.device_key
AND tn_network_resource.resource_key(+) = r1.resource_key
AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
I get an error message ORA-25175: no PRIMARY KEY constraint found
I would like to specify resource_key, resource_key2, and service_telephone_number as my primary key?Ah,
I get it now. This is what I did.
CREATE TABLE mv_next_hop_iot
resource_key NUMBER (38),
resource_key2 NUMBER (38),
resource_full_path_name VARCHAR2 (256 BYTE),
device_name VARCHAR2 (64 BYTE),
device_model VARCHAR2 (64 BYTE),
service_telephone_number VARCHAR2 (20 BYTE),
service_package_name VARCHAR2 (64 BYTE),
telephone_number_key NUMBER (38),
created_on DATE,
CONSTRAINT mv_next_hop_pk PRIMARY KEY (resource_key, resource_key2, service_telephone_number)
ORGANIZATION INDEX
CREATE MATERIALIZED VIEW rcs_stg.mv_next_hop_iot
ON PREBUILT TABLE
AS
/* Formatted on 2010/06/10 1:39:04 PM (QP5 v5.149.1003.31008) */
SELECT resource_key, resource_key2, resource_full_path_name, device_name, device_model, service_telephone_number,
service_package_name, telephone_number_key, created_on
FROM (SELECT r2.resource_key, r1.resource_key resource_key2, r2.resource_full_path_name, device_name, device_model,
NVL (service_telephone_number, ' ') AS service_telephone_number, service_package_name,
telephone_number.telephone_number_key, c1.created_on
FROM network_resource PARTITION (network_resource_subinterface) r1,
connection c1,
network_resource PARTITION (network_resource_subinterface) r2,
device d1,
tn_network_resource,
telephone_number
WHERE r1.resource_key = c1.resource1_key
AND c1.resource2_key = r2.resource_key
AND d1.device_key = r2.device_key
AND tn_network_resource.resource_key(+) = r2.resource_key
AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key
UNION ALL
SELECT r1.resource_key, r2.resource_key resource_key2, r1.resource_full_path_name, device_name, device_model,
NVL (service_telephone_number, ' ') AS service_telephone_number, service_package_name,
telephone_number.telephone_number_key, c1.created_on
FROM network_resource PARTITION (network_resource_subinterface) r1,
connection c1,
network_resource PARTITION (network_resource_subinterface) r2,
device d1,
tn_network_resource,
telephone_number
WHERE r1.resource_key = c1.resource1_key
AND c1.resource2_key = r2.resource_key
AND d1.device_key = r1.device_key
AND tn_network_resource.resource_key(+) = r1.resource_key
AND telephone_number.telephone_number_key(+) = tn_network_resource.telephone_number_key)
Many thanks. the PREBUILT TABLE is the secret. -
Error in creating materialized view
Hi all,
I am trying to create the following materialized view, but throwing me the error message below
CREATE MATERIALIZED VIEW "MVIW"."XXFA_R051_SHT2_AMV"
(PARTITION BY LIST (PERIOD_YEAR)
PARTITION YEAR2006 VALUES LESS ('2006'),
PARTITION YEAR2007 VALUES LESS ('2007'),
PARTITION YEAR2007 VALUES LESS ('2008'))
TABLESPACE "MVIEW"
BUILD IMMEDIATE
USING INDEX
REFRESH FORCE ON DEMAND
USING DEFAULT LOCAL ROLLBACK SEGMENT
DISABLE QUERY REWRITE
AS (SELECT * FROM XXFA_R051_SHT2_MV);
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Any pointers would be appreciated
Thanks
VRWhat is it your are actually trying to do?
On one hand you say:
PARTITION BY LIST (PERIOD_YEAR)
Then you proceed to use the syntax for range partitioning:
VALUES LESS ('2006'),
Look up the correct syntax at http://tahiti.oracle.com or the demos in Morgan's Library at www.psoug.org. -
Create Materialized View with GROUP BY
I have a table
treecluster NUMBER(3)
treenumber NUMBER(3)
treedate DATE
nestnumber NUMBER(3)
eggs NUMBER(3)
nestlings NUMBER(3)
fledglings NUMBER(3)
nestfate VARCHAR2(10)
nestfailurecode NUMBER(2)
I want to group the data by treecluster, treenumber, year, and nest number and get a max eggs, nestlings, fledglings. I am doing this with the following:
SELECT treecluster, treenumber, to_char(nestchecksdate, 'YYYY'), nestnumber,
max(eggs), max(nestlings), max(fledglings)
FROM nestchecks
GROUP BY treecluster, treenumber, to_char(nestchecksdate, 'YYYY'), nestnumber;
This works fine.
The last record for a year has a nestfate and nestfailurecode value.
I need to group all information and then also get the nestfate and nestfailurecode for the year. How do I go about getting this information?
I am really trying to create a summary materialized view based on a data table so the select I am trying to craft would be a part of a create materialized view as SELECT...
so I want to be able to group the info and add in the nestfate and failurecode in one step.
Thanks!try this:
SQL> select * from table_tree;
TREECLUSTER TREENUMBER NESTCHECK NESTNUMBER EGGS NESTLINGS FLEDGLINGS NESTFATE NESTFAILURECODE
4 167 17-MAY-00 2 0 0
4 167 24-MAY-00 2 3 0
4 167 30-MAY-00 2 3 0
4 167 12-JUN-00 2 0 1 FAILURE 2
select a.treecluster, a.treenumber, to_char(a.nestyear,'YYYY') nestyear,
a.nestnumber, a.eggs, a.nestlings, a.fledglings, a.nestfate, a.nestfailurecode
from (select max(treecluster) treecluster, max(treenumber) treenumber,
max(nestchecksdate) nestyear,
max(nestnumber) nestnumber, max(eggs) eggs, max(nestlings) nestlings,
nvl(max(FLEDGLINGS),0) FLEDGLINGS, max(NESTFATE) NESTFATE,
max(nestfailurecode) nestfailurecode
from table_tree) a
TREECLUSTER TREENUMBER NEST NESTNUMBER EGGS NESTLINGS FLEDGLINGS NESTFATE NESTFAILURECODE
4 167 2000 2 3 1 0 FAILURE 2hope this helps -
ORA-12015: cannot create a fast refresh materialized view from a complex q
Hi,
I'm facing very strange problem. Please help me why this error is coming
I'm creating a simple materialized view, but it is giving below error since this is simple select * from.
CREATE MATERIALIZED VIEW EFMS.MS_TASK
BUILD IMMEDIATE
REFRESH FAST
START WITH SYSDATE
NEXT (SYSDATE + 1/24)
WITH ROWID
AS
SELECT * FROM MS_TASK@efms_link;
SELECT * FROM MS_TASK@efms_link
ERROR at line 8:
ORA-12015: cannot create a fast refresh materialized view from a complex query
CREATE MATERIALIZED VIEW LOG ON MSDBO.MS_TASK
TABLESPACE DBOR_MVLOG
PCTUSED 0
PCTFREE 60
INITRANS 20
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
NOCACHE
NOLOGGING
PARALLEL ( DEGREE 2 INSTANCES 1 )
WITH ROWID, PRIMARY KEY
EXCLUDING NEW VALUES;1º
Not is a best practice to use 'select *'
2º
ORA-12015: cannot create a fast refresh materialized view from a complex query
Cause: Neither ROWIDs and nor primary key constraints are supported for complex queries.
Action: Reissue the command with the REFRESH FORCE or REFRESH COMPLETE option or create a simple materialized view.
Then you have to change REFRESH FAST or create a primary key in MS_TASK@efms_link to avility fast refresh.
. :-) any help with my english is wellcome :-) . -
Error Creating Materialized View With a Job
Oracle 9ir2
I've created a job like this in a java class:
...Java Code ...
cs = conn.prepareCall ("DECLARE v_job NUMBER; BEGIN DBMS_JOB.SUBMIT(v_job,'begin CTH_REGENERA_VM; end;', TRUNC(SYSDATE+1) + (3/24)); END;");
...Java Code ...
The Procedure called in the Job:
CREATE OR REPLACE PROCEDURE CTH_REGENERA_VM
AUTHID CURRENT_USER IS
existe NUMBER(1);
cur BINARY_INTEGER := DBMS_SQL.OPEN_CURSOR;
fdbk BINARY_INTEGER;
BEGIN
SELECT count(*) INTO existe FROM user_mviews WHERE mview_name = 'CTH_PRESENTA_A_VM';
IF existe > 0 THEN
DBMS_SQL.PARSE(cur, 'DROP MATERIALIZED VIEW CTH_PRESENTA_A_VM', DBMS_SQL.NATIVE);
fdbk := DBMS_SQL.EXECUTE(cur);
INSERT INTO CTH_HISTORIAL VALUES('ELIMINADA VM CTH_PRESENTA_A_VM', SYSDATE);
COMMIT;
END IF;
DBMS_SQL.PARSE(cur, 'CREATE MATERIALIZED VIEW CTH_PRESENTA_A_VM
TABLESPACE DAT1_CTH
STORAGE(INITIAL 16M NEXT 8M MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0)
XMLTYPE XML STORE AS CLOB ( TABLESPACE DAT1_CTH
STORAGE(INITIAL 16M NEXT 8M MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0))
AS select FICHA, XML,
extractvalue(xml, ''/FICHE/Encab_de_nombre_geogr�fico_a'') as MUNICIPIO,
extractvalue(xml, ''/FICHE/Encab_de_nombre_geogr�fico_c'') as CALIFICACION,
extractvalue(xml, ''/FICHE/Encab_de_nombre_geogr�fico_b'') as PROVINCIA,
extractvalue(xml, ''/FICHE/Encab_tem�tico_de_materia_a[1]'') as MATERIA,
extractvalue(xml, ''/FICHE/Fecha_cronol�gica_b[1]'') as FECHA,
extractvalue(xml, ''/FICHE/Datos_matem�ticos_a[1]'') as ESCALA
from cth_xmltable', DBMS_SQL.NATIVE);
INSERT INTO CTH_HISTORIAL VALUES('ASIGNO EL PARSE DE MATERIALIZED', SYSDATE);
fdbk := DBMS_SQL.EXECUTE(cur);
INSERT INTO CTH_HISTORIAL VALUES('EJECUTO EL PARSE DE MATERIALIZED', SYSDATE);
INSERT INTO CTH_HISTORIAL VALUES('CREADA VM CTH_PRESENTA_A_VM', SYSDATE);
DBMS_SQL.PARSE(cur, 'CREATE INDEX CTH_INDEX1
ON CTH_PRESENTA_A_VM(XML)
INDEXTYPE IS CTXSYS.CONTEXT
PARAMETERS (''storage cth section group ctxsys.auto_section_group'')', DBMS_SQL.NATIVE);
fdbk := DBMS_SQL.EXECUTE(cur);
INSERT INTO CTH_HISTORIAL VALUES('CREADO INDICE ORACLE TEXT CTH_INDEX1', SYSDATE);
DBMS_SQL.PARSE(cur, 'CREATE INDEX CTH_IDX_MUNICIPIO3
ON CTH_PRESENTA_A_VM(UPPER(MUNICIPIO))
TABLESPACE IDX1_CTH
STORAGE (INITIAL 1M NEXT 512K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0)', DBMS_SQL.NATIVE);
fdbk := DBMS_SQL.EXECUTE(cur);
INSERT INTO CTH_HISTORIAL VALUES('CREADO INDICE CTH_IDX_MUNICIPIO2', SYSDATE);
DBMS_SQL.PARSE(cur, 'CREATE INDEX CTH_IDX_FICHA2
ON CTH_PRESENTA_A_VM
(FICHA)
TABLESPACE IDX1_CTH
STORAGE(INITIAL 1M NEXT 512K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0)', DBMS_SQL.NATIVE);
fdbk := DBMS_SQL.EXECUTE(cur);
INSERT INTO CTH_HISTORIAL VALUES('CREADO INDICE CTH_IDX_FICHA2', SYSDATE);
DBMS_SQL.CLOSE_CURSOR(cur);
COMMIT;
END;
I got always an error in the created materialized view. If I call the procedure with SQL Plus, it run ok. The user
has CTXAPP, DBA roles, so I supouse it is not a privileges problem. I also tried to create a simple materialized view or a table, and always got an error ora-12011
Thanks in advance.If I call the procedure with SQL Plus, it run ok. Are you using the same user to run it in SQL*Plus as runs it from Java.
The normal reason for procedures to fail like this is privileges. Particularly, we cannot run procedures using privileges we have been granted through roles.
The user has CTXAPP, DBA roles, so I supouse it is not a privileges problem. Try granting the system privilege CREATE MATERIALIZED VIEW to the user and see what happens.
I drop the materialized and create again, cause it's the fastest way I've found. With a DBMS_MVIEW.REFRESH is too slow.I find that surprising as drop & create has to do all the work that a refresh has to do plus some more - maybe it's something to do with XML. Did you try adding a snapshot log and going for FAST? I don't know whwther the XML procesing would render the view complex - have you explained it?
Cheers, APC -
Create materialized view throws insufficient privileges in single schema
I'm trying to create a complex materialized view in my own schema, using only tables from my own schema:
CREATE MATERIALIZED VIEW MYSCHEMA.MYMVIEW AS
SELECT
A.ONE_THING,
B.ANOTHER_THING,
C.A_THIRD_THING
FROM MYSCHEMA.TABLEA A
JOIN MYSCHEMA.TABLEB B
ON A.COL1 = B.COL1
JOIN MYSCHEMA.TABLEC C
ON A.COL2 = C.COL2The line JOIN MYSCHEMA.TABLEB B throws an ORA-01031: insufficient privileges error, highlighting TABLEB.
I understand that grants need to be explicit on tables when creating objects across schemas, but this code is operating within my own schema only; i created and own all the tables in this schema.
What's going on?
Thanks!Perhaps it is the tool that i am using that highlights the wrong item, because as it turns out, i don't have the CREATE MATERIALIZED VIEW permission after all (the permission was mistakenly granted to a different user instead of to me).
SELECT * FROM SESSION_PRIVS;returns CREATE VIEW, but does not return CREATE MATERIALIZED VIEW.
Sorry to have wasted your time. -
Problem in creating MATERIALIZED VIEW
Hello All,
I am trying to create the following materialized view and getting this error
SQL> CREATE MATERIALIZED VIEW system_active_loss_mv
2 BUILD IMMEDIATE
3 REFRESH FAST ON COMMIT
4 ENABLE QUERY REWRITE
5 AS
6 SELECT zone_name,
7 EXTRACT(YEAR FROM active_loss_datetime)|| EXTRACT(MONTH FROM active_loss_datetime) as
active_loss_period,
8 count(*) ,
9 count(active_qloss),
10 SUM(active_qloss) as active_qloss,
11 SUM(active_ploss) as active_ploss,
12 SUM(active_gain) as active_gain
13 FROM system_active_loss_day
14 GROUP BY zone_name,
15 EXTRACT(YEAR FROM active_loss_datetime),
16 EXTRACT(MONTH FROM active_loss_datetime);
FROM system_active_loss_day
ERROR at line 13:
ORA-01031: insufficient privileges
what is the error?Hello Andrew,
Thanks for your reply, after granting the necessary priviliges i executed the query again this time i got the following error
SQL> CREATE MATERIALIZED VIEW system_active_loss_mv
2 BUILD IMMEDIATE
3 REFRESH FAST ON COMMIT
4 ENABLE QUERY REWRITE
5 AS
6 SELECT zone_name,
7 EXTRACT(YEAR FROM active_loss_datetime)|| EXTRACT(MONTH FROM active_loss_datetime) as
active_loss_period,
8 count(*) ,
9 count(active_qloss),
10 SUM(active_qloss) as active_qloss,
11 SUM(active_ploss) as active_ploss,
12 SUM(active_gain) as active_gain
13 FROM system_active_loss_day
14 GROUP BY zone_name,
15 EXTRACT(YEAR FROM active_loss_datetime),
16 EXTRACT(MONTH FROM active_loss_datetime);
FROM system_active_loss_day
ERROR at line 13:
ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
when i removed the 'REFRESH FAST ON COMMIT' from above query the view has created...but we want this to be refreshed everytime we insert a new record in the base table. -
Illegal use of LONG datatype error message when i create materialized view
Hello to all
I want create read only materialized view replication environment two of our tables have LONG datatype when i create materialized view against on them
I recieve this error message
CREATE MATERIALIZED VIEW MDB.TOAD_PLAN_TABLE TABLESPACE aramis REFRESH FORCE WITH ROWID AS SELECT * FROM MDB.TOAD_PLAN_TABLE@arahisto
Error report:
SQL Error: ORA-00997: illegal use of LONG datatype
00997. 00000 - "illegal use of LONG datatype"
Do you know any resort solution for it?
thanksYou can not use longs in materialized views over a database link, you can however take a part of a long over to a materialized view.
I have gotten this to work in the past l had to create a PL/SQL function that you can use to extract the character data from the long column and use that to
as part of the function you will need to pass in the columns of the table that will identify the unique records so you can pick out the long column
example function
-- you will need to make sure this funtion is in the remote location as you can not select longs accross a DB LINK.
CREATE OR REPLACE FUNCTION MDB.TOAD_PLAN_LONG_CONV
(pass in the primary key columns for the table)
RETURN VARCHAR2
IS
v_long VARCHAR2(32767) ;
BEGIN
BEGIN
-- need to select the long column into the PL/SQL variable
SELECT long_column
INTO v_long
FROM MDB.TOAD_PLAN_TABLE
WHERE key_columns = passed columns ;
EXCEPTION
WHEN OTHERS THEN
IF SQLCODE = '-01406' THEN
NULL ;
ELSE
RAISE ;
END IF ;
END ;
RETURN SUBSTR(v_long,1,4000) ;
END ;
Then when you create the materialized view utilize that function on the long column.
create or replace materialized view MDB.TOAD_PLAN_TABLE TABLESPACE aramis REFRESH FORCE WITH ROWID
AS
SELECT column1, .... columnx,
MDB.TOAD_PLAN_LONG_CONV@arahisto (primary key column list) as long_column_name
FROM MDB.TOAD_PLAN_TABLE@arahisto ;
See if this will work for you? Keep in mind however this solution will not get the entire long column only as much as a PL/SQL variable will hold of it.
Mike
Maybe you are looking for
-
How to get all the data stored on a table?
Hi. I'm tryng to get all the data stored on a database table but I'm losing in trouble. I've looked for a soloution to my problem in the forums but each post I follow related to this issue gives me a different way to solve the problem and no one work
-
Mid 2009 13" MBP iSight camera bad picture quality in photo booth
My daughter's stock mid 2009 13" MBP 2.26 ghz intel core two duo has a problem with the isight camera. The isight camera is built in to the screen. The isight camera works some of the time flawlessly and other times it comes out real grainy and with
-
Preview does not open a particular group of images modified in Photoshop CS
The problem described below occurs in a PowerBook G4 with Mac OS X 10.3.9 and Preview 2.1.1. This computer now refuses to open a group of .jpg images in Preview that have been modified in Adobe Photoshop CS, but opens up images that have not been mod
-
How do I re-download Adobe Photo Shop Elements 11?
My computer crashed; how do I re-download Adobe Photo Shop Elements 11?
-
ADADMIN failing after changhing APPS password
Hi After changing the aps password with FNDCPASS all ad utilities are failing with the following error. AD Administration error: DCPW null for "APPLSYS" [0] AD Administration error: Failed getting PDI list for product 'fnd' AD Administration error: a