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

Package STANDARD package named STANDARD defines the PL/SQL atmosphere. The package specification globally declares the exceptions, types, and subprograms that are available a

Effects of NULL for union - SQL The treatment of NULL in invocations of EXCEPT is as for UNION. This is different from its treatment in those of NOT IN and quantified compari

Primary Key - SQL A PRIMARY KEY specification carries an implicit NOT NULL constraint on each column of the specified key. When more than one key constraint is required, the k

Opening a Cursor Opening the cursor executes the query & identifies the result set that consists of all rows that meet the query search criteria. For the cursors declared usin

Avoid the NOT NULL Constraint In the PL/SQL, using the NOT NULL constraint incur a performance cost. Consider the illustration as shown below: PROCEDURE calc_m IS m NUMB

SQL Database: So, an SQL database is one whose symbols are organized into a collection of tables. Now, shows an SQL table as the current value of an SQL variable, ENROLMENT, b

Remote Operations: As the illustration shows below, the PL/SQL subprograms can execute the dynamic SQL statements which refer to the objects on a remote database: PROCEDURE

ROWID and UROWID Internally, every database table has a ROWID pseudo column that stores binary values known as rowids. Each rowid shows the storage address of a row. A physical

Positional and Named Notation You can write the actual parameters when calling a subprogram, using either positional or named notation. That is, you can point to the relationsh