can any one say how to update the following senario

I have a table <srabank>
in which the table structure is as follows
ANAME ACCNO LOCATION ACCTYPE BAL
SBanuPrakash 31518746291 Punganur deposit 4000
Sreenivas 31518746292 mahoobnagar current 14000
Ranjith 31518746293 Karimnagar Savings 2000
Giresh 31518746294 Chennai deposit 40000
Boo 31518746295 Chennai Savings 20000
Jay 31518746296 Valachari Savings 1000
tirumalraj 31518746297 Vellore Savings 8000

The senario is
We need to select one account number and check the balance after checking the balance if the balance exist we need to transfer to another account .
in the from account the amount need to be reduced and in the to account the amount needed to be added.
for example
for the <accountno> <31518746291> the balance is <4000>
for the <accno> <31518746292> the balance is <14000>

after transferring the balance the details will look as follows
<accno><31518746291> <bal> <2000>
<accno><31518746292> <bal> <16000>
the above mentioned two statment will come under the final result.

Answer Posted / bijaylaxmi

create or replace procedure proc_bal (paccno srabank.accno%type)
is
pbal srabank.bal%type;
pacctype srabank.acctype%type;
pamt number:=2000;
begin
select bal,acctype into pbal,pacctype from srabank where accno=paccno;
if pacctype= 'rd' and pbal>0
then pbal:=pbal+pamt;

elsif pacctype= 's' and pbal>0
then pbal:=pbal-pamt;
elsif pacctype= 'c' and pbal>0
then pbal:=pbal*pamt;
end if;
dbms_output.put_line( pbal);
insert into srabank_tran values (pbal,paccno);
insert into srabank_det select amt,accno from srabank_tran;
end proc_bal;

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me the use of keyword with encryption. Create a store procedure with encryption?

548


How to create and drop temp table in sql server?

585


What are statistics?

566


What is lookup override?

584


How to insert data with null values?

580






How do I open a .db file?

476


What is instead of trigger sql server?

495


Explain various On-Delete options in a DB table. Which is the default option?

891


what is the difference in login security modes between v6.5 and 7.0? : Sql server database administration

643


What is the difference between a local and a global temporary table?

616


what is a correlated sub-query? : Sql server database administration

480


State the difference between local and global temporary tables?

556


How to create a view and a stored procedure in ms sql server using "create view/procedure" statements?

506


How to create a local temporary stored procedure?

497


What are the new features introduced in SQL Server 2000 (or the latest release of SQL Server at the time of your interview)? What changed between the previous version of SQL Server and the current version?

583