I have a table Students with the following schema:
CREATE TABLE STUDENTS
(
SID VARCHAR2(10 BYTE) NOT NULL,
SNAME VARCHAR2(50 BYTE) NOT NULL, . . .
)
I want to create a stored procedure that will take a list of students as input argument each item in the list will have sid and sname.
What will be the type of the input parameter and how to define it?
You could pass in an Oracle collection type as a parameter.
The collection could be a key value pair such as an associative array indexed by a varchar.
In that example, the index could be the SID and the value could be the SNAME.
Read here to learn about collections: http://docs.oracle.com/cd/B10501_01/appdev.920/a96624/05_colls.htm
And here for associative arrays in particular: http://www.oracle-base.com/articles/9i/AssociativeArrays9i.php
Alternatively you could pass two parameters, both collections holding varchar values (such as DBMS_SQL.VARCHAR2_TABLE types) the first holding the SID and the second holding the corresponding SNAME values they would effectively be linked by their index number.
See here for DBMS_SQL defined types: http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_sql.htm
Hope it helps…
EDIT:
If you are declaring all types and performing all actions within a package then:
If you want global types then you’ll have to explicitly declare the columns:
You can then use the student collection type with your DB to pass collections of student data into and out of procedures and functions.
The docs for using oracle objects are here: http://docs.oracle.com/cd/B19306_01/appdev.102/b14260/adobjint.htm