Using trim - collection method, PL-SQL Programming

Using TRIM

This process has two forms. The TRIM removes an element from the end of the collection. The TRIM(n) removes the n elements from the end of the collection. For e.g. this statement removes all the last three elements from the nested table courses:

courses.TRIM(3);

If n is bigger than COUNT, then TRIM(n) raises SUBSCRIPT_BEYOND_COUNT.

TRIM operates on the internal size of the collection. Therefore, if TRIM encounters deleted elements, then it includes them in its tally. Consider the example shown below:

DECLARE

TYPE CourseList IS TABLE OF VARCHAR2(10);

courses CourseList;

BEGIN

courses := CourseList('Biol 4412', 'Psyc 3112', 'Anth 3001');

courses.DELETE(courses.LAST); -- delete element 3

/* At this point, COUNT equals 2, the number of valid

elements remaining. So, you might expect the next

statement to blank the nested table by trimming

elements 1 and 2. Instead, it trims valid element 2

and the deleted element 3 as TRIM includes deleted

elements in its tally. */

courses.TRIM(courses.COUNT);

DBMS_OUTPUT.PUT_LINE(courses(1)); -- prints 'Biol 4412'

In normal, do not depend on the interaction between the TRIM and DELETE. It is better to treat nested tables such as fixed-size arrays and use only DELETE, or to treat them like the stacks and use only TRIM and EXTEND.

The PL/SQL does not keep placeholders for the trimmed elements. As a result, you cannot replace a trimmed element just by assigning it a new value.

Posted Date: 10/4/2012 3:18:44 AM | Location : United States







Related Discussions:- Using trim - collection method, Assignment Help, Ask Question on Using trim - collection method, Get Answer, Expert's Help, Using trim - collection method Discussions

Write discussion on Using trim - collection method
Your posts are moderated
Related Questions
THEO R Y OF ETERNITY OF LIFE (PRAYER - 1880) - The theory of eternity of life, also called the steady-state theory , states that life has ever been in existence as at presen

Literals A literal is an explicit numeric, string, character, or Boolean value not represented by an identifier. Numeric literal 147 and the Boolean literal FALSE are some of

Quantification in SQL To quantify something, as the theory book has it, is to state its quantity, to say how many of it there are. For example, in Tutorial D the expression CO

Using NOT NULL Besides assigning an initial value, the declarations can impose the NOT NULL constraint, as the example below shows: acct_id INTEGER(4) NOT NULL := 9999; You ca

DBMS: The answer to this question is of course given in of the theory book. This book is concerned with SQL DBMSs and SQL databases in particular. Soon we will be looking a

Referencing Records Unlike the elements in a collection, that are accessed using subscripts, the fields in a record are accessed by name. To reference an individual field, you

%ISOPEN The Oracle closes the SQL cursor automatically after executing its related SQL statement. As a result, the %ISOPEN forever yields FALSE.

Methods: In normal, a method is a subprogram declared in an object type specification using the keyword MEMBER or STATIC. The method cannot have similar name as the object typ

Scope Rules You cannot declare an exception twice in the similar block. Though, you can, declare the similar exception in 2 different blocks. The Exceptions declared in a bloc

Using Operator VALUE: As you may expect, the operator VALUE returns the value of an object. The VALUE takes its argument a correlation variable.  For illustration, to return a