Home » SQL & PL/SQL » SQL & PL/SQL » Oracle view creation (ORACLE 11g)
Oracle view creation [message #600751] Tue, 12 November 2013 01:19 Go to next message
kalpeshrmopkar
Messages: 10
Registered: November 2013
Junior Member

How can a view be successfully created even if the stored procedure referred in view is invalid? Creation of "force view" is not sufficing the purpose.
Re: Oracle view creation [message #600754 is a reply to message #600751] Tue, 12 November 2013 01:54 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
kalpeshrmopkar
Creation of "force view" is not sufficing the purpose.

Why not?

Here's an example: I'm creating a table, a function that selects from that table, and a view that uses a function:
SQL> create table a1_brisime (col number);

Table created.

SQL> create or replace function f_brisime
  2    return number as
  3    retval number;
  4  begin
  5    select count(*) into retval from a1_brisime;
  6    return retval;
  7  end;
  8  /

Function created.

SQL> create or replace force view v1_brisime as
  2    select 1 col from dual union
  3    select f_brisime from dual;

View created.

SQL> select * From v1_brisime;

       COL
----------
         0
         1

Now I'll drop the table:
SQL> drop table a1_brisime;

Table dropped.

SQL> select * from v1_brisime;
select * from v1_brisime
              *
ERROR at line 1:
ORA-04063: view "SCOTT.V1_BRISIME" has errors
Obviously, I can't use the view any more.

I'll recreate the view anyway:
SQL> create or replace force view v1_brisime as
  2    select 1 col from dual union
  3    select f_brisime from dual;

Warning: View created with compilation errors.

SQL> show err view v1_brisime
Errors for VIEW V1_BRISIME:

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      ORA-06575: Package or function F_BRISIME is in an invalid state

The view *WAS* created (but I can't use it until I fix those errors):
SQL> select view_name, text_length from user_views where view_name = 'V1_BRISIME';

VIEW_NAME                      TEXT_LENGTH
------------------------------ -----------
V1_BRISIME                              57

SQL> select * from v1_brisime;
select * from v1_brisime
              *
ERROR at line 1:
ORA-04063: view "SCOTT.V1_BRISIME" has errors


OK then, I'll recreate the table and I'm up and running again:
SQL> create table a1_brisime (col number);

Table created.

SQL> select * from v1_brisime;

       COL
----------
         0
         1


So, why exactly do you think that FORCE VIEW doesn't satisfy your needs? Documentation saysOracle
Specify FORCE if you want to create the view regardless of whether the base tables of the view or the referenced object types exist or the owner of the schema containing the view has privileges on them. These conditions must be true before any SELECT, INSERT, UPDATE, or DELETE statements can be issued
Re: Oracle view creation [message #601048 is a reply to message #600754] Fri, 15 November 2013 01:05 Go to previous message
kalpeshrmopkar
Messages: 10
Registered: November 2013
Junior Member

Tried again with force view, it works. Thanks for the help
Previous Topic: IF is not working right please suggest
Next Topic: Use of index vs full table scan
Goto Forum:
  


Current Time: Fri Apr 26 16:39:32 CDT 2024