Data abstraction, PL-SQL Programming

Data Abstraction

The Data abstraction extracts the important properties of data while ignoring the not necessary details. Once you design a data structure, you can fail to remember the details and focus on designing algorithms that manipulate the data structure.

Collections

The collection types TABLE and VARRAY permit you to declare nested tables and variable-size arrays (varrays in short). A collection is an ordered group of elements, all of the similar type. Every element has a unique subscript that determines its place in the collection.

To reference an element, use the standard subscripting syntax. For e.g., the following call references the 5th element in the nested table returned by the function new_hires:

DECLARE

TYPE Staff IS TABLE OF Employee;

staffer Employee;

FUNCTION new_hires (hiredate DATE) RETURN Staff IS

BEGIN ... END;

BEGIN

staffer := new_hires('10-NOV-98')(5);

...

END;

The Collections work like an array found in most third-generation programming languages. The collections can also be passed as parameters. And hence, you can use them to move columns of data into and out of database tables or between the client-side applications and stored subprograms.

Records

You can use the %ROWTYPE attribute to declare a record that shows a row in a table or a row fetched from a cursor. Although, with a user-defined record, you can declare fields of your own. The Records contain exclusively named fields that can have different datatypes. Assume that you have different data about an employee like name, salary, & hire date. These items are not similar in type but logically related. Records containing a field for each item treat the data as a logical unit. Consider the example shown below:

DECLARE

TYPE TimeRec IS RECORD (hours SMALLINT, minutes SMALLINT);

TYPE MeetingTyp IS RECORD

(

date_held DATE,

duration TimeRec, -- nested record

location VARCHAR2(20),

purpose VARCHAR2(50));

Remember that you can nest the records. That is, the record can be the component of another record.

Posted Date: 10/2/2012 1:49:29 AM | Location : United States







Related Discussions:- Data abstraction, Assignment Help, Ask Question on Data abstraction, Get Answer, Expert's Help, Data abstraction Discussions

Write discussion on Data abstraction
Your posts are moderated
Related Questions
Task 2 [12 marks] Write the package body for the following package specification (the detailed description of each function and procedure is provided in the appendix below). Place

Ensuring Backward Compatibility   The PL/SQL Version 2 permits some abnormal behavior which Version 8 disallows. Particularly, Version 2 permits you to (i) Make the forw

Use Native Dynamic SQL A few programs (a normal-purpose report writer for illustration) should build and process a variety of SQL statements at run time. Therefore, their full

Fetching Across Commits The FOR UPDATE clauses acquire exclusive all row locks. All rows are locked when you open the cursor, and when you commit your transaction they are unl

SQL Pseudocolumns The PL/SQL recognizes the following SQL pseudocolumns, that returns the specific data items: LEVEL, NEXTVAL, CURRVAL, ROWID, & ROWNUM. The Pseudocolumns are n

Third Step at defining type SID in SQL CREATE DOMAIN SID AS VARCHAR(5) CHECK ( VALUE IS NOT NULL AND SUBSTRING(VALUE FROM 1 FOR 1) = 'S' AND CAST('+'||SUBSTRING(VALUE

Using Pragma RESTRICT_REFERENCES: The function called from the SQL statements should obey certain rules meant to control the side effects. To check for violation of the rules,

Committing and Rolling Back The COMMIT and ROLLBACK end the active autonomous transaction but do not exit the autonomous routine. As the figure shows, if one transaction ends,

Autonomous versus Nested Transactions Though an autonomous transaction is started by the other transaction, it is not a nested transaction for the reasons shown below: (i)

Parameter and Keyword Description: select_item: This select_item is a value returned by the SELECT statement, and then assigned to the equivalent variable or field in the