472,978 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

Its very very urgent Please....Could you please help.plz help in solving queries

Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors...
The table structures i hav

Employee (EmpID, EmpName,DeptID,DateOfJoin, Sal, Addr)
Finance (EmpID, Sal)
Club (Clubname, EmpID, Fee, DateOfJoin)
Leave (EmpID, Date)
Department (DeptID, DeptName, NoOfEmployees)
-----------------------------------------------------------------------------------------------------
The queries i hav tried... please help me with the code to sovle errors.. I m a fresher .... please help me....

1) write a PL/SQL block to increase the salary of a given employee by 15 % if the years of experience of that employee is greater than 2 years else generate an error using Raise_Application_Error.

DECLARE
CURSOR C_EMP1 IS
SELECT EmpId from Employee where (SYSDATE-Employee.DateOfJoin)/730>1;
Emp_Rec C_EMP1%ROWTYPE;
Begin
Open C_EMP1;
For rec1 in C_EMP1
Loop
Fetch C_EMP1 into Emp_Rec;
Exit when C_EMP1%NOTFOUND;
UPDATE Employee
SET Sal=Sal+0.15*Sal;
End Loop;
Close C_EMP1;
End; // Error – Cursor already open

2) write a PL/SQL block to update the salary of all employees by 10 %. Make use of For Update and Where Current of Clauses in cursor.

DECLARE
CURSOR C_EMP IS
SELECT EmpId,Sal from Employee
For Update NOWAIT;
Emp_Rec C_EMP%ROWTYPE;
Begin
Open C_EMP;
Loop
Fetch C_EMP into Emp_Rec;
Exit when C_EMP%NOTFOUND;
UPDATE Employee
SET Sal=Sal+0.1*Sal
Where current of C_EMP;
DBMS_OUTPUT.PUT_LINE(‘Processed Rows :’|| sql%rowcount);
End Loop;
Close C_EMP;
End; // Successful – But not displaying the processed rows

3) write a PL/SQL block to display the employees joined in a given club. Make use of cursor with parameters for fetching data.

Declare
Emp_Rec Employee%ROWTYPE;
Cursor C1 (club Varchar2:=&name) is
Select EmpId from Club
Where Club.ClubName=club group by clubName;
Cursor C2(empid Employee.EmpId%TYPE) is
Select EmpName from Employee
Where Employee.EmpId=empid;
Begin
For mrec in C1
Loop
For mrec1 in C2(mrec.empid)
Loop
DBMS_OUTPUT.PUT_LINE(mrec1.EmpName);
End Loop;
End Loop;
End; /// identifier 'GYMNASIUM' must be declared and wrong number or types of arguments in call to 'C1'

4) Write a stored function that receives an employee number and returns the total salary deductions for that employee.

Create or Replace Function Emp_Fn(eno IN Employee.EmpId%TYPE:=0 ,sal OUT Employee.Sal%TYPE)
Is
Return Number
As
Begin
Select sal=Employee.Sal-(Club.Fee+Employee.Sal/30*Leave.NoOfLeave) into Sal
From Employee,Club,Leave
Where EmpId=eno;
End;
/


5) write a PL/SQL block to find the no of employees in each club.

Declare
V_count number(10);
V_clubname varchar2(15);
V_empid number(10);
Begin
Select ClubName,EmpId into v_clubname,v_empid
From club
Group by ClubName;
v_count:=(sql%rowcount);
dbms_output.put_line(v_count);
End;

6) whenever a new employee is added to the employee table one row should be added in the Finance table for that employee and update Department table such that Department.NoOfEmployees = Department.NoOfEmployees + 1.
Whenever the salary field is updated the difference should be updated in the finance table.



CREATE OR REPLACE TRIGGER mytrig
After INSERT ON Employee
FOR each ROW
BEGIN
IF inserting THEN
INSERT INTO Finance VALUES(:NEW.empno,:NEW.sal);
UPDATE INTO Department SET Department.NoOfEmployees = Department.NoOfEmployees + 1;
END IF;
END;


7)how to display the salary deduction details for the employees in a given department for a given month. The salary deduction is sum ( Club fees for that employee) + ( Employee.Sal / 30 * no of leaves taken for that month)

Declare
v_s_date date := &startdate;
v_e_date date := &enddate;
Begin
select EmpId,count(date)
from Leave
where date between v_s_date and v_e_date
end

Declare
V_eno Employee.EmpId%TYPE:=&no;
v_clubfee Club.Fee%TYPE;
v_sal Employee.Sal%TYPE;
v_finalsal Employee.Sal%TYPE;
v_noofleave Leave%DateOfLeave%TYPE;
Begin
Select v_sal=v_sal-(v_clubfee+v_sal/30*v_noofleave) into v_finalsal
From employee where EmpId:=&v_eno;
End;


how to combine both the queries ? will i get the ans if i write query lik dis?


8) write a PL/SQL block to display the employee details with department name and salary deductions. Make use of cursor for loops to fetch rows.

How to calculate the salary deductions and to display?



9)write a stored function to find the employee ID who is having highest no of memberships.

Create or Replace Function F1(count IN Number, empid Employee.EmpId)
Is
Return number
As
Begin
Select count(ClubName),EmpId
From Club
Groupby EmpId;
End;


10) How to write a stored procedure that deletes all the rows from the finance table and insert new values into it. Make use of the stored function to find the deduction in salary. Finance.Sal = Employee.Sal – deductions.
Jul 7 '07 #1
6 3225
debasisdas
8,127 Expert 4TB
In the article section of oracle of ths forum u will find hundreds of sample examples on all of your requested topic.
try to follow those.
if u still have doubts then please do post back.
Jul 9 '07 #2
In the article section of oracle of ths forum u will find hundreds of sample examples on all of your requested topic.
try to follow those.
if u still have doubts then please do post back.

I have gone through the articles and tried answers for these queries .. But stil i have doubt and hence posted with the ans i have tried.... Could you please check and tell me where i went wrong.This is my first assignment and haven't undergone any training. thats y i seek help badly from this forum.....
Jul 9 '07 #3
debasisdas
8,127 Expert 4TB
please check your PMs on the top of the page of the site.
Jul 9 '07 #4
debasisdas
8,127 Expert 4TB
Ans #1
===========
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR C_EMP IS SELECT EmpNO from Emp where (SYSDATE-HIREDATE)/730 > 1;
  3. Begin
  4. For rec1 in C_EMP
  5. Loop
  6. Exit when C_EMP%NOTFOUND;
  7. UPDATE Emp SET Sal=Sal * 1.15 where empno=rec1.empno;
  8. End Loop;
  9. End;
Generally raise_appication_error is not used within a cursor.
Jul 14 '07 #5
debasisdas
8,127 Expert 4TB
Ans #2
===========
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR EMPREC IS SELECT * FROM EMP FOR UPDATE OF SAL NOWAIT;
  3. MYREC EMPREC%ROWTYPE;
  4. NUM NUMBER(4);
  5. BEGIN
  6. OPEN EMPREC;
  7. LOOP
  8. FETCH EMPREC INTO MYREC;
  9. EXIT WHEN EMPREC%NOTFOUND;
  10. NUM:=EMPREC%ROWCOUNT;
  11. UPDATE EMP SET SAL=SAL * 1.10 WHERE CURRENT OF EMPREC;
  12. END LOOP;
  13. CLOSE EMPREC;
  14. DBMS_OUTPUT.PUT_LINE(NUM ||'   RECORDS UPDATED');
  15. END;
Jul 14 '07 #6
debasisdas
8,127 Expert 4TB
Ans #4
==========
Expand|Select|Wrap|Line Numbers
  1. Create or Replace Function Emp_Fn(eno IN Emp.Empno%TYPE,sal OUT Emp.Sal%TYPE)
  2. Return Number
  3. As
  4. Begin
  5. Select Emp.Sal-(Club.Fee+Emp.Sal/30 * Leave.NoOfLeave) into Sal
  6. From Emp,Club,Leave Where emp.empno=club.empno and emp.empno=leave.empno and EmpId=eno;
  7. return sal;
  8. End;

from your code it clear that you have no idea of PL/SQL programming
please go through the basics first.
Jul 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Catherine Jones | last post by:
Hi all we are getting active x component can not create object (Error No. 16) while creating an instance of File System Object in ASP client side script. Could you plz help us in solving this...
6
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated...
0
by: IT Recruiter | last post by:
*Very Urgent Rek - SQL Server DBA from Direct Client: Full time* @ New Jersey ***Please send your resumes IMMEDIATELY to nslakshmi@eprocorp.com*** Job Title: SQL Server Developer with...
0
by: swaroopa | last post by:
Hello Partner Please forward some good resumes with excellent communication skills. 1.REMEDY AR CONSULTANT Exp: 6-10YEAR Location: San Jose CA Duration : 2 Months
0
by: bprasanth_20 | last post by:
Hi, I need an urgent help. I need to create a UDF (User Defined Function) in DB2 SQL which can accept any number of arguments (from 2 to 5 arguments). I do not how to achieve this. When I pass 2...
33
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
7
by: funfair | last post by:
hi,every one im facing a problem in running access it's about 25 tables 80 forms 46 query (5 append query ,1 update query ,2 delete query ) 60 reports 4 modules after 7 months of perfect...
0
by: Balamurugan Ranganathan | last post by:
I want to calculate the execution time of a sql query through C#.net this is to analysis two queries to compare their execution time it is very Urgent Please help me Please help Me ...
5
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.