PREV INDEX NEXT    SLUUG HOME

SQL in KSH
Running SQL Scripts in Kornshell

Variables


USING SHELL VARIABLES IN SQLPLUS


    table=$1; field=$2; value=$3
    sqlplus -s <<!
    select * from $table where $field = $value;
    !
    

    dfmt=\'yyyy-mm-dd\' # hardcoding quotes for SQL
    sqlplus -s <<!  # separate SQL script
    select to_char(sysdate,$dfmt) from dual;
    !

    dfmt=yyyy-mm-dd # quotes unneeded due to define
    sqlplus -s <<!
    define dfmt = $dfmt
    select to_char(sysdate,'&dfmt') from dual;
    !

    sqlplus -s <<!
    define tbl = &1
    define fld = &2
    select '&tbl', &fld, count(&fld) from &tbl
    group by &fld order by &fld;
    !
    

2002 April 10
Tom Chapin -- 314-721-3581 -- tjc@mvp.net