GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 208 of 241    Print  
PL/SQL tables
How will implement the PL/SQL tables?


  
Total Answers and Comments: 3 Last Update: May 29, 2008     Asked by: jagadeesh9 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 26, 2008 00:30:29   #1  
Smitha25 Member Since: March 2008   Contribution: 2    

RE: PL/SQL tables
PL/SQl tables were introduced in Oracle 7.PL/SQL tables are similar to arrays in C.By using PL/SQL Tables it is possible to create a collection of items all of the same type indexed by an integer.
eg:TYPE name IS TABLE OF varchar2 INDEX BY BINARY_INTEGER;

 
Is this answer useful? Yes | No
March 27, 2008 18:40:23   #2  
tonyrobert Member Since: February 2007   Contribution: 3    

RE: PL/SQL tables
INDEX By Tables composed of two components
1. Primary key of data type BINARY_INTEGER
2. Column of scalar or record data type.

Since this table is unconstrained it can increase its size dynamically.

Syntax:
TYPE type_name IS TABLE OF
{column_type | variable type
| table.column type } [NOT NULL]
| table. ROWTYPE
[INDEX BY BINARY_INTEGER];
identifier type_name;

for eg:
To declare an INDEX BY TABLE to store names.

TYPE enam_table_type IS TABLE OF employees.name TYPE INDEX BY BINARY_INTEGER;
ename_table ename_table_type;

To Refer the INDEX BY TABLE:
INDEX_BY_TABLE_NAME(primary_key_value)
where primary_key_value belongs to type BINARY_INTEGER

For eg: We have already have the ename_table which is of type ename_table_type. To refer the 5th row in this table we can use ename_table(5).

The methods associated with this index by table are:
EXISTS COUNT FIRST and LAST PRIOR NEXT TRIM DELETE


 
Is this answer useful? Yes | No
May 29, 2008 00:52:26   #3  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: PL/SQL tables
- Pl/sql is in memory representation of a table.
- It is just a data type. ( Collection type)
- It may store any number of rows from table.

Here is a simple example

CREATE OR REPLACE PROCEDURE TEST_PROC AS
TYPE EMP_TYPE IS TABLE OF EMP ROWTYPE;
EMP_VAR EMP_TYPE;
BEGIN
SELECT * BULK COLLECT INTO EMP_VAR FROM EMP;
FOR I IN EMP_VAR.FIRST..EMP_VAR.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(' EMPLOYEE ' ||EMP_VAR(I).ENAME || ' SALARY IS '|| EMP_VAR(I).SAL);
END LOOP;
END;

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape