Materialized view for different oracle schema results in ORA-1208 - oracle

I want to create on commit materialized oracle view pointing to table from different schema within same database instance.
schema (BATCH):
CREATE TABLE "BATCH"."BATCH_CONFIG"
( "KEY" VARCHAR2(100 BYTE),
"VALUE" VARCHAR2(4000 BYTE),
"COMMENTS" VARCHAR2(4000 BYTE),
"UPDATED_BY" VARCHAR2(25 BYTE),
"UPDATED" TIMESTAMP (6),
CONSTRAINT "PK_BATCH_CONFIG" PRIMARY KEY ("KEY")
);
create materialized view log on batch_config;
grant all on batch_config to profile;
schema (PROFILE):
create materialized view mv_batch_config REFRESH FAST ON COMMIT
as select * from BATCH.batch_config;
Got Error:
SQL Error: ORA-12018: following error encountered during code generation for "PROFILE"."MV_BATCH_CONFIG"
ORA-00942: table or view does not exist
12018. 0000 - "following error encountered during code generation for \"%s\".\"%s\""
*Cause: The refresh operations for the indicated materialized view could
not be regenerated due to errors.
*Action: Correct the problem indicated in the following error messages and
repeat the operation.
What is the issue with ? I am able to view query by (from profile schema) select * from BATCH.batch_config

OK finally I got the solution.
I have to grant select on mview log also.
GRANT SELECT ON MLOG$_BATCH_CONFIG TO PROFILE;

Related

ORA-00942: table or view does not exist while creating the table

I am creating a table in an oracle database using a statement like this:
CREATE TABLE T_MY_NEW_TABLE (
ID VARCHAR2(10 char) not null,
VERSION NUMBER(4),
SOME_ID VARCHAR2(10 char) not null,
constraint PK_MY_NEW_TABLE primary key(ID)
);
This script usually runs fine. But sometimes I get the error: ORA-00942: table or view does not exist.
Which doesn't make any sense to me. What is the error supposed to mean?
I am creating a new table. The table that I am creating should not exist. But oracle want it to exist, so I can create it?
It must be something else. And only the error is misleading?
I tried to create a new table.
I expected the new table to be created.
Sometimes I am getting the error ORA-00942 instead of the created table.

How to add primary key to materialized view in oracle

please help me with an example on how to add primary key to materialized view in oracle 19c or 21c.
Also, real life application where we use primary key to materialized view. I posting this after complete research on materialized view.
I have a strong opinion that primary key is not required on materialized view. Please correct me if I am wrong.
How to add a primary key? Using the ALTER TABLE statement.
This is a sample table; I'll create a materialized view on it.
SQL> create table test as
2 select deptno, empno, ename, job
3 from emp;
Table created.
SQL> create materialized view mv_test as
2 select deptno, empno, ename, job
3 from test;
Materialized view created.
Primary key:
SQL> alter table mv_test add constraint pk_mvt primary key (empno);
Table altered.
SQL>
Real life: use it whenever appropriate. Primary key implicitly creates index on primary key column(s). Index improves performance (if optimizer chooses to use it).

When I Create New Table from Oracle Sql Developer. I get this error

Error Messages:
ORA-00604: error occurred at recursive SQL level 1
ORA-00942: table or view does not exist
You're living a dangerous life.
Never, ever create anything in SYS (nor SYSTEM) schema.
Who knows what might be wrong ... maybe you dropped some SYS-owned object. Maybe there's a trigger which does "something" when you create a table.
There's nothing obvious in what you posted. Table, as is, creates normally:
SQL> show user
USER is "SCOTT"
SQL> create table table1
2 (id varchar2(20) not null,
3 ivoice varchar2(20) not null
4 );
Table created.
SQL>

What is the disadvantage of using SHRINK SPACE for an Oracle Table?

I am going to develop a reporting database by querying the production database once using a stored procedure.
The stored procedure will then write the result into it's own output tables.
Following is the schema for the output table:
Create table Output (
Customer_ID NUMBER(15) not null,
STD_HASH RAW(1000 BYTE) ,
VALID_PERIOD_START NOT NULL TIMESTAMP(6),
VALID_PERIOD_END NOT NULL TIMESTAMP(6),
Address VARCHAR2(30 CHAR),
period for valid_period(valid_period_start,valid_period_end),
Constraint Output_PK Primary Key ( Customer_ID, valid_period_start, valid_period_end )
)
As the stored procedure will perform a lot of update and delete statement on the output table, and those output table is very big. The largest one I have right now is 8GB. I am thinking to alter those output tables with the "SHRINK SPACE" option at the end of the stored procedure to reclaim some spaces.
Following is the statement that I am going to apply:
Alter table OUTPUT1 ENABLE ROW MOVEMENT; -- Temporary enable row movement for the table
Alter TABLE output2 SHRINK SPACE;
Alter table OUTPUT1 DISABLE ROW MOVEMENT;-- Disable row movement.
Those output tables are temporal table that is using the valid period and the ID from production as a primary key.
However, as I am very new with the Shrink Space function. Can anyone tell me what is the disadvantage of using this function?
The table, basically will not be updated from anywhere other than this stored procedure. The stored procedure will be scheduled to run in a daily base.
Thanks in advance!
yes, shrink has some restrictions:
(1) it locks the table during the shrink operation
(2) it change the rowid of the table.
(3) it needs the tablespace with automatic segment-space management enabled.
we have other alternatives to claim the unused space:
(1) export/import
(2) dbms_redefinition

oracle apex GTT preserve rows after logout

I have a GTT in my oracle apex application.
CREATE GLOBAL TEMPORARY TABLE "SEARCH"
( "CODE" VARCHAR2(15 BYTE),
"HEAD" VARCHAR2(100 BYTE),
"BRCODE" VARCHAR2(3 BYTE)
) ON COMMIT PRESERVE ROWS ;
But the GTT preserves it's rows even after the user log out from the application. If another user login to the application, he can access the same data created by the previous user. What might be the problem with GTT or session ?
Please read this answer thread from oracle community. GTT - Global Temporary Table - Problem with Apex

Resources