Thursday, November 21, 2013

Simple Step to Execute Java Programe from Oracle

Step 1
Write java prg and compile from Oracle bin folder
public class Hello
{
  public static String world()
  {
    return "Hello world";
  }
}
D:\app\oracle\product\11.1.0\db_1\BIN>javac  -target 1.5 Hello.java
------------------------------------------------------------------------
Step 2
load the class file
D:\app\oracle\product\11.1.0\db_1\BIN>loadjava -user hr/hr Hello.class
-------------------------------------------------------------------------
Step 3
Write a plsql function in SQL
CREATE OR REPLACE FUNCTION helloworld RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'Hello.world () return java.lang.String';
/
------------------------------------------------------------------------
Step 4
select helloworld() from dual;
Hello world

Oracle 11g Virtual Columns

VIRTUAL COLUMNS

   With 11g release, Oracle allows user to explicitly create virtual columns in a table.  These virtual columns are associated with an expression, which always generate the value for the virtual column.
 

  •       The data type of the virtual column is also optional. If it is not explicitly specified, it attains the return data type of the expression.
  •         The virtual property of a column can be queried in VIRTUAL_COLUMN of USER_TAB_COLS table.
  •          INSERT and UPDATE operation are disallowed on virtual columns.

EXAMPLE :

SQL> create table orders(oid number,oname varchar2(12),qty as (oid*30));

SQL> insert into orders(oid,oname) values(1,'Mouse');

SQL> insert into orders(oid,oname) values(2,'Keyboard');

SQL> commit;

SQL> select * from orders;

SQL> select * from USER_TAB_COLS where TABLE_NAME='ORDERS'

SQL> desc orders;