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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with collection?

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 from

CREATE 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 far


create or replace
procedure common_names
is
-- define a varray type to store upto 25 rows from the empx table
TYPE empArray IS VARRAY(25) OF empx%rowtype;
-- declare an empty instance of the varray type
empList empArray := empArray();

-- define a cursor to hold multiple (all) rows from the emp table
cursor empCur is select * from empx;

vCount number(2):=1;
--declare and initialise counter for varray

begin

empList.extend(25); -- extend the varray to hold 25 elements

-- declare a cursor for loop to retrieve all the rows from the cursor
for empRec in empcur loop -- empRec is a record based on the cursor type

empList(vCount) := empRec; -- put an empRec into the varray at the index specified
dbms_output.put_line(empList(vCount).ename); -- print out the employees name
vCount := vcount +1; -- increment vcount
end loop;

end;

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-10 : 19:15:21
This is a Microsoft SQL Server site, and it appears you are using a different dbms. I can't tell what dbms it is, but you should post your question on a forum site that specifically deals with the technology you are using. Try dbforums.com which has many different dbms forums.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sasha1987
Starting Member

2 Posts

Posted - 2010-04-10 : 19:17:41
I am using sql developer to write this. Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-10 : 19:19:52
Is SQL Developer an Oracle product? If so, you should try an Oracle forum site.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -