HELP! Coding problems! 
Author Message
 HELP! Coding problems!

I am having a tough time trying to solve these two programming problems:

1.)  I need to write a PL/SQL program that prompts the user for the percent
discount that should be applied to the cost of all 'JAVA' courses.  Update
the COURSE table decreasing the course cost for the 'JAVA' courses by the
percent discount.  Us an explicit cursor to retrieve all of the updated
courses and produce output containing the course id, title, credits, and
cost.  Use a cursor FOR loop to shortcut the process of displaying the
course information.  Display the course cost as currency.  Don't hardcode
literals within the executable section.  Create variables and assign initial
values in the declarative section.

2.) Write a PL/SQL program to display enrollment for each course section
that a specified student is in.  Accept a student id from the user.
Retrieve all the course sections that the student is enrolled in from the
ENROLLMENT table and store them in a PL/SQL table.  Using another loop,
retrieve a count of all students who are enrolled in each of the sections
that are loaded into the table.  Produce output like:

Please enter the student id: 123

Course section 95 has an enrollment of 1.
Course section 125 has an enrollment of 1.

Explicitly OPEN, FETCH data from, and CLOSE each cursor.  Do not use FOR
loops to shortcut the process.

I really, REALLY, appreciate any suggestions and help that can be offered.



Sun, 23 May 2004 12:27:07 GMT
 HELP! Coding problems!

What is the problem?

here is a suggestion :-)

Open cursor...
  exit when not found.
  loop thru cursor
  fetch records into variables
close cursor


Quote:
> I am having a tough time trying to solve these two programming problems:

> 1.)  I need to write a PL/SQL program that prompts the user for the
percent
> discount that should be applied to the cost of all 'JAVA' courses.  Update
> the COURSE table decreasing the course cost for the 'JAVA' courses by the
> percent discount.  Us an explicit cursor to retrieve all of the updated
> courses and produce output containing the course id, title, credits, and
> cost.  Use a cursor FOR loop to shortcut the process of displaying the
> course information.  Display the course cost as currency.  Don't hardcode
> literals within the executable section.  Create variables and assign
initial
> values in the declarative section.

> 2.) Write a PL/SQL program to display enrollment for each course section
> that a specified student is in.  Accept a student id from the user.
> Retrieve all the course sections that the student is enrolled in from the
> ENROLLMENT table and store them in a PL/SQL table.  Using another loop,
> retrieve a count of all students who are enrolled in each of the sections
> that are loaded into the table.  Produce output like:

> Please enter the student id: 123

> Course section 95 has an enrollment of 1.
> Course section 125 has an enrollment of 1.

> Explicitly OPEN, FETCH data from, and CLOSE each cursor.  Do not use FOR
> loops to shortcut the process.

> I really, REALLY, appreciate any suggestions and help that can be offered.



Sun, 23 May 2004 13:44:57 GMT
 HELP! Coding problems!
Forgot to do your homework, huh ?
And no sample data ? How'd you expect people
to know about your COURSE table etc ?

Save the code below into Notepad
and run in sql*plus. It should take care of Part 1 of your question
I'll let you do the 2nd part

Since you gave no sample data
You'll have got some editing to do to suit your need:
I used a table of mine MY_EMP

Robert Chin
------------
accept test_entry number prompt 'Enter pay-cut %: '

declare
cursor happy_emp(target varchar2) is
    select * from my_emp where UPPER(job) like target;
amount number := &test_entry;
discount_target my_emp.job%TYPE := '%BUSBOY%';

begin
  begin
    if (to_number(amount) > 0) then
       null;
    end if;
  exception
    when value_error then
 dbms_output.put_line('Input error !');
  end;
  dbms_output.put_line('Now giving '||lower(REPLACE(discount_target,'%'))||'
a well-deserved pay-cut !'||Chr(10));
  update my_emp set sal = sal * (1 - amount/100)
       where UPPER(job) like discount_target;
  commit;
  dbms_output.put_line('Merry Christmas, guys/gals !........'||chr(10));
  for rec in happy_emp(discount_target)
  loop
  dbms_output.put_line(rec.empno||' '||rec.ename||' '||rec.job||'
'||to_char(rec.sal,'$9,999,999.99'));
  end loop;

end;
/

--
Robert Chin

"Dude"

Quote:
> I am having a tough time trying to solve these two programming problems:

> 1.)  I need to write a PL/SQL program that prompts the user for the
percent
> discount that should be applied to the cost of all 'JAVA' courses.  Update
> the COURSE table decreasing the course cost for the 'JAVA' courses by the
> percent discount.  Us an explicit cursor to retrieve all of the updated
> courses and produce output containing the course id, title, credits, and
> cost.  Use a cursor FOR loop to shortcut the process of displaying the
> course information.  Display the course cost as currency.  Don't hardcode
> literals within the executable section.  Create variables and assign
initial
> values in the declarative section.

> 2.) Write a PL/SQL program to ....

--
Robert Chin
203-846-4198

Quote:
> I am having a tough time trying to solve these two programming problems:

> 1.)  I need to write a PL/SQL program that prompts the user for the
percent
> discount that should be applied to the cost of all 'JAVA' courses.  Update
> the COURSE table decreasing the course cost for the 'JAVA' courses by the
> percent discount.  Us an explicit cursor to retrieve all of the updated
> courses and produce output containing the course id, title, credits, and
> cost.  Use a cursor FOR loop to shortcut the process of displaying the
> course information.  Display the course cost as currency.  Don't hardcode
> literals within the executable section.  Create variables and assign
initial
> values in the declarative section.

> 2.) Write a PL/SQL program to display enrollment for each course section
> that a specified student is in.  Accept a student id from the user.
> Retrieve all the course sections that the student is enrolled in from the
> ENROLLMENT table and store them in a PL/SQL table.  Using another loop,
> retrieve a count of all students who are enrolled in each of the sections
> that are loaded into the table.  Produce output like:

> Please enter the student id: 123

> Course section 95 has an enrollment of 1.
> Course section 125 has an enrollment of 1.

> Explicitly OPEN, FETCH data from, and CLOSE each cursor.  Do not use FOR
> loops to shortcut the process.

> I really, REALLY, appreciate any suggestions and help that can be offered.



Mon, 24 May 2004 00:18:37 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Problem with linking C++ Code with SQL Code for Oracle DB's

2. SQL code -246, ISAM code -154 problem.

3. FW: SQL code -246, ISAM code -154 problem.

4. HELP Error code 2244 & Error code 2465

5. Zip code, Area code, DB- Help

6. Help with code problem.

7. Code page problem ! HELP

8. VB coding problem - Help

9. HELP with coding problems

10. VB Code problem- Help

11. VB Code problem - Help

12. Help on keyboard scan-code problem


 
Powered by phpBB® Forum Software