Monday, December 28, 2009

Time difference between two date columns

Ex 1
SELECT floor((date1-date2)*24) || ' HOURS ' ||
mod(floor((date1-date2)*24*60),60) || ' MINUTES ' ||
mod(floor((date1-date2)*24*60*60),60) || ' SECS ' time_difference
FROM dates

Ex 2
SELECT to_number( to_char(to_date('1','J') + (date1 - date2), 'J') - 1) days,
to_char(to_date('00:00:00','HH24:MI:SS') + (date1 - date2), 'HH24:MI:SS') time
FROM dates;

Ex 3
select numtodsinterval(date1-date2,'day') time_difference from dates;

Wednesday, July 1, 2009

VPN setup on Ubuntu

PPTP (Microsoft VPN)
sudo apt-get install network-manager-pptp

Cisco VPN
sudo apt-get install network-manager-vpnc

OpenVPN
sudo apt-get install network-manager-openvpn

Wednesday, June 3, 2009

Analytical Functions

Sample Run
-----------
drop table t1 purge;

create table t1 (c1 number, c2 number, c3 date default sysdate);

insert into t1 (c1,c2) values (1,10);
insert into t1 (c1,c2) values (1,20);
insert into t1 (c1,c2) values (1,30);
insert into t1 (c1,c2) values (2,10);
insert into t1 (c1,c2) values (2,15);
insert into t1 (c1,c2) values (3,10);
insert into t1 (c1,c2) values (3,11);
insert into t1 (c1,c2) values (4,10);

select * from t1;

select a.*, max(a.c2) over (partition by c1) max_c2
from t1 a;

select *
from (select a.*, max(a.c2) over (partition by c1) max_c2
from t1 a
) b
where b.c2 = b.max_c2
;


Output
--------

SQL> drop table t1 purge;
Table dropped.
SQL> create table t1 (c1 number, c2 number, c3 date default sysdate);
Table created.
SQL> insert into t1 (c1,c2) values (1,10);
1 row created.
SQL> insert into t1 (c1,c2) values (1,20);
1 row created.
SQL> insert into t1 (c1,c2) values (1,30);
1 row created.
SQL> insert into t1 (c1,c2) values (2,10);
1 row created.
SQL> insert into t1 (c1,c2) values (2,15);
1 row created.
SQL> insert into t1 (c1,c2) values (3,10);
1 row created.
SQL> insert into t1 (c1,c2) values (3,11);
1 row created.
SQL> insert into t1 (c1,c2) values (4,10);
1 row created.

SQL> select * from t1;
C1 C2 C3
---------- ---------- ---------
1 10 03-JUN-09
1 20 03-JUN-09
1 30 03-JUN-09
2 10 03-JUN-09
2 15 03-JUN-09
3 10 03-JUN-09
3 11 03-JUN-09
4 10 03-JUN-09
8 rows selected.

SQL> select a.*, max(a.c2) over (partition by c1) max_c2
from t1 a;
C1 C2 C3 MAX_C2
---------- ---------- --------- ----------
1 10 03-JUN-09 30
1 20 03-JUN-09 30
1 30 03-JUN-09 30
2 10 03-JUN-09 15
2 15 03-JUN-09 15
3 10 03-JUN-09 11
3 11 03-JUN-09 11
4 10 03-JUN-09 10
8 rows selected.

SQL> select *
from (select a.*, max(a.c2) over (partition by c1) max_c2
from t1 a) b
where b.c2 = b.max_c2 ;
C1 C2 C3 MAX_C2
---------- ---------- --------- ----------
1 30 03-JUN-09 30
2 15 03-JUN-09 15
3 11 03-JUN-09 11
4 10 03-JUN-09 10

Reference
-----------
http://www.orafaq.com/node/55

Sunday, May 17, 2009

Manually configure the Oracle 10g Enterprise Manager

oracle@nuwank:/home/app/oracle/product/10.2.0/db_1/bin$ emca -repos create


oracle@nuwank:/home/app/oracle/product/10.2.0/db_1/bin$ emca -config dbcontrol db

STARTED EMCA at May 18, 2009 10:46:20 AM
EM Configuration Assistant, Version 10.2.0.1.0 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.

Enter the following information:
Database SID: MYDB2
Database Control is already configured for the database MYDB2
You have chosen to configure Database Control for managing the database MYDB2
This will remove the existing configuration and the default settings and perform a fresh configuration
Do you wish to continue? [yes(Y)/no(N)]: Y
Listener port number: 1521
Password for SYS user:
Password for DBSNMP user:
Password for SYSMAN user:
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
-----------------------------------------------------------------

You have specified the following settings

Database ORACLE_HOME ................ /home/app/oracle/product/10.2.0/db_1

Database hostname ................ nuwank
Listener port number ................ 1521
Database SID ................ MYDB2
Email address for notifications ...............
Outgoing Mail (SMTP) server for notifications ...............

-----------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: Y



Wednesday, May 13, 2009

Display issue when switching between users - Ubuntu

Run xeyes with default user













Switch to oracle and run xeyes - Not working












Switch to oracle export DISPLAY and run xeyes


Tuesday, May 12, 2009

Display issue when switching between users

Run xclock with default user














Switch to oracle and run xclock - Not working











Install "sux"













Check again by connecting using sux

Friday, April 24, 2009

Reduce the icon size in Ubuntu 8.10

1. Open Nautilus
2. Edit –> Preferences –> View Tab
3. Adjust the zoom level under the “Icon View Defaults” to a preferable size.
By default it is set to 100%. Reducing it to 66% will end up with a fairly decent icon size.
4. Click “Close”