الانتقال إلى المحتوى

ماذا يقصد بـ Varray و Nested Tables


الواثق بوعد الله

Recommended Posts

Nested Tables and Varrays [iD 61745.1]

--------------------------------------------------------------------------------

Modified 28-MAY-2009 Type BULLETIN Status PUBLISHED


Checked for relevance on 28-May-2009

Nested Tables and Varrays


Introduction
------------

Oracle8 provides two collection types: nested tables and varying
arrays or VARRAYS. A collection is an ordered group of elements
of the same type. Each element from the group can be accessed
using a unique subscript. The element types of a collection can
be either built-in datatypes, user-defined types or references
(REFs) to object types.


Nested Tables
-------------

An ordered group of items of type TABLE are called nested tables.
Nested tables can contain multiple columns and can be used as
variables, parameters, results, attributes, and columns. They
can be thought of as one column database tables. Rows of a
nested table are not stored in any particular order.

The size of a nested table can increase dynamically, i.e., nested
tables are unbounded. Elements in a nested table initially have
consecutive subscripts, but as elements are deleted, they can have
non-consecutive subscripts.

Nested tables can be fully manipulated using SQL, Pro*C, OCI, and
PL/SQL. The range of values for nested table subscripts is
1..2147483647. To extend a nested table, the built-in procedure
EXTEND must be used. To delete elements, the built-in procedure
DELETE must be used.

An uninitialized nested table is atomically null, so the IS NULL
comparison operator can be used to see if a nested table is null.
Oracle8 provides new operators such as CAST, THE, and MULTISET for
manipulating nested tables.


Examples for Nested Tables
--------------------------

Example 1:
----------

The following example illustrates how a simple nested table is created.

a) First, define a Object type as follows:

SQL> CREATE TYPE ELEMENTS AS OBJECT (
2> ELEM_ID NUMBER(6),
3> PRICE NUMBER(7,2));
4> /

:) Next, create a table type ELEMENTS_TAB which stores ELEMENTS objects:

SQL> CREATE TYPE ELEMENTS_TAB AS TABLE OF ELEMENTS;
2> /

c) Finally, create a database table STORAGE having type ELEMENTS_TAB as
one of its columns:

SQL> CREATE TABLE STORAGE (
2> SALESMAN NUMBER(4),
3) ELEM_ID NUMBER(6),
4) ORDERED DATE,
5) ITEMS ELEMENTS_TAB)
6) NESTED TABLE ITEMS STORE AS ITEMS_TAB;


Example 2:
----------

This example demonstrates how to populate the STORAGE table with a single
row:

SQL> INSERT INTO STORAGE
2> VALUES (100,123456,SYSDATE,
3> ELEMENTS_TAB(ELEMENTS(175692,120.12),
4> ELEMENTS(167295,130.45),
5> ELEMENTS(127569,99.99)));


Example 3:
----------

The following example demonstrates how to use the operator THE which is
used in a SELECT statement to identify a nested table:

SQL> INSERT INTO
2> THE
3> (SELECT ITEMS FROM STORAGE WHERE ELEM_ID = 123456)
4> VALUES (125762, 101.99);


Example 4:
----------

The following example shows how to update the STORAGE table row where
salesman column has value 100:

SQL> UPDATE STORAGE
2> SET ITEMS = ELEMENTS_TAB(ELEMENTS(192512, 199.99))
3> WHERE SALESMAN = 100;


Varrays
-------

Varrays are ordered groups of items of type VARRAY. Varrays can be used
to associate a single identifier with an entire collection. This allows
manipulation of the collection as a whole and easy reference of
individual elements.

The maximum size of a varray needs to be specified in its type definition.
The range of values for the index of a varray is from 1 to the maximum
specified in its type definition. If no elements are in the array, then
the array is atomically null. The main use of a varray is to group
small or uniform-sized collections of objects.

Elements of a varray cannot be accessed individually through SQL, although
they can be accessed in PL/SQL, OCI, or Pro*C using the array style
subscript. The type of the element of a VARRAY can be any PL/SQL type
except the following:

BOOLEAN
TABLE
VARRAY
object types with TABLE or VARRAY attributes
REF CURSOR
NCHAR
NCLOB
NVARCHAR2

Varrays can be used to retrieve an entire collection as a value. Varray
data is stored in-line, in the same tablespace as the other data in its row.

When a varray is declared, a constructor with the same name as the varray is
implicitly defined. The constructor creates a varray from the elements
passed to it. You can use a constructor wherever you can use a function
call, including the SELECT, VALUES, and SET clauses.

A varray can be assigned to another varray, provided the datatypes are the
exact same type. For example, suppose you declared two PL/SQL types:

TYPE My_Varray1 IS VARRAY(10) OF My_Type;
TYPE My_Varray2 IS VARRAY(10) OF My_Type;

An object of type My_Varray1 can be assigned to another object of type
My_Varray1 because they are the exact same type. However, an object of
type My_Varray2 cannot be assigned to an object of type My_Varray1 because
they are not the exact same type, even though they have the same element type.

Varrays can be atomically null, so the IS NULL comparison operator can be
used to see if a varray is null. Varrays cannot be compared for equality
or inequality.


Examples for Varrays
--------------------

Example 5:
---------

The following shows how to create a simple VARRAY:

a) First, define a object type ELEMENTS as follows:

SQL> CREATE TYPE MEDICINES AS OBJECT (
2> MED_ID NUMBER(6),
3> MED_NAME VARCHAR2(14),
4> MANF_DATE DATE);
5> /

:P Next, define a VARRAY type MEDICINE_ARR which stores MEDICINES objects:

SQL> CREATE TYPE MEDICINE_ARR AS VARRAY(40) OF MEDICINES;
2> /


c) Finally, create a relational table MED_STORE which has MEDICINE_ARR as a
column type:

SQL> CREATE TABLE MED_STORE (
2> LOCATION VARCHAR2(15),
3> STORE_SIZE NUMBER(7),
4> EMPLOYEES NUMBER(6),
5> MED_ITEMS MEDICINE_ARR);


Example 6:
----------

The following example shows how to insert two rows into the MED_STORE table:

SQL> INSERT INTO MED_STORE
2> VALUES ('BELMONT',1000,10,
3> MEDICINE_ARR(MEDICINES(11111,'STOPACHE',SYSDATE)));

SQL> INSERT INTO MED_STORE
2> VALUES ('REDWOOD CITY',700,5,
3> MEDICINE_ARR(MEDICINES(12345,'STRESS_BUST',SYSDATE)));


Example 7:
----------

The following example shows how to delete the second row we have inserted in
example 6 above:

SQL> DELETE FROM MED_STORE
2> WHERE LOCATION = 'REDWOOD CITY';


Example 8:
----------

The following example shows how to update the MED_STORE table and add more
medicines to the Belmont store:

SQL> UPDATE MED_STORE
2> SET MED_ITEMS = MEDICINE_ARR (
3> MEDICINES(12346,'BUGKILL',SYSDATE),
4> MEDICINES(12347,'INHALER',SYSDATE),
5> MEDICINES(12348,'PAINKILL',SYSDATE));



Differences Between Nested Tables and Varrays
---------------------------------------------

* Nested tables are unbounded, whereas varrays have a maximum size.

* Individual elements can be deleted from a nested table, but not from
a varray. Therefore, nested tables can be sparse, whereas varrays are
always dense.

* Varrays are stored by Oracle in-line (in the same tablespace), whereas
nested table data is stored out-of-line in a store table, which is a
system-generated database table associated with the nested table.

* When stored in the database, nested tables do not retain their ordering
and subscripts, whereas varrays do.

* Nested tables support indexes while varrays do not.

رابط هذا التعليق
شارك

بارك الله فيكي يا أخت (أم مريم) ولكن لي سؤال
كيف يمكن استخدام هذه القيم سواء داخل الشاشات Forms أو التقارير Reports أو حتى الاستعلامات Query

عشان أنا جربت أعمل Data Block Wizard ولم يقبل مني الNested ولا حتى الVarray

رابط هذا التعليق
شارك

جرب الدمو بالمرفق بس run الscribt الاول
ولمعلومات اكثر شوف اللينك ده:
http://sheikyerbouti.developpez.com/collec...collections.htm

UsingNested_tables.rar

رابط هذا التعليق
شارك

  • بعد 1 شهر...

عزيزتي ام مريم عندي فورم صرف دواء لمستشفى تخصصي ارادوا مني عمل تصفح في رقم المريض حتى 25 رقم مريض اني ما اعرف array حليتها بان عملت 25 text itemاعرف انه هذا مو حل بس كنت مصره اتعلم عمل

type arr is table of number(10);
x arr:=arr();
for i in 1..25 loop
x.extend;
x(x.count)=i;
end loop;

رابط هذا التعليق
شارك

ممكن خطوه خطوه تعلميني الي اسويه مع العلم انه اني قريت الملف المرفق الي حضرتج واضعته كلش مفيد بس اخر موضوع بيه وهو ربط nessted array with developerعن طريق set_block_property لم افتهمه
typeيكون عام بس الvariable راح يكون وين اعرفه ويشوفه كل البرنامج
بس لو ممكن تطولين بالج وتشرحيلي اولى الخطوات واني متاكده بانه راح اكدر اكمل وحدي وما ازعجج واستند على الملف الي رافقته حضرتج

رابط هذا التعليق
شارك

عزيزتي ام مريم كنت انتظر ردك بفارغ الصبر والترقب المشكله الي عندي هي كالاتي فورم صرف الدواء فيها رقم المريض واسمه وعند ادخال رقم مريض جديد وضغط انتر المفروض يخزنه هذا الرقم ولح 25 رقم وهو ماسموه الي تصفح 25 id وفي اي لغه عاديه كان الحل بسيط بان اعمل arrayوتكون globalوكم مره يخزن فيها عند ضغط انتر بس الاوراكل يصعب الامور ويعقدها بان لايوجد arrayموجوده فيه بس موضوعج فتحلي باب الامل من جديد فلا تقطعي عن الامل بالاوراكل

رابط هذا التعليق
شارك

السلام عليكم ورحمة الله

الأخت / أم طيبة

اذا كان المقصود من السؤال هو استخدام فكرة ال array لتخزين مجموعه من الارقام المختارة معا ... ثم تحريكها الى التقرير لاستخراج تقرير معين من خلال فكرة استخدام ال global values

فيمكن الاطلاع على هذه المشاركة السابقة بالمنتدى ... لتحريك مجموعة الارقام المختارة بدون استخدام ال array وبدون استخدام ال global

او للرد على السؤال التالي

لدي form بها بعض بيانات الموظفين تظهر بطريقة ال tabular . اريد أن اختار بعض ارقام الموظفين من هذه الشاشة وارسلها الى report لطباعة بيانات تخص ارقام الموظفين المحددة والمختاره من الform.


إضغط هنا : تحريك بيانات من الform الى الreport

ارجوا ان يكون هذا هو المطلوب
رابط هذا التعليق
شارك

مشكور اخ اشرف
هذا الموضوع الي ذكرته انهي قرأته وفادني كثيرا هذا الموضوع بس الي احتاجه هنا غير هذا الخزن الي اريده مو داتا بيس خزن خلال جلسه عمل ليتم تذكر كل المرضى الذين تم صرف العلاج لهم لهذا اليوم ومشكور امجد واني بانتظار رد ام مريم علي لانها هي طرحت هذا الموضوع وتعرف بيه اكيد

رابط هذا التعليق
شارك

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   تمت استعادة المحتوى السابق الخاص بك.   مسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

جاري التحميل
×
×
  • أضف...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية