Thursday, April 24, 2014

Oracle: select from list of values

select distinct column_value from table(sys.odcinumberlist(1,1,2,3,3,4,4,5));
or
select column_value from table(sys.dbms_debug_vc2coll('One', 'Two', 'Three', 'Four'));

Tuesday, April 1, 2014

ORA-01555: snapshot too old: rollback segment number 61 with name "_SYSSMU61_1706556987$" too small

SQL> select max(maxquerylen) from v$undostat;

26687
Add 20% to this value and update UNDO_RETENTION parameter.
SQL> ALTER SYSTEM SET UNDO_RETENTION = 32024;

Wednesday, March 26, 2014

Update CPAN perl packages

cpan upgrade /(.*)/

Sunday, March 23, 2014

Mavericks 10.9.2: network lost after upgrade

Symptom: network stopped working suddenly after Mavericks upgrade
History:
  1. Updated Mavericks to 10.9.2 using Combo update
  2. Re-installed conf. using MultiBeast 6.2.1
  3. Reboot
  4. Network KO
  5. Repair permissions: sudo diskutil repairPermissions /
  6. Reboot

Friday, March 21, 2014

Friday, February 28, 2014

Oracle: monitoring long tasks

SELECT start_time, username, target, sofar blocks_read, totalwork total_blocks, round(time_remaining/60) minutes FROM v$session_longops WHERE sofar <> totalwork;

Friday, February 14, 2014

PL/SQL: how to deal with nullable variables in query

where decode(column, variable, 0) is not null

Friday, January 17, 2014

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

Find the blocking session port, and then kill the process listening on that port.
SELECT O.OBJECT_NAME, S.SID, S.SERIAL#, P.SPID, S.PROGRAM,S.USERNAME,
S.MACHINE,S.PORT , S.LOGON_TIME,SQ.SQL_FULLTEXT 
FROM V$LOCKED_OBJECT L, DBA_OBJECTS O, V$SESSION S, 
V$PROCESS P, V$SQL SQ 
WHERE L.OBJECT_ID = O.OBJECT_ID 
AND L.SESSION_ID = S.SID AND S.PADDR = P.ADDR 
AND S.SQL_ADDRESS = SQ.ADDRESS;
[root@dwh1 ~]# netstat -ap | grep 22735
tcp        1      0 dwh1.prod.mbqt:ncube-lm     dwh1.prod.mbqt:22735        CLOSE_WAIT  19050/oracledwhmbqt 

[root@dwh1 ~]# kill -9 19050

VirtualBox: force guest IP address

> sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:B5:56:05
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=static
#IPADDR=192.168.2.8
IPADDR=192.168.1.101
NETMASK=255.255.255.0
TYPE=Ethernet
DNS1=8.8.8.8
DNS2=8.8.4.4
Then restart network
> sudo service network restart

Wednesday, January 15, 2014

/usr/bin/perl^M: bad interpreter

One perlish way to fix this:
>./fm_test.pl
-bash: ./fm_test.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
is:
> perl -pi -e 'tr[\r][]d' ./fm_test.pl
Another way is to use dos2unix

Wednesday, January 8, 2014

Compute files size

find . -name "*" -ls | awk '{total += $7} END {print total}'

Tuesday, January 7, 2014

Vim backspace issue

If backspace leaves ^? in vim, this is most probably because of "stty erase ^H" being present either in your .bashrc or .bash_profile.
Remove it and Vim will be happy with backspace.

Friday, November 22, 2013

Oracle: ORA-14402: updating partition key column would cause a partition change

This can be circumvented with:
ALTER TABLE my_table ENABLE ROW MOVEMENT;

Wednesday, November 20, 2013

Perl: sort hash values by keys

my @sorted_values = @hash{sort {$a <=> $b} keys %hash};

Oracle: aggregate data from a number of rows into a single row

Base Data:

    DEPTNO ENAME
---------- ----------
        20 SMITH
        30 ALLEN
        30 WARD
        20 JONES
        30 MARTIN
        30 BLAKE
        10 CLARK
        20 SCOTT
        10 KING
        30 TURNER
        20 ADAMS
        30 JAMES
        20 FORD
        10 MILLER

SELECT deptno, LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
FROM   emp
GROUP BY deptno;

    DEPTNO EMPLOYEES
---------- --------------------------------------------------
        10 CLARK,KING,MILLER
        20 ADAMS,FORD,JONES,SCOTT,SMITH
        30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD

Thursday, November 14, 2013