Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 5th, 2004, 01:30 AM
genociderus genociderus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 genociderus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;
--------------------------------------------------------

Reply With Quote
  #2  
Old October 5th, 2004, 12:22 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 20 m 49 sec
Reputation Power: 48
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

Reply With Quote
  #3  
Old October 6th, 2004, 02:42 AM
genociderus genociderus is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 genociderus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old October 6th, 2004, 02:51 PM
trianu trianu is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 trianu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > help! - Stored Proccedures in KSH scripts


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT