Bash script to check for final closing /data xml tag in file

Bash script to check for final closing </data> xml tag in file: if [ -f file.xml ] then # if grep -1iq ‘</data>’ file.xml # simplest syntax # if tac file.xml | grep -1iq ‘</data>’ # faster syntax (tac is reverse cat) if tail -100 file.xml | grep -1iq ‘</data>’ # fastest syntax, assumes at […]

Read More Bash script to check for final closing /data xml tag in file
June 23, 2015

One Comment

List oracle indexes and their columns with listagg

List indexes on large tables, with listagg to show the indexed columns in a comma separated line, and outer join to include tables with no indexes: SELECT t.owner , t.table_name , ROUND ( t.blocks * 8 / 1024 / 1024 ) AS gb — assuming each block is default 8kb , t.num_rows , i.index_name , […]

Read More List oracle indexes and their columns with listagg
June 17, 2015

Oracle distributed query join over remote database link slow performance leading driving_site hint fix

Oracle Optimizer doesn’t cope so well with distributed queries, joining to tables in different databases. 1) The leading and/or driving_site hints can dramatically improve distributed query performance. SELECT /*+ leading(tab1) driving_site(tab2) */ … FROM table1 AS tab1 JOIN table2@db2 AS tab2 … Driving_site specifies the database you want doing the bulk of the work, likely […]

Read More Oracle distributed query join over remote database link slow performance leading driving_site hint fix
June 16, 2015

Oracle User Group Scotland Conference 2015

Oracle User Group Scotland Conference 2015 1) SQLcl (SQL command line) new enhanced SQL*Plus, easy to output index info, DDL, output/load data in csv, xml. Early adopter (beta) version available for download now, production version expected soon and to be bundled by default into Oracle 12cR2. More at Kris Rice. 2) Relax and Recover Martin […]

Read More Oracle User Group Scotland Conference 2015

execute immediate quote escape oracle pl/sql

To run this via execute immediate: CREATE TABLE t2 AS SELECT * FROM t1 WHERE col1 = ‘1’ ; Either use new style quote format: EXECUTE IMMEDIATE q'[CREATE TABLE t2 AS SELECT * FROM t1 WHERE col1 = ‘1’]’ ; Or older style still works also: EXECUTE IMMEDIATE ‘CREATE TABLE t2 AS SELECT * FROM […]

Read More execute immediate quote escape oracle pl/sql
April 25, 2015

One Comment

Partition an existing oracle table example

I used this SQL to convert an existing non-partitioned table to be partitioned. Table was mostly queried on snapshot_id=’Current’, which had the most up to date data, but had much more historic data that was rarely queried against, all flagged with snapshot_id = ‘YYYYMMDD’ format. — 1) Create an empty table with one partition CREATE […]

Read More Partition an existing oracle table example
April 25, 2015

SQL to display date duration as number of years and months

Convert date duration (here customer age at time of first application) in years and months, e.g. ‘3408’ for 34 years and 8 months old: WITH customers AS ( SELECT SYSDATE AS appl_date , TO_DATE ( ’01-AUG-1980′ , ‘DD-MON-YYYY’ ) AS date_of_birth FROM DUAL ) SELECT TO_CHAR ( GREATEST ( 0 , LEAST ( 99 , […]

Read More SQL to display date duration as number of years and months
April 24, 2015

Rebuild table indexes lobs in oracle

Rebuilds are beneficial in some rare circumstances such as after a mass delete operation. The below method is safer and faster than export/import. Example table: CREATE TABLE tab1 ( col1 VARCHAR2(1) , col2 CLOB ) TABLESPACE ts1 ; CREATE INDEX tab1i ON tab1 ( col1 ) TABLESPACE ts1 ; List objects and tablespaces: SELECT tablespace_name […]

Read More Rebuild table indexes lobs in oracle
January 20, 2015

One Comment