Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sasha1987
Starting Member
2 Posts |
Posted - 2010-04-10 : 18:52:34
|
hey everyone,this is the question i am trying to write so i just want to make sure i am goin into the right direction as i am bit confused.Write a procedure that uses a collection to find and display how many employees have the same name and what is the most common name.this is the table i am working fromCREATE TABLE EMPX (EMPNO NUMBER(4) NOT NULL, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2), constraint emp_pk primary key(empno));here is my code so farcreate or replaceprocedure common_namesis-- define a varray type to store upto 25 rows from the empx tableTYPE empArray IS VARRAY(25) OF empx%rowtype; -- declare an empty instance of the varray typeempList empArray := empArray();-- define a cursor to hold multiple (all) rows from the emp tablecursor empCur is select * from empx;vCount number(2):=1;--declare and initialise counter for varraybeginempList.extend(25); -- extend the varray to hold 25 elements-- declare a cursor for loop to retrieve all the rows from the cursorfor empRec in empcur loop -- empRec is a record based on the cursor typeempList(vCount) := empRec; -- put an empRec into the varray at the index specifieddbms_output.put_line(empList(vCount).ename); -- print out the employees namevCount := vcount +1; -- increment vcountend loop;end; |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sasha1987
Starting Member
2 Posts |
Posted - 2010-04-10 : 19:17:41
|
| I am using sql developer to write this. Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|