|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
help! - Stored Proccedures in KSH scripts
Hi,
I am new to KSH and need help in putting SQL Scripts into KSH. Here are sample of my sql scripts stored procedures... Anyone can do the equivalent in KSH? Thanks. ------------------------------------------------- CREATE OR REPLACE package body purgethis_pkg as beg_time date; sequence number; function initialData return number is seqid number; begin select purge_seq.nextval into seqid from dual; return seqid; end; procedure initialData as begin beg_time := sysdate; sequence := getPurgeNumber; end; procedure insertIntoMe( sequence number, dta varchar2 ) as pragma autonomous_transaction; begin insert into table_purge_me( id, sequence , dt, text ) values ( sequence, purge_seq2.nextval, sysdate, dta ); commit; end; procedure showRes( sequence number, dta varchar2 ) is begin dbms_application_info.set_module( pInfo, to_char( sysdate, 'dd/mm/yyyy hh24:mi:ss' ) ); insertIntoMe( sequence, dta ); end; end; -------------------------------------------------------- |
|
#2
|
|||
|
|||
|
I don't see what you're gaining by decalring packages in a shell script. Production reports and processing, yes.
Here's how: Code:
#!/bin/ksh
# assumes you issue sqlplus with the instacne already 'aimed' at with ORACLE_SID
# ie sqlplus user/pass gets you into Oracle
# otherwise you will have to add the instance name @instance
UID="username"
PSWD="password"
exsql () {
awk '{ if(NR == 1) {
STR=sprintf("%s/%s",UI,PW)
print STR
print "set echo off;"
}
print $0}' UI=$UID PW=$PSWD | sqlplus -s
}
# a package description must come before this package body
echo "
CREATE OR REPLACE package body purgethis_pkg
as
beg_time date;
sequence number;
function initialData
return number
is
seqid number;
begin
select purge_seq.nextval
into seqid
from dual;
return seqid;
end;
procedure initialData
as
begin
beg_time := sysdate;
sequence := getPurgeNumber;
end;
procedure insertIntoMe( sequence number, dta varchar2 )
as
pragma autonomous_transaction;
begin
insert into table_purge_me( id, sequence , dt, text ) values ( sequence, purge_seq2.nextval, sysdate, dta );
commit;
end;
procedure showRes( sequence number, dta varchar2 )
is
begin
dbms_application_info.set_module(
pInfo,
to_char( sysdate, 'dd/mm/yyyy hh24:mi:ss' ) );
insertIntoMe( sequence, dta );
end;
end;
/
" | exsql
|
|
#3
|
|||
|
|||
|
thx a lot jim mcnamara
Now i've written all the procedures in a sql scripts and will start it from a ksh. Will the following do the work, coz when i'm tetsting i don't receive anything.....even when checking if the instructions were well executed.... Code:
######################################### Checking is the db is accessible ######################################### tnsping $ODB > /dev/null if [ ! $? = 0 ]; then echo "DB ERROR" exit else echo "DB ACCESSIBLE" fi ######################################### Executing the SQL script ######################################### sqlplus -s $OUSER/$OPASS@$ODB >/dev/null << EOF sqlplus @MYSQLSCRIP_PKG.pkb.SQL ######################################### IF EXECUTION ERRORS ######################################### if [ ! "$?" = "0" ] ; then echo "EXECUTION ERROR" exit else echo "EXECUTION SUCCEED" exit fi |
|
#4
|
|||
|
|||
|
reply
hi
have a look into the unix section of this forum.. it tells u how to execute sql scripts..from unix i am not sure about the.....pl/sql though... |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > help! - Stored Proccedures in KSH scripts |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|