Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 13th, 2004, 06:10 AM
gerrards gerrards is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 gerrards User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
procedure question

i am a student at the university of toronto. I have to make a database in oracle for a coursework. I have never used oracle before and am a little unfamilliar with sql. I have to make a procedure in pl/sql to display details of a video supplier from a given address in my video supplier database. I am totally stuck with this.

Reply With Quote
  #2  
Old April 13th, 2004, 09:32 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Here I assume that you have installed Oracle database in your system and know how to invoke the SQL*Plus, now see the following example:

/* This procedure will take department number as input, manipulate data and display the output on SQL prompt */

CRAETE OR REPLACE PROCEDURE get_emp_info (p_deptno IN NUMBER) IS

CURSOR c_emp IS
SELECT empno,ename,job,sal
FROM emp
WHERE deptno=p_deptno;

BEGIN
/* dbms_output.put_line prints the user output on SQL prompt */
dbms_output.put_line('Employees information for department '||LTRIM(p_deptno));
dbms_output.put_line('---------------------------------------');
dbms_output.put_line('Employee Employee Name Job Salary');
dbms_output.put_line(' No.');
dbms_output.put_line(-------- --------------- --------- ------');

/* loop creates an implicit cursor "emp_rec" that has same structure defined in CRAETE CURSOR command */
FOR emp_rec IN c_emp
LOOP
dbms_output.put_line(LPAD(emp_rec.empno,9,' ')||' '||RPAD(emp_rec.ename,15,' ')||' '||RPAD(emprec.job,10,' ')||emp_rec.sal);
END LOOP;

END;
/

When your procedure is created successfully, run it as follows:

SQL>execute get_emp_info(10);

before run your procedure to get output, make sure that your serveroutput is on, to make your serveroutput on, use the following command:

SQL>set serveroutput on size 1000000

Let's see how you done your assignment.

Regards

Reply With Quote
  #3  
Old April 15th, 2004, 06:52 AM
gerrards gerrards is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 2 gerrards User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi there, thanks for helping me out with that procedure. I have changed it to my values but i still get compilation errors.

CREATE OR REPLACE PROCEDURE get_supplier_info (p_supp_code IN NUMBER) IS

CURSOR c_su IS
SELECT supp_code,name,address,tel_num
FROM supplier
WHERE supp_code=p_supp_code;

BEGIN
/* dbms_output.put_line prints the user output on SQL prompt */
dbms_output.put_line('Supplier information for given address '||LTRIM(p_supp_code));
dbms_output.put_line('---------------------------------------');
dbms_output.put_line('Supp_code Name Address Tel_Num');
dbms_output.put_line(' No.');
dbms_output.put_line(-------- --------------- --------- ------');

/* loop creates an implicit cursor "emp_rec" that has same structure defined in CRAETE CURSOR command */
FOR supp_rec IN c_sup
LOOP
dbms_output.put_line(LPAD(sup_rec.supp_code,9,' ')||' '||RPAD(sup_rec.name,15,' ')||' '||RPAD(supp_rec.address,10,' ')||sup_rec.tel_num);
END LOOP;

Reply With Quote
  #4  
Old April 15th, 2004, 08:56 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
here is your error free code:

CREATE OR REPLACE PROCEDURE get_supplier_info (p_supp_code IN NUMBER)
IS
CURSOR c_sup IS
SELECT supp_code,name,address,tel_num
FROM supplier
WHERE supp_code=p_supp_code;

BEGIN
/* dbms_output.put_line prints the user output on SQL prompt */
dbms_output.put_line('Supplier information for given address '||LTRIM(p_supp_code));
dbms_output.put_line('---------------------------------------');
dbms_output.put_line('Supp_code Name Address Tel_Num');
dbms_output.put_line(' No.');
dbms_output.put_line('-------- --------------- --------- ------');
/* loop creates an implicit cursor "emp_rec" that has same structure defined in CRAETE CURSOR command */
FOR sup_rec IN c_sup
LOOP
dbms_output.put_line(LPAD(sup_rec.supp_code,9,' ')||' '||
RPAD(sup_rec.name,15,' ')||' '||
RPAD(sup_rec.address,10,' ')||' '||sup_rec.tel_num);
END LOOP;
END;
/

To remove errors from your code, use 'show errors' command, this command displays the line number that has error and possible solution.

SQL>show errors

Regards,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > procedure question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway