PL/SQL Proc, execute immediate and materialized view 9.2.0.6
Hello,
Environement description: Sun Solaris 8 , Oracle database 9.2.0.6
I've a problem trying to execute this PL/SQL Procedure:
I'm loged in with PMU user
CREATE OR REPLACE PROCEDURE PMU.PROC_TEST_PMU_C035 (part_arrete in integer, part_session in integer) AS
lv_p_arrete number := part_arrete;
lv_p_session number := part_session;
lv_stmt varchar2(31000);
BEGIN
lv_stmt := ' ';
lv_stmt := lv_stmt || 'CREATE MATERIALIZED VIEW 'PMU''.''TEST_PMU_C035'' ';
lv_stmt := lv_stmt || 'TABLESPACE PMU_8M_DATA ';
lv_stmt := lv_stmt || 'BUILD IMMEDIATE ';
lv_stmt := lv_stmt || 'REFRESH COMPLETE AS ';
lv_stmt := lv_stmt || 'SELECT * FROM ACTION ';
lv_stmt := lv_stmt || 'WHERE LIBELLE IN ( ''SOCIETE 1'', ''SOCIETE 2'', ''SOCIETE 3'' ) ;';
dbms_output.put_line ( lv_stmt) ;
execute immediate ( lv_stmt);
END;
When I comment the line : execute immediate ( lv_stmt); It works fine and my statement appear on the screen:
CREATE MATERIALIZED VIEW PMU.TEST_PMU_C035 TABLESPACE PMU_8M_DATA BUILD
IMMEDIATE REFRESH COMPLETE AS SELECT LIBELLE FROM ACTION WHERE LIBELLE IN (
'SOCIETE1', 'SOCIETE2', 'SOCIETE3' ) ;
When I execute manually this query it works.
But when I try to do the execute immediate, it gives me this error:
BEGIN "PMU"."PROC_TEST_PMU_C035" ( 13, 14); END;
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at "PMU.PROC_TEST_PMU_C035", line 15
ORA-06512: at line 1
Action Table has this description and datas:
SQL> desc action
Name Null? Type
ISIN NOT NULL VARCHAR2(20)
LIBELLE VARCHAR2(100)
SQL>
ISIN LIBELLE
FR1 SOCIETE 1
FR2 SOCIETE 2
FR3 SOCIETE 3
FR4 SOCIETE 4
FR5 SOCIETE 5
FR6 SOCIETE 6
FR7 SOCIETE 7
FR8 SOCIETE 8
FR9 SOCIETE 9
FR10 SOCIETE 10
FR11 SOCIETE 11
This is a sample description of my probleme because the real case is on multiple partition tables with million rows, but the problem is the same with this sample.
My question is why it doesn't work ? Could anybody help me ?
Thanks In advance.
Loic
Yes but you did not show where you want the parametersOK this is my Original Query :
CREATE OR REPLACE PROCEDURE "PMU"."PROC_TEST_PMU_C035" (part_arrete in integer, part_session in integer)AS
lv_p_arrete integer := part_arrete;
lv_p_session integer := part_session;
lv_stmt varchar2(31000);
BEGIN
lv_stmt := 'CREATE OR REPLACE MATERIALIZED VIEW PMU.TEST_PMU_C035 ';
lv_stmt := lv_stmt || ' TABLESPACE PMU_8M_DATA ';
lv_stmt := lv_stmt || ' BUILD IMMEDIATE ';
lv_stmt := lv_stmt || ' REFRESH COMPLETE AS ';
lv_stmt := lv_stmt || ' select CD_SOCIETE, MONTANT, MOIS, TYPEDET, LIEUCONS, DETPEA, PERSPHYS, SECTDET, PAYSDET, ZONEDET, CSPDET, AGEDET, TRMONT, NATINSFI, MATURITE, MONNAIE, DEVISEISO, SECTEMT, PAYSEMT, ZONEEMT, ENCRSDEB, NBCPTIT, TYPEFLUX, CONTRAT, CODISIN, LIBELTIT, SEUILDET, PAYSCTP, NBTIT, SEUILA1, SEUILA2, SEUILM1, SEUILM2, SEUILB1, SEUILB2, SEUILQ1, SEUILQ2, TXEVOL, NBCPTITPEA, NBCPTITPPP, ';
lv_stmt := lv_stmt || ' NO_PCI || ''-'' || SECTDET || ''-'' || ZONEDET || ''-'' || MONNAIE || ''-'' || SECTEMT || ''-'' || DETPEA || ''-'' || PERSPHYS || ''-'' || (CASE WHEN TYPEDET IN (''DCL'', ''DCG'') THEN ''DCL'' ';
lv_stmt := lv_stmt || ' ELSE NVL(TYPEDET,'''') ';
lv_stmt := lv_stmt || ' END ) || ''-'' || (CASE WHEN NATINSFI in (''OBL'', ''EMT'', ''BTR'', ''CDD'', ''CDE'', ''CPP'', ''BTS'', ''MIB'') THEN ''OBL'' ';
lv_stmt := lv_stmt || ' ELSE NVL(NATINSFI,'''') ';
lv_stmt := lv_stmt || ' END) || ''-'' ||(CASE WHEN MATURITE IN (''A0'', ''A1'') THEN ''AC'' ELSE NVL(MATURITE,'''') END) || ''-'' ||(CASE WHEN PAYSEMT IN (''FR'',''MC'') THEN ''F1'' ';
lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''DE'',''AT'',''BE'',''ES'',''FI'',''GR'',''IE'',''IT'',''LU'',''NL'',''PT'',''SI'', ''4F'') THEN ''ZE'' ';
lv_stmt := lv_stmt || ' WHEN PAYSEMT IN (''BG'',''CY'',''DK'',''EE'',''HU'',''LV'',''LT'',''MT'',''PL'',''RO'',''GB'',''SK'',''SE'',''CZ'', ''4C'', ''4D'', ''4H'', ''4E'', ''4Z'', ''JE'') THEN ''ZU'' ';
lv_stmt := lv_stmt || ' ELSE ''ZR''';
lv_stmt := lv_stmt || ' END ) AS CLE';
lv_stmt := lv_stmt || ' from PMU_ESLD_ESTD partition(PMU_M13_S14) e ,';
lv_stmt := lv_stmt || ' PMU_ESLD_ESTD_SPPRO partition(PMU_M13_S14) a';
lv_stmt := lv_stmt || ' where e.PART_ARRETE = '||lv_p_arrete ;
lv_stmt := lv_stmt || ' AND e.PART_ENV = ''BCE''' ;
lv_stmt := lv_stmt || ' AND e.PART_SESSION = '||lv_p_session ;
lv_stmt := lv_stmt || ' and e.ID = a.ID_ESTD ';
lv_stmt := lv_stmt || ' and e.CD_STATUT = ''VE'' ' ;
lv_stmt := lv_stmt || ' and e.TYP_MONTANT = ''33'' ; ' ;
execute immediate lv_stmt;
END;
Thanks
Similar Messages
-
Truncate table and materialized view log
I user oracle 10 R2
I have a table and on that table a materialized view log.
I execute in a pl/sql procedure:
1) execute immediate('drop materialized view log on tab1');
then:
2) execute immediate('truncate table tab1');
3) Now I insert a lot of records in tab1
4) execute immediate('create materialized view log on tab1 WITH rowid INCLUDING NEW VALUES');
When I create the materialized view log I recieved this message:
ora32321: refresh fast on tab2 unsupported after detail table truncate
Why?Refresh fast after truncate operation on container table is not supported, regardless the container table is or is not partitioned.
Perform a refresh complete.
ORA-32321 :
Cause: A detail table has been truncated and no materialized view
supports fast refersh after a detail table has been truncated
Action: Use REFRESH COMPLETE. Note: you can determine why your
materialized view does not support fast refresh after TRUNCATE
using the DBMS_MVIEW.EXPLAIN_MV() API. -
Table and Materialized View in different namespaces?
I've just faced something completly new for me. It appears that there are two objects with the same name and owner. Table and Materialized View have the same names and when I look into system dictionary I can se sth. like that:
OWNER OBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE NAMESPACE
USER_A USER_TABLE 159381 159381 TABLE 1
USER_A USER_TABLE 159382 MATERIALIZED VIEW 19
(I couldn't find how to write above with const length font).
Two object in different namespace? I thought that Tables and Materialized Vievs have the same namespace.
Can you please tell me how can I create objects to achieve above result? I would also be grateful if you tell me where to find that topic in documentation.Perfectly normal.
SQL> select object_name, object_type from user_objects where object_name = 'TEST_MV';
no rows selected
SQL>
SQL> create materialized view test_mv
2 as
3 select sysdate from dual;
Materialized view created.
SQL>
SQL> select object_name, object_type from user_objects where object_name = 'TEST_MV';
OBJECT_NAME OBJECT_TYPE
TEST_MV TABLE
TEST_MV MATERIALIZED VIEW
SQL>
SQL> drop materialized view test_mv;
Materialized view dropped.
SQL>
SQL> select object_name, object_type from user_objects where object_name = 'TEST_MV';
no rows selected
SQL> -
Create Partition tables in PL/SQL using Execute Immediate
Hi
I have to create a partiton table in PL/SQL using Execute Immediate. I concat the necessary Create Table syntax into a variable and use Execute Immediate variable name. This gives a error ORA-00900: invalid SQL statement. However if i cut and paste the SQL statement from DBMS_OUTPUT, the table creation goes through without any problem.
What could be the issue. Has anyone face this before please.
I am using 10G DBThanks for your reply. It is a big code. I am pasting the part required.
v_sqlstmtout :='CREATE TABLE a_10(MYDATE DATE NOT NULL,ID NUMBER(14) NOT NULL)';
v_sqlstmtout := v_sqlstmtout || ' PARTITION BY RANGE (MYDATE) ';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION BY HASH(id) ';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION TEMPLATE(';
v_sqlstmtout := v_sqlstmtout || 'SUBPARTITION SP1,SUBPARTITION SP2) ';
v_sqlstmtout := v_sqlstmtout || '(PARTITION mth_dummy VALUES LESS THAN ';
v_sqlstmtout := v_sqlstmtout || '('||V_SQLSTMT3||')' || v_sqlstmt||')';
EXECUTE IMMEDIATE ''''||v_sqlstmtout||'''';
variables are substituted through data from different tables.
The output looks like the following
CREATE TABLE a_10(MYDATE DATE NOT NULL,ID NUMBER(14) NOT NULL)
PARTITION BY RANGE (mydate) SUBPARTITION BY HASH(id) SUBPARTITION
TEMPLATE(SUBPARTITION SP1,SUBPARTITION SP2) (PARTITION mth_dummy VALUES
LESS THAN ('01-MAY-2006'), PARTITION mth_JAN2007 VALUES LESS THAN
('01-FEB-2007'))
The above is the output from DBMS_OUTPUT. If i run this statement the table is created. Please help.. -
What is the difference between view and materialized views
Hi
What is the difference between view and materialized view ? can we update the base table using viewscan we update the base table using viewsYes:
VIEWS
1. an updatable view is one that lets you perform DML on the underlying table
(see Oracle Database Concepts 10g - 5 Schema Objects)
2. non-updatable view requires INSTEAD OF Triggers
(see Oracle Database Concepts 10g - 22 Triggers)
SNAPSHOTS
You can have updateable (and writeable) snapshots - in updateable (writeable) MV replication.
Oracle uses snapshots (Materialized Views - MV) for two different purposes:
1. replication
2. automated Query Rewrite facility (first introduced in Oracle Discoverer, later included in Oracle database 8i).
Replication types in Oracle are:
a) Basic replication (MV replication)
- transaction based
- row-level
- asynchronous from master table to MV (Materialized View)
- DML replication only
- database 7 / 8.0 / 8i / 9i / 10g
- Standard and Enterprise Edition
1. Read-only MV replication
2. Updateable MV replication:
2.1 asynchronous from MV to master
2.2 synchronous from MV to master
3. Writeable MV replication
b) Multimaster replication
- transaction based
- row-level or procedural
- asynchronous or synchronous
- DML and DDL replication
- database 7 / 8.0 / 8i / 9i / 10g
- Enterprise Edition only
1. row-level asynchronous replication
2. row-level synchronous replication
3. procedural asynchronous replication
4. procedural synchronous replication
c) Streams replication
- (redo) log based
- row-level
- asynchronous
- DML and DDL replication
- database 9i / 10g (10g has Down Streams Capture)
- Enterprise Edition only (Standard Edition 10g can execute Apply process)
Regards,
Zlatko Sirotic -
Authorization for material type and material views
Hello all,
I would need to restrict a user group, in creation (MM01) and modification of material master, based of type material and material views.
The authorization, for each user should be:
- view, modify and create of all views, except accounting (B) for type material ZFER;
- view, modify and create of all views for type material ZOFF.
I tried to create 2 roles in PFCG with the following authorization objects:
1) M_MATE_MAR (Material Master: Material Types) ACTVT = *, BEGRU = ZFER and M_MATE_STA (Maintenance Statuses) ACTVT = *, STATM = A,C, D, E, F, G,K, L, P, Q, S, V, X, Z (excluding B)
2) ) M_MATE_MAR ACTVT = *, BEGRU = ZFER and M_MATE_STA ACTVT = *, STATM = B
but the effect is to be authorized, to all view for material type ZFER and ZOFF.
I have already updated the authorization group of the type materials (OMS2).
Is there a solution for this problem?
(component version SAP ECC 6.0)
Thanks.
Regards,
LucaI tried to create 2 roles in PFCG with the following authorization objects: 1) M_MATE_MAR (Material Master: Material Types) ACTVT = *, BEGRU = ZFER and M_MATE_STA (Maintenance Statuses) ACTVT = *, STATM = A,C, D, E, F, G,K, L, P, Q, S, V, X, Z (excluding B) 2) ) M_MATE_MAR ACTVT = *, BEGRU = ZFER and M_MATE_STA ACTVT = *, STATM = B
- Are both these roles assigned to the same user? then your purpose is not solved, It is more or less like giving full authorization.
- One role should be
M_MATE_MAR (Material Master: Material Types) ACTVT = *, BEGRU = ZFER and M_MATE_STA (Maintenance Statuses) ACTVT = *, STATM = A,C, D, E, F, G,K, L, P, Q, S, V, X, Z (excluding B) for view, modify and create of all views, except accounting (B) for type material ZFER. This should be assigned to one user
- Second role should be
M_MATE_MAR ACTVT = *, BEGRU = ZOFF and M_MATE_STA ACTVT = *, STATM = * for view, modify and create of all views for type material ZOFF. This role should be assigned to the second user.
Regards,
Subbu -
Oracle equals_path condition NOT working with table and materialized view
The user i am using is xdb with dba role.
1.When i try to use the statement
SELECT PATH FROM xdb.path_VIEW
WHERE
EQUALS_PATH(res, '/home/OE/PurchaseOrders/2002')=1
the result is
/home/OE/PurchaseOrders/2002
2. When i drop the path_view and recreated it like materialized view with statement
create MATERIALIZED view path_view as
select /*+ ORDERED */ t2.path path, t.res res,
xmltype.createxml(xdb.xdb_link_type(NULL, r2.xmldata.dispname, t.name,
h.name, h.flags, h.parent_oid, h.child_oid),
'http://xmlns.oracle.com/xdb/XDBStandard.xsd', 'LINK') link,
t.resid
from ( select xdb.all_path(9999) paths, value(p) res, p.sys_nc_oid$ resid,
p.xmldata.dispname name
from xdb.xdb$resource p
where xdb.under_path(value(p), '/', 9999)=1 ) t,
TABLE( cast (t.paths as xdb.path_array) ) t2,
xdb.xdb$h_link h, xdb.xdb$resource r2
where t2.parent_oid = h.parent_oid and t2.childname = h.name and
t2.parent_oid = r2.sys_nc_oid$
then the equals_path condition STOP working !!!
3. The same experiment, but i recreate it like table
create table path_view as .... using the rest of the statement ...
Can someone help me to understand why equals_path is NOT working on table and materialized view !Thanks Jonah. I was under the impression that I already had it but seems like it has to be a direct priv - thru a role doesn't work.
I granted the reqd privs and then it worked fine. Thx for your help! -
Differences between view and materialized view
Hello,
Please tell me the Differences between view and materialized view in oracle 9i.
Thanks and regards
MadhuriHow can I create index in a view?
Please read reply of Justin Sir.
Regards
Girish Sharma -
Execute immediate and dynamic sql
Dear all;
Just curious....Why do developers still use dynamic sql..and execute immediate, because I always thought dynamic sql were bads and the use of execute immediate as well...
or am I missing something...There are no 'bad' things and 'good' things.
There are 'correctly used' and 'incorrectly used' features.
It depends what you want to do.
One simple example: Oracle 11.2 - you write a package that fetches data from range interval partitioned table (a new partition is created automatically every day when new key values are inserted). If you use static SQL then whenever Oracle creates a new partition then your package gets invalidated and has to be compiled. If your package is heavily used (by many sessions running in parallel) then you may get this:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "PACKAGE.XXXXX" has been invalidated
ORA-06508: PL/SQL: could not find program unit being called: "PACKAGE.XXXXX" Nice, isn't it?
You can avoid this kind of problems by simply using dynamic SQL. You break dependency with the table and your package is not invalidated when new partition is created. -
Help with query rewrite and materialized views
Hello everybody,
I'm currently learning how to use Oracle (10G Enterprise) and in particular, Materialized Views.
I seem to have a problem making the optimizer use a materialized view. I have already set the OPTIMIZER_MODE, QUERY_REWRITE_ENABLED and QUERY_REWRITE_INTEGRITY as needed.
I need to create a materialized view for the following query:
Q1:
SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
and PS_SUPPCOST =
(SELECT min( PS_SUPPCOST)
FROM PARTSUPPLIER I
WHERE E.PS_PARTKEY=I.PS_PARTKEY)'
I created it using the following code:
CREATE MATERIALIZED VIEW mv_q1
ENABLE QUERY REWRITE
AS SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
FROM PARTSUPPLIER E JOIN PART ON (PS_PARTKEY=P_PARTKEY)
WHERE lower(P_COMMENT) LIKE '_o_a%' or lower(P_COMMENT) LIKE '_o_u%'
and PS_SUPPCOST=
(SELECT min( PS_SUPPCOST)
FROM PARTSUPPLIER I
WHERE E.PS_PARTKEY=I.PS_PARTKEY);
I have created the statistics using:
execute dbms_stats.gather_table_stats('frandres',' mv_q1');
execute dbms_stats.gather_table_stats('frandres','PARTSUPPLIER');
execute dbms_stats.gather_table_stats('frandres','PART');
Both partsupplier and part are tables and not views.
When executing Q1, the plan does not use the materialized view. Furthermore, when using explain rewrite:
DECLARE
qrytxt VARCHAR2(3000) := 'SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
and PS_SUPPCOST =
(SELECT min( PS_SUPPCOST)
FROM PARTSUPPLIER I
WHERE E.PS_PARTKEY=I.PS_PARTKEY)';
BEGIN
dbms_mview.EXPLAIN_REWRITE
(qrytxt,'MV_Q1','MV_Q1');
END;
I get the following message:
MESSAGE
QSM-01150: query did not rewrite
QSM-01263: query rewrite not possible when query references a dictionary table o
r view
QSM-01219: no suitable materialized view found to rewrite this query
What I can't understand is why it says I am referencing the dictionary or a view?
If I remove the (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'') condition to the query (using the same materialized view), I get the following message from EXPLAIN_REWRITE:
MESSAGE
QSM-01150: query did not rewrite
QSM-01219: no suitable materialized view found to rewrite this query
Which is reasonable.
I don't know if the like condition is messing up my materialized view. Can anyone please help?
Thanks a lot in advance.
Edited by: user12072111 on Oct 29, 2009 9:43 PMBingo!
The 10.2.0.3 patch set is supposed to fix this ( [List of bugs fixed (MVs)|http://www.dbatools.net/doc/bug10203.html#MVIEW] )
In particular:
5052568 Query rewrite does not work for SQL with LIKE clause.
Thank you very much for your message!
The downside is that I'm only using Oracle for educational purposes and consequently have no Metalink id, so I can't install the patch. Thanks a lot though! -
Instr command in APEX and materialized view
This worked fine up until we changed it to use a materialized layer. P6080_DEPARTMENT, P6080_TITLE and P6080_ROLE are all Multi-Select lists. ACMV is the materialized view. I have been trying multiple things but nothing works.
( instr(':'||:P6080_DEPARTMENT||':',':'||ACMV.DEPARTMENT||':') > 0 or
:P6080_DEPARTMENT is NULL or :P6080_DEPARTMENT = 'ALL') and
( instr(':'||:P6080_TITLE||':',':'||ACMV.TITLE||':') > 0 or
:P6080_TITLE is NULL or :P6080_TITLE = 'ALL') and
( instr(':'||:P6080_ROLE||':',':'||ACMV.ROLE||':') > 0 or
:P6080_ROLE is NULL or :P6080_ROLE = 'ALL')
I can run this in a sql window and get the results using the following for Department
when if use the values from the debugging output.
select business_name from account_contacts_mv acmv
where instr(':ADMINISTRATION:COMPLIANCE:ENGINEERING:EXECUTIVE:FINANCE:HR:IT:LEGAL:',':'||ACMV.department||':')>0
This is a little frustrating and any help will be appreciated.
KDPKDP,
what is your actual problem. Do you get an error or do you suffer performance problems?
Patrick
My APEX Blog: http://inside-apex.blogspot.com
The ApexLib Framework: http://apexlib.sourceforge.net
The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/ -
Hi All,
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
I am getting error when trying to use CLOB with execute immediate.
DECLARE
v_clob CLOB;
BEGIN
EXECUTE IMMEDIATE 'SELECT DBMS_METADATA.GET_DDL(''TABLE'',''T_FDB_TMP'') from dual'
INTO v_clob_part_ddl;
EXECUTE IMMEDIATE 'DROP TABLE T_FDB_TMP';
EXECUTE IMMEDIATE to_char(v_clob_part_ddl);
END;
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1
ORA-06502: PL/SQL: numeric or value error
ORA-31605: the following was returned from LpxXSLResetAllVars in routine kuxslResetParams:
LPX-1: NULL pointer
ORA-06512: at line 3
06502. 00000 - "PL/SQL: numeric or value error%s"Please helpIf you can't upgrade to 11g then you'll have to use DBMS_SQL package...
e.g.
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_large_sql CLOB;
3 v_num NUMBER := 0;
4 v_upperbound NUMBER;
5 v_sql DBMS_SQL.VARCHAR2S;
6 v_cur INTEGER;
7 v_ret NUMBER;
8 begin
9 -- Build a very large SQL statement in the CLOB
10 LOOP
11 IF v_num = 0 THEN
12 v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
13 ELSE
14 v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
15 END IF;
16 v_num := v_num + 1;
17 EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
18 END LOOP;
19 DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
20 DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
21 --
22 -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
23 v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
24 FOR i IN 1..v_upperbound
25 LOOP
26 v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
27 ,256 -- amount
28 ,((i-1)*256)+1 -- offset
29 );
30 END LOOP;
31 --
32 -- Now parse and execute the SQL statement
33 v_cur := DBMS_SQL.OPEN_CURSOR;
34 DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
35 v_ret := DBMS_SQL.EXECUTE(v_cur);
36 DBMS_OUTPUT.PUT_LINE('View Created');
37* end;
SQL> /
Length:40015
Num:548
View Created
PL/SQL procedure successfully completed.
SQL> select count(*) from vw_tmp;
COUNT(*)
548
SQL> select * from vw_tmp where rownum <= 10;
COL1
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009
10 rows selected.
SQL> -
Dynamic Sql Using Execute Immediate
I am trying to construct a dynamic statement that takes in a supplied column name (COL_NAME), then do an Update on the column based on a supplied username. The table myTable has 4 columns and I would like to update a column thats supplied each time.
NOT DYNAMIC
PROCEDURE UpdateUser(aauser myTable.USERNAME%Type,COL_NAME varchar2, val varchar2) AS
BEGIN
Update myTable
set userid = '002'
where username= aauser;
[b]DYNAMIC
PROCEDURE UpdateUser(aauser myTable.USERNAME%Type,COL_NAME varchar2, val varchar2) AS
BEGIN
EXECUTE IMMEDIATE 'UPDATE myTable
Set ' ||COL_NAME||' = val
where myTable.username = aauser';
END UpdateUser;
However I get the following error when I execute this statement. Please help me.
Connecting to the database Local.
ORA-00904: "aaUser": invalid identifier
ORA-06512: at "ANOLD.PUB", line 1433
ORA-06512: at line 10
Process exited.
Disconnecting from the database Local.TEST@XE SQL> desc mytable
Name Null? Type
USERNAME VARCHAR2(30)
USERID VARCHAR2(30)
COL3 NUMBER
COL4 NUMBER
TEST@XE SQL> insert into mytable values('TEST','001',1,2);
1 row created.
TEST@XE SQL> create or replace PROCEDURE UpdateUser(aauser myTable.USERNAME%Type,COL_NAME varchar2, val varchar2) AS
2 BEGIN
3 EXECUTE IMMEDIATE 'UPDATE myTable
4 Set ' ||COL_NAME||' = ' || chr(39) ||val|| chr(39) ||
5 ' where myTable.username = ' || chr(39) ||aauser|| chr(39);
6 END UpdateUser;
TEST@XE SQL> /
Procedure created.
TEST@XE SQL> exec UpdateUser('TEST','userid','002');
PL/SQL procedure successfully completed.
TEST@XE SQL> select * from mytable;
USERNAME USERID COL3 COL4
TEST 002 1 2
TEST@XE SQL> exec UpdateUser('TEST','col3',111);
PL/SQL procedure successfully completed.
TEST@XE SQL> select * from mytable;
USERNAME USERID COL3 COL4
TEST 002 111 2
TEST@XE SQL> -
DBMS_METADATA.GET_DDL and Materialized View
hi gurus,
In 10gR2, i have created a materialized view EMP_MV with a simple structure.
I wanted to get the DDL of EMP_MV.
I used DBMS_METADATA to get the DDL,
select DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET') into v_return from dual;
Output
CREATE MATERIALIZED VIEW "TARGET"."EMP_MV"
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)
TABLESPACE "TARGET_TS_01"
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)
TABLESPACE "TARGET_TS_01"
REFRESH FAST ON DEMAND
WITH PRIMARY KEY USING DEFAULT LOCAL ROLLBACK SEGMENT
DISABLE QUERY REWRITE
AS select empid,empname,address from web.emp
Is there any way to get only SELECT part of this MV, ie select empid,empname,address from web.emp directly from dictionary without any string manipulation?
tia,
newbieYes you can do it. By using INSTR and SUBTR against the result of GET_DDL function
Try this:
select substr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),instr(DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW','EMP_MV','TARGET'),'select'),1000)
into v_return from dual;- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/] -
MATERIALIZED VIEW and MATERIALIZED VIEW LOG
Hello,
I have the following table
create table My_price
(price_id number(10),
product_id number(10),
price_date date,
price_value number(10,2));
I want to create the following materialized view
create materialized view Last_Price_Date
refresh
on commit complete
as
select max(price_date) as max_date, product_id from my_price group by product_id;
Do I have to create materialized view log ? Will my materialized view be refresh on commit without materialized view log ?As a student the requisite first task is always to study. Thus your assignment is to go to http://tahiti.oracle.com and read the concept and architecture docs on Materialized Views so that you can learn about the different types of MVs and how and when they are refreshed. There you will learn about what ON COMMIT means.
Then please turn your "I want to create" into an "I created it." Then, having read the docs, you will be able to observe how your MV behaves.
PS: Your SELECT statement is not syntactically correct. Start by fixing it so that it works in SQL*Plus.
Maybe you are looking for
-
Open production order issue in recording
Hi, I am doing an LSMW recording of the transaction CO02 for the release of open production orders.If i try to release an order which has a missing part list a pop up appears which has the following three options 1. Release order 2.Mising part list 3
-
How to trigger crystal report from SAP ECC
Hi All, I hope i m right forum to ask this question. we want to do label printing from Crystal reports. data will be present in SAP ECC . So I below issues 1 ) how to connect SAP ECC database with Crystal Reports. 2 ) how to trigger print output in C
-
Can't start up past gray screen on iMac G4 flat panel
My iMac G4 flat panel is messed up right now and I'd appreciate any help I can get here. This morning after I realized my internet wasn't working I tried a restart but the restart stalled around the part where it just shows your desktop picture and w
-
When opening Firefox, the bookmarks hang for up to 30 seconds before they can be accessed. Also have a hanging issue when opening a window/pop-up within an application (i.e., email search window). == This happened == Every time Firefox opened == Afte
-
Someone Please Help??? Question About Internet?
Hi, I got my daughter the 8gb touch in May and how is she able to go on the internet for free?? Is there some kind of free trial or something?? I have internet in my house but not WIFI....any help would be greatly appreciated as I do not want to be b