zenity

Sometimes you learn something new and ask yourself : how is it possible I’ve never seen this before. Zenity is a tool that allows you to display Gtk+ dialog boxes from the command line and through shell scripts. Here is a rather crude example:

#!/bin/sh

ORATAB=/etc/oratab; export ORATAB
ORAENV=/usr/local/bin/oraenv;export ORAENV



# Set this in accordance with the platform
db=`if [ ! $ORATAB ] ; then
      echo "$ORATAB not found"
      exit 1;
    fi

    (cat $ORATAB |grep -v "^$" | while read LINE
    do
    case $LINE in
      \#*)                ;;
      *)                  echo FALSE
                          echo $LINE | awk -F: '{print $1}'
                          ;;
    esac
    done) |
    zenity  --list  --text "Choose a database" --radiolist  --column "Pick" --column "Database" --width=300 --height=300`

un=`zenity --entry \
        --title="Username for $db " \
        --text="Enter your _username:" \
        --entry-text "system"`

pw=`zenity --entry \
        --title="Add an Entry" \
        --text="Enter your _password for $db:" \
        --entry-text "password" \
        --hide-text`

zenity --question \
          --text="Are you sure you wish to logon on $db as $un?"
if [ $? ]
then
   ORACLE_SID=$db;export ORACLE_SID
   ORAENV_ASK=NO;export ORAENV_ASK
   $ORAENV $db
   sqlplus $un/$pw@$db
fi

Run this script:



Oracle Leave a comment

VirtualBox 4.0 released

Cube


Oracle VM VirtualBox is an x86 virtualization software package. It is installed on an existing host operating system; within this application, additional guest operating systems, each known as a Guest OS, can be loaded and run, each with its own virtual environment.

Get it here

Oracle Leave a comment

Select hidden optimizer parameters

Hidden parameters are not included in the v$parameter view. Use this statement to view all optimizer parameters in a 11g (and 10g) database:

SELECT
  x.ksppinm name,
  y.ksppstvl VALUE,
  decode(ksppity,
    1,   'BOOLEAN',
    2,   'STRING',
    3,   'INTEGER',
    4,   'PARAMETER FILE',
    5,   'RESERVED',
    6,   'BIG INTEGER',
    'UNKNOWN') typ,
  decode(ksppstdf,
    'TRUE',   'DEFAULT VALUE',
    'FALSE',   'INIT.ORA') isdefault,
  decode(bitand(ksppiflg / 256,   1),
    1,   'IS_SESS_MOD(TRUE)',
    'FALSE') isses_modifiable,
  decode(bitand(ksppiflg / 65536,   3),
    1,   'MODSYS(NONDEFERED)',
    2,   'MODSYS(DEFERED)',
    3,   'MODSYS(*NONDEFERED*)',
    'FALSE') issys_modifiable,
  decode(bitand(ksppstvf,   7),
    1,   'MODIFIED_BY(SESSION)',
    4,   'MODIFIED_BY(SYSTEM)',
    'FALSE') is_modified,
  decode(bitand(ksppstvf,   2),
    2,   'ORA_STARTUP_MOD(TRUE)',
    'FALSE') is_adjusted,
  ksppdesc description,
  ksppstcmnt update_comment
FROM x$ksppi x,
  x$ksppcv y
WHERE x.inst_id = userenv('Instance')
 AND y.inst_id = userenv('Instance')
 AND x.indx = y.indx
 AND x.ksppinm LIKE '%optim%';

Oracle Leave a comment

Tsst

Words of wisdom from the man :

    “To be happy, (dogs) basically need a good job, and good food, and a pat on the head. Americans tend to over-do on the affection and under-do on the exercise.”
    “Stay calm and assertive.”
    “Humans are the only animals who will follow unstable pack leaders.”

Click on his image for an impression of his work. You’ll first have to sit through some advertising.

Fun 1 Comment

Data transformation: pipelined functions and ref cursor

create table all_tables_plus as select * from all_tables where 1 = 2;
alter table all_tables_plus add (prev_table_name varchar2(30));
 
 
 
create or replace package ref_pkg is
  type refcur_tables IS REF CURSOR RETURN all_tables%ROWTYPE;
  type t_tables_plus IS TABLE OF all_tables_plus%ROWTYPE;
end ref_pkg;
/
 
create or replace function add_prev_table (cur_tables IN ref_pkg.refcur_tables)
return ref_pkg.t_tables_plus pipelined
IS
  l_prev_table_name VARCHAR2(30) := NULL;
  l_tables          all_tables%ROWTYPE;
  l_tables_plus     all_tables_plus%ROWTYPE;
BEGIN
  LOOP
   FETCH cur_tables INTO l_tables;
   EXIT WHEN cur_tables%NOTFOUND;
   l_tables_plus.table_name :=  l_tables.table_name;
   l_tables_plus.prev_table_name := l_prev_table_name;
   l_prev_table_name := l_tables.table_name;
   PIPE ROW(l_tables_plus);
  END LOOP;
END;
/
 
 
select table_name,prev_table_name
from table(add_prev_table(cursor(select * from all_tables)));

TABLE_NAME PREV_TABLE_NAME
DUAL  
SYSTEM_PRIVILEGE_MAP DUAL
TABLE_PRIVILEGE_MAP SYSTEM_PRIVILEGE_MAP
STMT_AUDIT_OPTION_MAP TABLE_PRIVILEGE_MAP
AUDIT_ACTIONS STMT_AUDIT_OPTION_MAP
PSTUBTBL AUDIT_ACTIONS
WRI$_ADV_ASA_RECO_DATA PSTUBTBL
PLAN_TABLE$ WRI$_ADV_ASA_RECO_DATA
OL$ PLAN_TABLE$
Uncategorized Leave a comment

Put XML data into a relational table

First put the XML data into a Oracle tables XMLTYPE column:

DROP TABLE XMLTEST;

CREATE TABLE XMLTEST
(	XML_COL XMLTYPE);

DECLARE
  poXML CLOB;
BEGIN
  -- Store the Purchase Order XML in the CLOB variable
  poXML := '

	
		88
		01 West 430
		eXpress_BK
	
	
		170
		02 Midden 010
		eXpress_BK
	
	
		173
		02 Midden 110
		eXpress_BK
	
	
		F491B0A119DABE76B2F6B2C0A3E902F6
		183
		02 Oost 010
		eXpress_BK
	
	
		172
		02 Oost 300
		eXpress_BK
	
  .
  .
  .
	
		F491B0A119DABE76B2F6B2C0A3E901E3
		129
		HB.02.140
		eXpress_EWI
	
';
  -- Insert the Purchase Order XML into an XMLType column
  INSERT INTO xmltest (xml_col) VALUES (XMLTYPE(poXML));

END;

Use XMLTable function to create the table:

drop table zalen;
create table zalen as
select xt.zaal_id
,      xt.altiris_id
,      xt.syllabus_id
,      xt.altiris_db
,      xt.display_naam
from xmltest xts
,    XMLTable('zalen/zaal' PASSING xts.xml_col
                   columns zaal_id INTEGER PATH '@zaal_id'
                             ,altiris_id INTEGER PATH 'altiris_id'
                             ,syllabus_id VARCHAR2(100) PATH 'syllabus_id'
                             ,display_naam VARCHAR2(100)PATH 'display_naam'
                             ,altiris_db VARCHAR2(100)PATH 'altiris_db') xt;

Let’s make it a little more complex. Given:




 
  
    Biotechnology
    
      
      
    
  
  
    Chemical Engineering
    
      
      
      
      
      
    
  
  
    Applied Physics
    
      
      
      
      
      
      
      
    
  


  
    EWI Practicumgebouw
    
      
      
      
      
      
      
      
      
      
      
      
      
      
    
  
  
    Elektrotechniek, Wiskunde en Informatica
    
      
      
      
      
    
  


Load the XML file into the table.

select xt1.naam as faculteit
,xt2.gebouw_id,xt2.gebouw_naam,xt3.zaal_id
from xmlzaalindeling xts
,    XMLTable('gebouwindeling/faculteit'
     PASSING xts.xml_col
     COLUMNS naam VARCHAR2(100) PATH '@naam'
            ,gebouwen_t XMLTYPE PATH 'gebouwen') xt1
,    XMLTable('gebouwen/gebouw'
     PASSING xt1.gebouwen_t
     COLUMNS gebouw_id INTEGER PATH '@gebouw_id'
            ,gebouw_naam VARCHAR2(100) PATH 'gebouw_naam'
            ,zalen_t XMLTYPE PATH 'zalen') xt2
,    XMLTable('zalen/zaal'
     PASSING xt2.zalen_t
     COLUMNS zaal_id INTEGER PATH '@zaal_id') xt3
;

FACULTEIT GEBOUW_ID GEBOUW_NAAM ZAAL_ID
TNW 5 Biotechnology 37
TNW 5 Biotechnology 38
TNW 12 Chemical Engineering 39
TNW 12 Chemical Engineering 40
TNW 12 Chemical Engineering 41
TNW 12 Chemical Engineering 42
TNW 12 Chemical Engineering 43
TNW 22 Applied Physics 44
TNW 22 Applied Physics 45
TNW 22 Applied Physics 46
TNW 22 Applied Physics 47
TNW 22 Applied Physics 48
TNW 22 Applied Physics 49
TNW 22 Applied Physics 50
EWI 35 EWI Practicumgebouw 109
EWI 35 EWI Practicumgebouw 110
EWI 35 EWI Practicumgebouw 111
EWI 35 EWI Practicumgebouw 112
EWI 35 EWI Practicumgebouw 113
EWI 35 EWI Practicumgebouw 114
EWI 35 EWI Practicumgebouw 115
EWI 35 EWI Practicumgebouw 116
EWI 35 EWI Practicumgebouw 117
EWI 35 EWI Practicumgebouw 118
EWI 35 EWI Practicumgebouw 120
EWI 35 EWI Practicumgebouw 121
EWI 35 EWI Practicumgebouw 122
EWI 36 Elektrotechniek, Wiskunde en Informatica 123
EWI 36 Elektrotechniek, Wiskunde en Informatica 124
EWI 36 Elektrotechniek, Wiskunde en Informatica 125
EWI 36 Elektrotechniek, Wiskunde en Informatica 126
Oracle, Uncategorized, XML 2 Comments

Using TABLE function with CAST

Using this method whe can use a function that returns a collection as a table in the FROM clause of a SELECT

First we create a FUNCTION that returns a Collection.

CREATE OR REPLACE TYPE rob_type IS OBJECT (n1 NUMBER,n2 NUMBER,v1 VARCHAR2(100));
/

CREATE OR REPLACE TYPE rob_table_type IS TABLE OF rob_type;
/

CREATE OR REPLACE FUNCTION rob_function (startn INTEGER , endn INTEGER)
RETURN rob_table_type
IS
  retval rob_table_type := rob_table_type();
  PROCEDURE expand_collection (rob IN rob_type)
  IS
  BEGIN
    retval.extend;
    retval(retval.LAST) := rob;
  END;
BEGIN
  FOR i in startn .. endn
  LOOP
    expand_collection(rob_type(i,i*i,to_char(sysdate,'SSSSS')));
  END LOOP;
  return retval;
END;
/

Now we can use it in a SELECT

SQL> select * from TABLE(CAST(rob_function(1,10) AS rob_table_type));

    N1     N2 V1
------ ------ ----------------------------------------------------------------
     1      1 30823
     2      4 30823
     3      9 30823
     4     16 30823
     5     25 30823
     6     36 30823
     7     49 30823
     8     64 30823
     9     81 30823
    10    100 30823

10 rows selected.
Oracle Leave a comment

Dump XML Data from the Database to the OS

I have used Oracle XML DB on a few occasions to dump relational data into xml files. Until now I did not have a method to dump the results directly onto the filesystem.

The filename parameter of dbms_xmldom.writeToFile takes a Oracle Directory name and a filename.
dbms_xmldom.newDOMDocument

DECLARE
   xmldoc xmltype;
BEGIN
   SELECT Sys_Xmlagg(
         Xmlelement(Name "student"
                   ,Xmlforest(os.studentnummer AS "studentnummer"
                            ,CAST(osvv.inhoud AS VARCHAR2(10)) AS "toisnummer"
                            ,os.achternaam AS "achternaam"
                            ,os.voorvoegsels AS "voorvoegsels"
                            ,os.voorletters AS "voorletters"
                            ,os.voornamen AS "voornamen"
                            ,to_char(os.geboortedatum,'YYYY-MM-DD')||
                                        'T00:00:00' AS "geboortedatum")
                   ),Xmlformat('studenten'))
   INTO xmldoc
   FROM ost_student os ,
     ost_student_vrij_veld osvv ,
     ost_student_inschrijfhist osi
   WHERE osvv.studentnummer(+) = os.studentnummer
   AND osi.studentnummer    = os.studentnummer
   AND sysdate BETWEEN osi.ingangsdatum AND osi.afloopdatum
   AND osi.actiefcode_opleiding_csa = 4
   AND osvv.vrij_veld(+)               = 'TOIS nummer';
   dbms_xmldom.writeToFile(dbms_xmldom.newDOMDocument( xmldoc)
                                       ,'DATAPUMP/myfile.xml') ;
END;
/

Results in



  
    1234556
    Suijkerbuik
    J.J.
    Jean Jaques
    1980-12-11T00:00:00
  
  
    1234567
    Klooster
    B.B.
    Barend Bastiaan
    1966-12-12T00:00:00
  

Oracle, XML Leave a comment

SQL Developer : tip 1

Tired of typing to_char(datefield,'DD-MM-YYYY HH24:MI:SS') when you want to display the time component of the DATE field?

Tools|Preferences|Database|NLS
Change Date Format to: DD-MON-RR HH24:MI:SS

Oracle Leave a comment

Using CURSOR function with Query Web Service

This is an example of the use of the CURSOR function within a Query Web Service call to generate subnodes in de XML output. I stumbled on this link looking into the DBMS_XMLGEN functionality. So let’s see wat that does within a Query Web Service Call.


   
   
      
         

         false
         DEPARTMENTS
         DEPARTMENT
      
   


   
      
         
            
               10
               Administration
               
                  
                     Jennifer
                     Whalen
                  
               
            
            
               20
               Marketing
               
                  
                     Michael
                     Hartstein
                  
                  
                     Pat
                     Fay
                  
               
            
            
               30
               Purchasing
               
                  
                     Den
                     Raphaely
                  
                  
                     Alexander
                     Khoo
                  
                  
                     Shelli
                     Baida
                  
                  
                     Sigal
                     Tobias
                  
                  
                     Guy
                     Himuro
                  
                  
                     Karen
                     Colmenares
                  
               
            
         
      
   

Now that’s pretty cool.

Oracle, SOA Leave a comment
Wordpress Code Snippet by Allan Collins