Tuesday 21 May 2013

Create view and synonym on non-existing object in Oracle

When you try to create a view on non-existing object oracle will not allow to create. You can attain this by FORCE option in create view statement;

SQL> select count(1) from user_tables where table_name='BASE_TAB';

 COUNT(1)
---------
        0
           
-create view without force option
SQL> create view view_1 as select * from base_tab;
create view view_1 as select * from base_tab
                                    *
ERROR at line 1:
ORA-00942: table or view does not exist

-create view with force option
SQL> create force view view_1 as select * from base_tab;

Warning: View created with compilation errors.

-check the status of this view
SQL> set linesize 2000
SQL> col object_name format a20
SQL> select object_name,status from dba_objects where object_name in ('VIEW_1');

OBJECT_NAME          STATUS
-------------------- -------
VIEW_1               INVALID

-When you want to create synonym on non-existing objects we don’t need any force option.
SQL> create synonym syn_1 for base_tab;

Synonym created.

SQL> select object_name,status from dba_objects where object_name in ('SYN_1');

OBJECT_NAME          STATUS
-------------------- -------

SYN_1                VALID

Getting ORA-00942: table or view does not exist error when accessing meta data views in oracle

When you try to access any meta data views like DBA_OBJECTS, DBA_TABLES, DBA_VIEWS etc.. (starts with DBA_) some time you may get an error like below:

SQL> select object_name,status from dba_objects where object_name in ('VIEW_T1');
select object_name,status from dba_objects where object_name in ('VIEW_T1')
                               *
ERROR at line 1:
ORA-00942: table or view does not exist

Reason is user does not have DBA privileges to access them. So login into system schema grant DBA permissions to respected schema.

SQL> GRANT DBA TO SCOTT;


Monday 13 May 2013

What happens to oracle views if we alter a table structure by adding a new column?


Assume that the structure of the table on which a view is based is modified. When you describe the view by using iSQL*Plus DESCRIBE command, you get an error message that states that the object is invalid to describe. This is because the command is not a SQL command and, at this stage, the view is invalid because the structure of its base table is changed. If you query the view now, the view is recompiled automatically and you can see the result if it is successfully recompiled.

Note:- In the case of local dependencies, the objects are on the same node in the same database. The Oracle server automatically manages all local dependencies, using the database’s internal “depends-on” table. When a referenced object is modified, the dependent objects are invalidated. The next time an invalidated object is called, the Oracle server automatically recompiles it.

For better understanding go through an example below:

SQL> create table testtab(col1 number,col2 number);

Table created.

SQL> insert into testtab values(1,1);

1 row created.

SQL> commit;

Commit complete.

SQL> create view testtab_view as select * from testtab;

View created.

SQL> select * from testtab_view;

     COL1      COL2
--------- ---------
        1         1
       
SQL> select object_name,status from user_objects where object_name='TESTTAB_VIEW';

OBJECT_NAME        STATUS
--------------- -----------
TESTTAB_VIEW       VALID

SQL> ALTER TABLE TESTTAB_VIEW ADD (COL3 NUMBER);
ALTER TABLE TESTTAB_VIEW ADD (COL3 NUMBER)
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> ALTER TABLE TESTTAB ADD (COL3 NUMBER);

Table altered.

SQL> select object_name,status from user_objects where object_name='TESTTAB_VIEW';

OBJECT_NAME        STATUS
--------------- -----------
TESTTAB_VIEW       INVALID

SQL> DESC TESTTAB_VIEW;
ERROR:
ORA-24372: invalid object for describe


SQL> SELECT * FROM TESTTAB_VIEW;

     COL1      COL2
--------- ---------
        1         1

SQL> select object_name,status from user_objects where object_name='TESTTAB_VIEW';

OBJECT_NAME        STATUS
--------------- -----------
TESTTAB_VIEW       VALID

Note:- Your view definition is select * from testtab; Even though it doesn’t display col3 why because this column was not there while creation of a view, so view definition doesn’t contain that column in his definition.

Note: The data types of the columns in the base table do not matter at the
time of compiling the view. That means in the above example even columns
C1 is of VARCHAR2 type in table T1 still the view will be made valid. Because
Oracle precisely looks for columns C1 and C2 in table T1and not for any
specific data type. For better understanding Check below example:

SQL> create table test_tab (col1 number,col2 number);

Table created.

SQL> create view test_view as select * from test_tab;

View created.

SQL> desc test_view;
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ---------------
 COL1                                                           NUMBER
 COL2                                                           NUMBER

SQL> drop table test_tab;

Table dropped.

SQL> create table test_tab (col1 number,col2 varchar2(100),col3 number);

Table created.

SQL> desc test_view;
ERROR:
ORA-24372: invalid object for describe


SQL> select * from test_view;

no rows selected

SQL> desc test_view;
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ---------------
 COL1                                                           NUMBER
 COL2                                                           VARCHAR2(100)

Friday 3 May 2013

Oracle Database Editions & Licensing Option


Oracle database software is available in following different editions. The basic concept of having so many editions is, based on requirement people choose their editions.
i.e Oracle Database enterprise for large enterprises and Oracle Database Lite database to run on mobile devices.

Oracle Enterprise Edition:
Enterprise Edition is the full (top of the range) version or the Oracle Database Server. Options like RAC, Partitioning, Spatial, etc. can be purchased separately to enhance the functionality of the database. This edition typically runs on servers with 4 or more processors and it has no limit on memory (RAM). Clustering feature is available in this edition using Oracle RAC (Real Application Cluster) software. Moreover, it has more features than Standard Edition. Oracle Corporation licenses this product on the basis of
users or of processors.

Oracle Standard Edition:
Standard Edition is designed for smaller businesses and enterprises. It offers a subset of the features/ functionality implemented in Enterprise Edition. Database options like Data Guard, Partitioning, Spatial, etc. is not available with Standard Edition (from 10g one can use RAC with Standard Edition). Standard Edition can only be licensed on servers with a maximum capacity of four processors and it has no limit on memory (RAM).

Oracle Standard Edition One:
Standard Edition One is a low cost, entry-level version of the Oracle Standard Edition database server. Standard Edition One can only be licensed on small servers with a maximum capacity of two processors. Moreover it has no memory limitation. Can’t  use RAC with Standard Edition one.

Oracle Personal Edition:
Personal Oracle is a single user version of the database server. It is mostly the same as Enterprise Edition, but doesn't support advanced options like RAC, Streams, XMLDB, etc.
It is licensed for single-user. This edition is for single processor workstations.

Oracle Database Lite:
Oracle Light is a database engine that can be used on mobile platforms like cell phones and PDA's. The database itself is located on the mobile device and is having the ability to
synchronize with the main Oracle server.

Oracle Express Edition (XE):
Express Edition (XE) is a free, downloadable version of the Oracle database server. Oracle XE can only be used on single processor machines. It can only manage up to 4 GB of data and 1 GB of memory. ISVs can embed XE in 3rd party products and redistribute it freely.

After making a decision regarding which edition you need, the next thing is to find out how you want to have the licensing of the software. You can buy the licenses based on the number of users using the Oracle Server or based on the number of processors you will be having in the server machine.

To view these edition differences further more you can  go through below link:

Thursday 2 May 2013

Why we need another kind of memory: RAM inside the computer if we already have hard drives?


It’s because the speed with which Microprocessor (CPU) communicates with the RAM is much faster compared to the speed with which CPU interacts with the hard drive.  RAM is also a kind of microprocessor so it interacts with another Microprocessor (CPU) quickly and effectively.
                                                 
If you want more information about this go through the link below: