RDBMS SOLUTION


ASSIGNMENT 5 

SET A Q.3 SOLUTION

Write a cursor which will display status wise project details of each department.




Source code:

    

    /*set a q 3 solution

    explaination of the code at the end*/

    

Declare

pname pproject.pname%type;

pbudget pproject.budget%type;

cursor pdet is

select pname,budget from pproject p,department d,p_d pd

where d.dname='computer science' and p.budget>10000 and pd.project_number=p.pno and pd.department_number=d.dno;

Begin

open pdet;

loop

exit when pdet%notfound;

fetch pdet into pname,pbudget;

dbms_output.put_line(pname||' '||pbudget);

end loop;

close pdet;

end;

/* 

Explaination:

This is a PL/SQL code that selects project names and budgets for projects that belong to the "computer science" department and have a budget greater than 10,000. It then prints the project name and budget using the dbms_output.put_line() function.

Here is a breakdown of the code:

The code starts with a declaration section where two variables are declared: pname and pbudget. These variables are used to store the project name and budget, respectively.

Next, a cursor named pdet is declared. The cursor is defined to select project names and budgets for projects that belong to the "computer science" department and have a budget greater than 10,000. The cursor joins the pproject, department, and p_d tables on their respective keys to retrieve the required data.

The code then enters the begin block where the cursor is opened using the open statement. Then, a loop is started to fetch all the rows returned by the cursor. The loop continues until there are no more rows to fetch, which is detected by the exit when statement.

Inside the loop, the fetch statement is used to retrieve the project name and budget into the pname and pbudget variables, respectively. The dbms_output.put_line() function is then used to print the project name and budget.

Finally, the cursor is closed using the close statement to release the resources used by the cursor. */

   

    
 Download code         next