Version 15 of Oratcl

Updated 2003-08-27 15:08:17

Purpose: Discuss the Tcl <-> Oracle DBMS binding

http://oratcl.sf.net/ is the home page for this package binding Oracle to Tcl.

Insert your favorite Oratcl tips, tricks, and hints, etc. here. Also, point to various useful reading, such as BOOK Tcl/Tk Tools, or BOOK Oracle and Open Source.

"Cinderella languages" [L1 ] is a published article on Oratcl's origins.

Tom Poindexter created Oratcl. Todd M. Helfter currently maintains it. Tom Poindexter's Oratcl page http://www.nyx.net/~tpoindex/tcl.html has a little bit about Oratcl, but the primary work on the extension is being done by Todd via the SourceForge project.


Also add here information about tips for managing Unicode, images, etc. from within Oracle tables.

One thing that was discovered is that one needs to set something called the NLS before starting oracle and attempting to deal with UTF-8 data. This can be done using the NLS_LANG environment variable, or using something like SQLPLUS's alter session set nls_territory and 'alter session set nls_language to appropriate values.

Apparently, as long as NLS_LANG is set to some valid language, oracle then handles a localization sweep over the data properly before handing the data back to the requestor. Then, you do a call to

        encoding convertfrom utf-8 $string

and off you go.


Todd points out that, "OraTcl relies on the Oracle install. This means different things on different platforms.

On Unix, the ORACLE_HOME environment variable must point to a valid Oracle install.

On windows, the ociw32.lib file must be found in the WINDOWS search path. In the past, I have had to place the oracle directory in the windows PATH variable in autoexec.bat. In later releases, the registry information was sufficient to find the file."


Tcl has other connections to COMPANY: Oracle.


tksql is an application for editing PostgreSQL (not Oracle) tables.


LV For which version of Oratcl is this template - I seem to recall that at version changes, the paradigm used by oratcl programs had to change...

A recent article on comp.lang.tcl by Kevin Rodgers asked for comments about this sample boilerplate:

 # For error reporting:
 set program [file tail $argv0]

 # Package interface:
 package require Oratcl

 # Connect to the $env(TWO_TASK) database as USER with PASSWORD:
 if [catch {oralogon "USER/PASSWORD"} ora_logon] {
    puts stderr "$program: $ora_logon"
    exit 1
 }
 if [catch {oraopen $ora_logon} ora_statement] {
    oralogoff $ora_logon
    puts stderr "$program: $ora_statement"
    exit 1
 }
 #if [catch {oraconfig $ora_statement fetchrows 1024} ora_error] {
 #    puts stderr "$program: $ora_error"
 #} 

 # Execute SQL statement:
 set sql "SELECT column_1, ... column_N FROM ... WHERE ..."
 # Note that for Oratcl 4.x, the $oramsg references have to change to
 # [oramsg $ora_statement rc]
 if [catch {orasql $ora_statement $sql} ora_error] {
    puts stderr "$program: $ora_error"
 } elseif {$oramsg(rc) != 0} {
    puts stderr "$program: $oramsg(errortxt)"
 } else {
    # Process each row with column_I bound to var_I:
    while {$oramsg(rc) == 0} {
        if [catch {orafetch $ora_statement \
                            {... $var_1 ... $var_N ...} \
                            '@' var_1 1 ... var_N N} \
                  ora_error] {
            puts stderr "$program: $ora_error"
            break
        } elseif {$oramsg(rc) == 1403} {
            break
        } elseif {$oramsg(rc) != 0} {
            puts stderr "$program: $oramsg(errortxt)"
            break
        }
    }
 }

 # Disconnect from the $env(TWO_TASK) database:
 if [catch {oraclose $ora_statement ora_error] {
    puts stderr "$program: $ora_error"
 }
 if [catch {oralogoff $ora_logon ora_error] {
    puts stderr "$program: $ora_error"
 }

See also http://www.dbcorp.com/downloads/ORATCL.ppt for an intro to Oratcl (and Oracle's OEM) from 2000.

Addition of pointers to other Oratcl tutorials - particular current ones - would be greatly appreciated.


[ Category Package | Category Database ]