I have created a simple view and have forgotten to add WITH READ ONLY while creating the view.
Now I want to alter the view and add WITH READ ONLY option. What will be the query for it?
alter view x read only;
was added in 11.2, but unfortunately only for editioning views.
So there is a chance that in some future version this will be extended to regular views:)
Until that use simple create or replace view
create or replace view x as
select * from dual /* your query */
with read only;
or
create or replace view x as
select * from dual /* your query */
with check option;
Related
How can I check in Oracle if a view was created with the FORCE option?
In the view sys.all_views there is no column for this option and the query text itself doesn't contain the CREATE part.
I can confirm what #a_horse_with_no_name suggested: FORCE isn't stored in the data dictionary, and dbms_metadata.get_ddl makes it up, as probably TOAD does, too:
CREATE TABLE t (i NUMBER);
CREATE FORCE VIEW f AS SELECT * FROM t;
CREATE NOFORCE VIEW n AS SELECT * FROM t;
USER_VIEWS, USER_OBJECTS, SYS.VIEW$ and SYS.OBJ$ are identical for the two views. And dbms_metadata.get_ddl adds FORCE in any case:
SELECT dbms_metadata.get_ddl('VIEW', view_name) FROM user_views;
CREATE OR REPLACE FORCE EDITIONABLE VIEW "SO"."F" ("I") AS
SELECT "I" FROM t"
CREATE OR REPLACE FORCE EDITIONABLE VIEW "SO"."N" ("I") AS
SELECT "I" FROM t"
I have a view name customer and I want to restrict following SQL command
select * from customer;
I want to create a view where user must have where clause and only it is executable
select * from customer where address='ABC';
Use contexts.
create context where_condition using your_context_pkg;
Then use the context in the view:
create view customer_v as
select * from customer
where address = sys_context('where_condition', 'addreess')
You have to provide a PL/SQL package, named your_context_pkg, where the context value is set with dbms_session.set_context(...).
The way you put it, you'd recreate the view as
create or replace view customer as
select whatever
from bunch_of_tables
where address is not null --> add this
If you need this feature for security reasions, familiarize yourself with role based security (RBS).
There are some changes on the core product on which I'm working and some tables become now views and they are not working anymore because a view cannot be referenced with the schema name in front.
For example, the below will return an error: ORA-00942: table or view does not exist
select * from my_schema.my_view;
while a direct select from the view works fine
select * from my_view;
In case of a table, both scenarios above are working fine, is just the view that doesn't accept schema_name in front.
Why is that? Are there any decent workarounds?
EDIT: the selects are executed with my_schema user
Thanks all for your help, especially #mathguy.
Basically the problem was that my_view was in fact a public synonym for my_view_r which was the actual view and being public, you cannot call it using the schema name in front like I was trying. eg:
select * from my_schema.my_view;
Maybe it will be helpful for others that are facing this issue in the future, the workaround would be to create a private synonym to the same view (my_view_r) using the schema name like below:
create synonym my_schema.my_view for my_view_r;
This is the only way to call a synonym using the schema name.
It's a grant issue.
grant all on my_view to my_schema
Make sure your schema really is the owner by running:
Select * from all_objects where object_name = 'my_view';
I have a view stvytro with owner baninst1. There is a public synonym of the same name. The following both work:
select * from STVYTRO;
select * from baninst1.stvytro;
This question already has an answer here:
How to delete a column from a view
(1 answer)
Closed 5 years ago.
INITIAL VIEW CREATED
create or replace view concert_view
as
select concert.concert_id
from concert, event
where concert.concert_id=event.concert_id;
WHEN I TRIED TO ADD COLUMNS USING
alter view concert_view as
select
cname,edate
from concert,event
where concert.concert_id=event.concert_id;
I HAVE AN ERROR MESSAGE
alter view concert_view as
*
ERROR at line 1:
ORA-00922: missing or invalid option
ALTER VIEW is not used in this way. The only options for altering a view are to add/drop/modify constraints or to RECOMPILE the view.
If you want to add columns then just run the CREATE OR REPLACE VIEW statement again with a different select.
A View is basically only a SELECT -statement. If you want to add another column to your view, just change the statement on which it is based.
And recreate a view.
There is a table named IM_RESULT_INFO. Because I can see it by SELECT * FROM IM_RESULT_INFO.
But it doesn't exist in table nor view lists in sqldeveloper. I also tested SELECT * FROM all_all_tables and SELECT * FROM dba_tables, and couldn't find the table.
In Eclipse IDE, I searched for it in whole project files, but the only code I found was SELECT ... FROM IM_RESULT_INFO.
I think it is a mixture of tables, but there's no way to analyze it. How can I find it?
It must be a synonym or a view, check the synonyms view to see what object is referenced by it:
SELECT *
FROM all_synonyms
WHERE synonym_name = 'IM_RESULT_INFO'
Or the views view:
SELECT *
FROM all_views
WHERE view_name = 'IM_RESULT_INFO'
You can check in ALL_OBJECTS if you are not sure about the type of an object. It will provide you the Types and other important details also.
For Materialized view please check ALL_MVIEWS.
SELECT *
FROM ALL_OBJECTS
WHERE OBJECT_NAME='IM_RESULT_INFO';