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.

Answers were Sorted based on User's Feedback



can any one say how to update the following senario I have a table <srabank> in which the ..

Answer / 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

can any one say how to update the following senario I have a table <srabank> in which the ..

Answer / akhil

Hi, I am Akhil, I am also learing SQL, after reading your
question I have tried the pgm, please look into this.

And user need to give 2 accounts( from and to accounts )


create or replace procedure trans(acc1 in number, acc2 in
number,am in number) is
v_amount cus_details.amount%type;
begin
select amount into v_amount where acc_num=acc1;
if v_amount<am then
dbms_output.put_line('insufficient funds');
else
update cus_details set amount=amount-am where
acc_num=acc1;
dbms_output.put_line('amount debited from the
senders account');
update cus_details set amount=amount+am where
acc_num=acc2;
dbms_output.put_line('amount credited to the
receivers account');
end if;
end;


If any thing wrong, forgive me, thanks for making me to fee
about the task

Is This Answer Correct ?    0 Yes 0 No

can any one say how to update the following senario I have a table <srabank> in which the ..

Answer / akhil

the below program transfered the amount from one account to another account and generates the reference id and stores that reference id in the database;

in cus_det ac is the primary key
and in tranction table acc is the foreign key
then only reference number will be updated in the tranction table.

create or replace procedure test(acc1 in number,acc2 in number,amt in number) is
acm cus_det.am%type;
i number;
begin
select am into acm from cus_det where ac=acc1;
if acm<amt then
dbms_output.put_line('in sufficient funds');
else
update cus_det set am=am-amt where ac=acc1;
dbms_output.put_line('amount debited from senders account');
dbms_output.put_line('Tranction nnumber for your tranction....make a note of it for future reference');
select round(dbms_random.value(100000,200000)) into i from dual;
dbms_output.put_line(i);

update tranction set t_num=i where acc=acc1;
update cus_det set am=am+amt where ac=acc2;
dbms_output.put_line('amount credited to receivers account');
end if;
end;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What are the different type of replication in sql server?

0 Answers  


what information is maintained within the msdb database? : Sql server administration

0 Answers  


Is it possible to run multiple publications and different type of publications from the same distribution database? : sql server replication

0 Answers  


How to get a list of all tables with "sys.tables" view in ms sql server?

0 Answers  


What the different components of Replication and what is their use?

0 Answers  






hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.

0 Answers  


Explain transaction server isolation?

0 Answers  


Explain full-text query in sql server?

0 Answers  


How many types of database relationship in sql server?

0 Answers  


Tell about MOM Tool(Microsoft Operator Manager)?

0 Answers  


Write a program using SQL queries to find a unique entry in a table.

0 Answers   Tech Mahindra,


What are types of subqueries?

0 Answers  


Categories