Monday, August 21, 2006

Merge continuous ranges

SQL> select * from test;

ID S E
---------- ---------- ----------
1 1 5
1 5 7
1 8 12
1 12 19

SELECT ID, MIN (x), MAX (x)
FROM (SELECT CEIL (ROWNUM / 2) rn, ID, x
FROM ((SELECT ID, s x
FROM TEST
MINUS
SELECT ID, e x
FROM TEST)
UNION
(SELECT ID, e x
FROM TEST
MINUS
SELECT ID, s x
FROM TEST)))
GROUP BY ID, rn


ID MIN(X) MAX(X)
---------- ---------- ----------
1 8 19
1 1 7

Friday, August 11, 2006

SSH port forwarding on Unix/Linux

ssh -L your_client_ip_or_name:port1:destination_ip_or_name:22 proxy_ip_or_name -l username

your_client_id_or_name (The machine you want to start the connection to destination)
port1:whatever port in the client machine
destination_ip_or_name (the machine you want to connect to)
proxy_ip_or_name (The machine used as proxy, it is connectable to your_client and destination)

ssh -p port1 your_client_ip_or_name
this will connect you to destination

client -> client port 1 -> proxy -> destination

Converting Unix time_t to Oracle Date

select to_date(19700101, 'YYYYMMDD') + unix_time_t/(24*60*60) from dual;