Thursday, November 1, 2012
Cursors in Teradata - simple example
/* Program to Revise the employees salaries and return count based on range for a particular department */
Create procedure emp_sal(IN deptno INTEGER,OUT vrow INTEGER)
Begin
Declare v_cur CURSOR FOR select empno,salary from emp where deptno=:deptno;
DEclare v_empno INTEGER;
Declare v_sal INTEGER;
Declare V_count INTEGER default 0;
Declare V_rowcount INTEGER;
Declare V_pcount INTEGER;
OPEN v_cur;
set v_rowcount=ACTIVITY_COUNT;
set v_pcount=v_rowcount;
Repeat
FETCH v_CUR into v_empno,v_sal;
set v_count =v_count+1;
if(v_sal<30000) then
set Rev_sal=v_sal+v_sal*10/100;
elseif
if(v_sal<50000) then
set Rev_sal=v_sal+v_sal*8/100;
else
set Rev_sal=v_sal+v_sal*5/100;
end if;
// to insert into other table
select current_date;
INSERT rev_emp_sal(v_empno,v_sal,rev_sal,:current_date);
// update the employee table
Update emp set sal=rev_sal where empno=v_empno;
v_pcount=v_pcount-1;
unit v_pcount=0;
set vrow=v_count;
close cur1;
end;
Subscribe to:
Post Comments (Atom)
Your blog is really awesome and I got some useful information from your blog. This is really useful for me. Thanks for sharing such a informative blog. Keep posting.
ReplyDeleteMicrosoft Dynamics CRM Online Training | Sharepoint Training