Category Archives: Uncategorized

oracle substrb function to chop a string down to its first 4000 bytes

The substrb 1 , 4000 function will chop a string down to its first 4000 bytes, e.g.: SELECT SUBSTR(’1€3′,2,1) , SUBSTRB(’1€3′,1,3) , LENGTH(’1€3′) , LENGTHB(’1€3′) FROM dual ; Needed if using the (non default) option of ‘char’ in column lengths: … Continue reading

Posted in Uncategorized | Leave a comment

Format sql files with sed: tab to space, pad commas with spaces, uppercase match

Shell script to make more readable all sql files in a directory – pads commas and brackets with whitespace, converts tabs to spaces, makes SQL keywords uppercase. # FUNCTIONS pad () { sed -i “s/\([^ ]\)$1/\1 $1/g” *sql sed -i … Continue reading

Posted in Uncategorized | 1 Comment

PL/SQL bulk collect union

PL/SQL bulk collect will work with UNION ALL when written with an inline view: DECLARE TYPE l_type_assoc IS TABLE OF VARCHAR2(14) INDEX BY BINARY_INTEGER ; l_big l_type_assoc ; BEGIN WITH q AS ( SELECT ename AS name FROM emp UNION … Continue reading

Posted in Uncategorized | Leave a comment

Extended Hexadecimal in Oracle

Standard decimal > hexadecimal is done with: select to_char ( 10 , ‘x’ ) from dual ; But I wanted a kind of extended hexadecimal that would keep single letters going up beyond 15/f, so would return ‘g ‘for decimal … Continue reading

Posted in Uncategorized | Leave a comment

Denormalise listagg children on single row comma separated

You can denormalise data using the listagg function, so to display users with their roles on a single line comma separated: SELECT grantee , LISTAGG ( granted_role , ‘ , ‘ ) WITHIN GROUP ( ORDER BY granted_role ) AS … Continue reading

Posted in Uncategorized | Leave a comment

Oracle remove duplicates parent child with listagg

De-duplicating parent – child table sets of data here using the listagg function to merge all the child rows into a single denormalised column. set serverout on BEGIN FOR d1 IN ( WITH denorm AS ( SELECT parent.aos_code , parent.pre_group_id … Continue reading

Posted in Uncategorized | Leave a comment

Copy mirror files with robocopy rsync lftp

The best utilities to use when copying/mirroring/backing up files are: robocopy – Windows rsync – Linux lftp – Linux without setting up password-less ssh Scripts can supply a password to sftp using lftp like this: lftp -u user:password sftp://server.domain.com << … Continue reading

Posted in Uncategorized | Leave a comment

bash check count processes

Simple bash command to check if processes are running: if [ $(pgrep -f pmon) ] then echo One or more databases running else echo No databases running fi Syntax gets more complex if you want to check for specific counts … Continue reading

Posted in Uncategorized | Leave a comment

Unlock oracle accounts without alter user system privilege

I wanted to give non-DBA users (Servicedesk, Operations) the ability to unlock database user accounts. The ‘alter user’ system privilege allows that, but it also gives out a lot more privileges (change password, kill session, alter DBA accounts) than I … Continue reading

Posted in Uncategorized | Leave a comment

Oracle 12c new features

Oracle 12c was released yesterday (25-Jun-2013). I’m a little bit underwhelmed by a first look at the new features guide – if that’s all there is, Oracle is going to continue to struggle against Microsoft SQL Server. Main change with … Continue reading

Posted in Uncategorized | Leave a comment