I've made some changes to columns in a database table (increasing the size of varchar), however I need to have the view of the table refreshed to pick up this change. In SQL server 2005 I would use the script to -> alter to recreate the script for the view. I'm trying to figure out what the Oracle SQL command would be to rebuild the view to display the change of the column?
Unless your view is explicitly restricting the size of the column, it will pick up the change automatically. It may have been invalidated by the table change but would be automatically recompiled when first used; or can be manually recompiled with alter view <view name> compile.
If you do so:
create table sample_table(text varchar2(10));
insert into sample_table (text) values('text...');
create view sample_view as select * from sample_table;
select * from sample_view;
alter table sample_table modify text varchar2(200);
You do not do anything to promote this change in view in Oracle database.
Or you can use "ALTER VIEW sample_view COMPILE" (how wrote #AlexPole or #devio). Oracle do this automatically when you firstly use select on sample_view after alter table.
Try
ALTER VIEW MyView COMPILE;
Related
Oracle EBS R12.2.9
I have to add a new column to an editioning view of a custom table in oracle EBS R12.2.9.
Table was created like this...
From AMTO: create table amto.mci_jjtest1(a number)
From APPS: exec ad_zd_table.upgrade('AMTO', 'MCI_JJTEST1') -- This creates editioning view and also synonym under APPS
Now, new column B number with data type, needs to be added to the table, and the editioning view needs to be modified to add that column to the editioning view. Kindly let me know what commands and steps, I need to follow. I understand the traditional approach, where we would alter table to add column, and create or replace view to add the column to the SELECT, Not sure how to add column to table and editioning view the correct recommended way. Please suggest.
For table alterations - after running the DDL run below script to regenerate the editioning view for syncing any table changes.
exec AD_ZD_TABLE.PATCH('AMTO','MCI_JJTEST1')
I am new to Oracle and for practice I have created some tables (customer, drivers, payment, booking, location, area, job, job_history) in Oracle 11g and upon select * from cat statement I have found a strange table with other created tables named "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0".I don't know why this table is created.
I tried to remove this table through
drop table BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0;
but it gives error:
drop table BIN$c+*eOnMB3RbKSEfg/rsxtAQ==$0
ERROR at line 1: ORA-00933: SQL command not properly ended
what should I do to remove it?
What you see is a deleted table in the RECYCLEBIN
You may get the original name of the table with this query
SELECT original_name FROM RECYCLEBIN where OBJECT_NAME = 'BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0';
Note that (with your parameter setting) if you DROP a table it is not completely removed, but moved in the recyclebin.
You may ommit this using the PURGE option.
DROP TABLE xxx PURGE;
To remove the table from the recyclebin you must qoute the name with double quotes (as this is not a valid name) and use the PURGE statement (not a DROP - which would trigger ORA-38301: can not perform DDL/DML over objects in Recycle Bin).
PURGE TABLE "BIN$c+eOnMB3RbKSEfg/rsxtAQ==$0"
Alternatively you may use the original_name obtained with the query above:
PURGE TABLE {your_original_name};
To clean up the recyclebin completely use this statement (with the propper table user)
PURGE RECYCLEBIN;
I have a materialized view that I need to redefine the SQL for. We have an external system that hits the view over a db link, and the monster view takes 5 minutes to refresh the data in the view. The only way I know how to redefine the SQL for a view is to drop it and recreate it, but it would be very bad if the external system couldn't find the table, or it didn't have a complete data set. I need to have as little downtime as possible.
Is there any way to do this natively or more elegantly than:
Create public synonym for materialized view and make everything that uses the view use the synonym instead.
Create new materialized view with new SQL
Change the synonym to point to the new view
Drop the old view.
I've got code to do this dynamically but it is getting really ugly. It seems like there should be a better way to handle this.
Oracle has a build in solution for that. Keep in mind that the mview declaration is separate from that of the table.
The original mview
create materialized view mv1 as select dept , count(*) as cnt from scott.emp;
we want to change the declaration so that only dept over 5 will be calculated
drop materialized view mv1 preserve table;
notice the PRESERVE TABLE clause - the table mv1 is not droped - only the mview layer.
desc mv1
now we create the mview with a different query on top of the existing table
create materialized view mv1 on prebuilt table as
select dept , count(*) as cnt from scott.emp where dept > 5;
notice the on prebuilt table clause. the mview is using the existing object.
exec dbms_mview.refresh_mview('mv1');
If we have created a view on an existing DB2 table and then drop the table. What will happen to the view ?
The view becomes invalid/inoperative. Attempts to select from it will fail.
To try it:
create table TEST_TABLE (
TEST_COL INTEGER
);
INSERT INTO TEST_TABLE VALUES(1);
SELECT * FROM TEST_TABLE;
create view TEST_VIEW AS
SELECT * FROM TEST_TABLE;
SELECT * FROM TEST_VIEW;
DROP TABLE TEST_TABLE;
SELECT * FROM TEST_VIEW;
The last statement gives the error:
[IBM][CLI Driver][DB2/NT] SQL0575N View or materialized query table
"TEST_VIEW" cannot be used because it has been marked inoperative.
SQLSTATE=51024
When a view is invalidated, as shown in the above example, DB2 will allow you to recreate that view without dropping it first. This makes it possible to re-run your view DDL files (or simply dump the TEXT column of SYSCAT.VIEWS and execute that).
Nothing happened. Just don't use that view. You can recreate the table again to use the view again later.
It becomes inoperative.
Same information can be found using following query:
SELECT viewscheama,viewname,valid FROM syscat.views
.
For the perticular view , if the "Valid" column has any value apart of 'Y' , then the view will be inoperative.
Is it possible to 'hide' a column in an Oracle 10g database, or prevent data from being inserted altogether? We'd prefer to have existing INSERT statements still function, but have the information NOT insert for a particular column. Also, column masking or any type of encryption is not preferred.
Not sure if it's possible, but thanks in advance.
If all you need to do is stop data from being inserted, you could create a BEFORE INSERT FOR EACH ROW trigger that wipes out any value inserted into the column before the row is saved.
There are various other things you can do with security (also views) to prevent inserts/selects from particular users in particular circumstances, but these will probably not let existing inserts continue to work.
With Oracle feature virtual private database (VPD) you can define which users can change and which users can select a column. Virtual private database is also called fine-grained access control (FGAC).
I know how to hide the column.
You use the
SET UNUSED
option to mark one or more columns as unused.
You use the DROP
UNUSED COLUMNS
option to remove the columns that are marked as unused.
ALTER TABLE emp
SET UNUSED (last_name);
and
ALTER TABLE emp
DROP UNUSED COLUMNS;
Rename original table, create view with original table name but only selecting the columns you want to show.
Recompile code referring to existing table.
what about just setting your grants to each item you allow to update or insert
grant select on emp to scott;
grant update (column1, column2), insert (column1) on emp to scott