Home » Developer & Programmer » Forms » insert only 1 record...
insert only 1 record... [message #613226] Thu, 01 May 2014 05:24 Go to next message
shahzad-ul-hasan
Messages: 615
Registered: August 2002
Senior Member
declare
	b varchar2(70);
	d number;
	e number;
	f varchar2(30);
	g number;
	h number;
	i number;
cursor xyz is select nvl(s.Stuid,0),nvl(S.Tuition,0),nvl(max(ff.sno),0),(nvl(ff.tot,0)+nvl(Arrear,0))-nvl(paid,0) bal,s.fam_id
from student s,fees ff
where s.stuid=ff.stuid(+) AND S.STATUS='PRESENT' and ff.fstat in ('N_RECEIVED','RECEIVED')
GROUP BY S.Stuid,S.Tuition,(nvl(ff.tot,0)+nvl(Arrear,0))-nvl(paid,0),s.fam_id
order by s.stuid;
begin
open xyz;
loop
fetch xyz into b,d,g,h,i;
exit when xyz%notfound;
     if h > 0 then
 insert into fees   
 (stuid,fmonth,tmonth,fyear,ftution,fstat,annual,sno,tot,arrear,bal,chl_no,fam_id)
  values
 (b,:fmonth,:tmonth,:year1,d*:NM,'N_RECEIVED',:ANN,g+1,(d*:NM)+nvl(:ann,0),nvl(h,0),
 nvl(h,0)+nvl(:ann,0)+nvl(d,0),chal.nextval,i);	
 else
 insert into fees (stuid,fmonth,tmonth,fyear,ftution,fstat,annual,sno,tot,arrear,bal,chl_no,fam_id)
values
(b,:fmonth,:tmonth,:year1,d*:NM,'N_RECEIVED',:ANN,g+1,d*:NM+nvl(:ann,0),0,
  nvl(h,0)+nvl(:ann,0)+nvl(d,0),chal.nextval,i);	
end if;    
end loop;
commit;
close xyz;
next_item;
end;

i want to prevent the insert duplicate record. please advised .please view the attached file./forum/fa/11859/0/
Re: insert only 1 record... [message #613227 is a reply to message #613226] Thu, 01 May 2014 05:41 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
What is the criterion for a row being duplicated? Is there a primary key somewhere?
But apart from that, I think your logic may be flawed: you are testing whether H is NULL within an IF clause that has already tested whether H is greater than 0. You have in any case used NVL when calculating H.
Also, I see no need for PL/SQL at all. You can do all this with SQL, just an INSERT statement. That will be much easier to write and to understand, and of course be astronomically faster to run.
Re: insert only 1 record... [message #613228 is a reply to message #613227] Thu, 01 May 2014 05:48 Go to previous message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
1) The best way of restricting duplicates is to have database table level Primary Key
(2)Minimize coding USE the In Built Oracle Functionalities


(1) First apply the constraint at Table level or column level
(2) Then use INSERT STATEMENT.
(3) Write exception to catch error
(3) If any duplicate value, it automatically fails the INSERT Statement

[Updated on: Thu, 01 May 2014 06:07]

Report message to a moderator

Previous Topic: Is it possible to generate Solaris compatible .fmx in windows?
Next Topic: UTF-8 in Oracle 6i
Goto Forum:
  


Current Time: Wed Apr 24 19:39:57 CDT 2024