Monday 17 June 2013

ORA-25153 Temporary Tablespace is Empty Error in Oracle

When executing SQL query, sometimes you may get the following Oracle error:

ORA-25153: Temporary Tablespace is Empty

The cause for the ORA-25153 error is because attempt was made to use space in a temporary tablespace with no files (no datafiles defined).

To solve the problem, the solution is just by adding files (datafiles) to the TEMP tablespace by using ADD TEMPFILE command.

For more information go through below link


http://www.mydigitallife.info/ora-25153-temporary-tablespace-is-empty-error-in-oracle/

Sunday 16 June 2013

Learn HTML online with Online Editor

If anyone wants to learn HTML with the help of online line HTML editor, just go through below link. This website provides you simple examples along with online editor. Enjoy!!Happy Learning!!

http://www.w3schools.com/html/default.asp


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:

Monday 29 April 2013

Alter Table With Default Constraint


case1:-
========
When you are adding a column into an existing table with default constraint then it takes lot of time to add, if the table is big.

Why because adding column with default value means you are updating the total table with that value.

ex: ALTER TABLE Scott.EMP ADD (emp_flag VARCHAR2(1) DEFAULT 'N');

case2:-
========
When you are adding a column into an existing table without default constraint,
it doesnot take time even though you are adding it into a big table.

Why because adding a column without default value means it doesnot go for updating your table. It just adds a column with null values.

ex: ALTER TABLE Scott.EMP ADD (emp_flag VARCHAR2(1));

Note:- Based on your requirement go for adding.

Friday 19 April 2013

How to Compile a Schema in oracle


Use the supplied package procedure DBMS_UTILITY.COMPILE_SCHEMA. It Compiles all PLSQL objects in a schema.

EXECUTE DBMS_UTILITY.COMPILE_SCHEMA('SCHEMA_NAME');

ex:- EXECUTE DBMS_UTILITY.COMPILE_SCHEMA('SCOTT'); 

NOTE: Recompiles all stored packages, procedures and functions in the specified schema in dependency order.

NOTE:- It applies to 9.2.0.8 and later.

Wednesday 10 April 2013

OUT parameters in oracle Stored functions along with return Value


While writing PL/SQL functions we can use get values through return statement as well as using out parameters. Generally people don’t use out parameters in stored functions, but it is always pretty much possible to use them in functions also. Based on your requirement you can make use of them. Just go through below example:

CREATE OR REPLACE FUNCTION test_fun (var1 NUMBER, var2 OUT VARCHAR2,var3 out number)
   RETURN NUMBER
IS
   v_sal   NUMBER;
BEGIN
   SELECT ename, sal,deptno
     INTO var2, v_sal,var3
     FROM EMP
    WHERE empno=var1 and ROWNUM = 1;

   RETURN v_sal;
END;
/

Call the function like below:

DECLARE
   retval   NUMBER;
   var1     NUMBER;
   var2     VARCHAR2 (200);
   var3     NUMBER;
BEGIN
   var1 := 7369;
   var2 := NULL;
   var3 := NULL;
   retval := TEST_FUN (var1, var2, var3);
   DBMS_OUTPUT.put_line ('VAR2:' || var2);
   DBMS_OUTPUT.put_line ('VAR3:' || var3);
   DBMS_OUTPUT.put_line ('RETVAL:' || retval);
   COMMIT;
END;
/

Your output will be like below:
VAR2:SMITH
VAR3:20
RETVAL:800

Tuesday 9 April 2013

Printing Camel Case Names while creating Database Objects in Oracle


If you want to put the CamelCase names to your database objects, your create object script should have been with in double quotes like below:

create table "temp_2"
(“col1”  number constraint "temp_2_pk" primary key, col2 number);

select * from "temp_2"

select * from user_tables where table_name ='temp_2'

Without double-quotes Oracle helpfully converts all identifiers to uppercase.

Monday 8 April 2013

Save points in oracle

SAVEPOINT- name Marks a savepoint within the current transaction
ROLLBACK - ROLLBACK ends the current transaction by discarding all pending
                     data changes
ROLLBACK TO SAVEPOINT name-ROLLBACK TO SAVEPOINT rolls back the current transaction to the specified savepoint, thereby discarding any changes and or savepoints created after the savepoint to which you are rolling back. If you omit the TO SAVEPOINT clause, the ROLLBACK statement rolls back the entire transaction. As savepoints are logical, there is no way to list the savepoints you have created.

Syntax:
Savepoint <savepoint_name>;
Example:-
SQL> savepoint s1;
SQL> insert into student values(1, ‘a’, 100);
SQL> savepoint s2;
SQL> insert into student values(2, ‘b’, 200);
SQL> savepoint s3;
SQL> insert into student values(3, ‘c’, 300);
SQL> savepoint s4;
SQL> insert into student values(4, ‘d’, 400);

Before rollback 

SQL> select * from student;

NO NAME MARKS
--- ------- ----------
1 a 100
2 b 200
3 c 300
4 d 400

SQL> rollback to savepoint s3;
Or
SQL> rollback to s3;

This will rollback last two records.
SQL> select * from student;

NO NAME MARKS
--- ------- ----------
1 a 100
2 b 200

Example1:-

CREATE OR REPLACE PROCEDURE pp
IS
BEGIN
   UPDATE emp SET ename = ename || '1' WHERE empno = 7788;

   SAVEPOINT 1;

   UPDATE emp SET ename = ename || '2' WHERE empno = 7788;

   SAVEPOINT 2;

   UPDATE emp SET ename = ename || '3' WHERE empno = 7788;

   SAVEPOINT 3;

   UPDATE emp SET ename = ename || '4' WHERE empno = 7788;

   SAVEPOINT 4;
  
   ROLLBACK to 2;
  
   COMMIT;
END;
/
U will get compilation error like below:
PL/SQL: ORA-00933: SQL command not properly ended
Sol:- you can’t establish your savepoints using numbers, u should give characters.

Example2:-

CREATE OR REPLACE PROCEDURE pp
IS
BEGIN
   UPDATE emp SET ename = ename || '1' WHERE empno = 7788;

   SAVEPOINT a;

   UPDATE emp SET ename = ename || '2' WHERE empno = 7788;

   SAVEPOINT b;

   UPDATE emp SET ename = ename || '3' WHERE empno = 7788;

   SAVEPOINT c;

   UPDATE emp SET ename = ename || '4' WHERE empno = 7788;

   SAVEPOINT d;
  
     Commit;

   ROLLBACK to b;
  
   COMMIT;
END;
/
U will get run time error like below:
ORA-01086: savepoint 'B' never established
Sol:- you can’t establish your savepoints after commit statement, why because already transactions are committed using commit, so it is impossible to rollback.

Example3:-

CREATE OR REPLACE PROCEDURE pp
IS
BEGIN
   UPDATE emp SET ename = ename || '1' WHERE empno = 7788;

   SAVEPOINT a;

   UPDATE emp SET ename = ename || '2' WHERE empno = 7788;

   SAVEPOINT b;

   UPDATE emp SET ename = ename || '3' WHERE empno = 7788;

   SAVEPOINT c;

   UPDATE emp SET ename = ename || '4' WHERE empno = 7788;

   SAVEPOINT d;
  
    ROLLBACK to 2;
  
   COMMIT;
END;
/

Sol:- Here upto b transactions will be rollback, and before b whatever transactions are there those will be committed. Means SCOTT will become SCOTT12.