{"id":1382,"date":"2010-07-14T14:52:52","date_gmt":"2010-07-14T19:52:52","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=1382"},"modified":"2010-07-14T14:52:52","modified_gmt":"2010-07-14T19:52:52","slug":"oracle-collections","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=1382","title":{"rendered":"Oracle Collections"},"content":{"rendered":"<span id=\"Nested_Tables\"><h2>Nested Tables<\/h2><\/span>\n<p>* Contains <\/p>\n<span id=\"Associated_Arrays\"><h2>Associated Arrays<\/h2><\/span>\n<p>* Aka Index-by tables.<br \/>\n* Contain sets of key-value pairs similar to hash tables.<br \/>\n* Keys are unique and can be numbers or strings.<br \/>\n* The key_type can be numeric, either BINARY_INTEGER or PLS_INTEGER. It can also be VARCHAR2 or one of its subtypes VARCHAR, STRING, or LONG. You must specify the length of a VARCHAR2-based key, except for LONG which is equivalent to declaring a key type of VARCHAR2(32760). The types RAW, LONG RAW, ROWID, CHAR, and CHARACTER are not allowed as keys for an associative array.<\/p>\n<p>An initialization clause is not required (or allowed).<\/p>\n<p>When you reference an element of an associative array that uses a VARCHAR2-based key, you can use other types, such as DATE or TIMESTAMP, as long as they can be converted to VARCHAR2 with the TO_CHAR function.<\/p>\n<span id=\"Definition\"><h3>Definition<\/h3><\/span>\n<pre>\r\nTYPE type_name IS TABLE OF element_type [NOT NULL]\r\n   INDEX BY [BINARY_INTEGER | PLS_INTEGER | VARCHAR2(size_limit)];\r\n   INDEX BY key_type;\r\n<\/pre>\n<span id=\"Examples\"><h3>Examples<\/h3><\/span>\n<pre lang=\"sql\">\r\nSET serveroutput ON;\r\nDECLARE\r\n  -- Declare an associative number array type indexed by string\r\ntype price_type\r\nIS\r\n  TABLE OF NUMBER INDEX BY VARCHAR2(64);\r\n  -- Declare an associative array of the declared type\r\n  fruit_price price_type;\r\n  -- Some other simple variables\r\n  lemon_price   NUMBER;\r\n  bannana_price NUMBER;\r\n  fruit         VARCHAR2(64);\r\nBEGIN\r\n  -- Assign elements\r\n  fruit_price('lemon')   := 1.10;\r\n  fruit_price('bannana') := 2.20;\r\n  fruit_price('orange')  := 3.30;\r\n  bannana_price          := fruit_price('bannana');\r\n  lemon_price            := fruit_price('lemon');\r\n  dbms_output.put_line('Bannana price: ' || bannana_price);\r\n  dbms_output.put_line('Lemon price: ' || lemon_price);\r\n  \r\n  -- FIRST and LAST function\r\n  dbms_output.put_line('First fruit: ' || fruit_price.FIRST);\r\n  dbms_output.put_line('Last fruit: ' || fruit_price.LAST);\r\n  \r\n  -- Looping\r\n  fruit       := fruit_price.FIRST;\r\n  WHILE fruit IS NOT NULL\r\n  LOOP\r\n    dbms_output.put_line(fruit || ' costs ' || fruit_price(fruit) || ' dollars.');\r\n    fruit := fruit_price.NEXT(fruit);\r\n  END LOOP;\r\nEND;\r\n\r\nanonymous block completed\r\nBannana price: 2.2\r\nLemon price: 1.1\r\nFirst fruit: bannana\r\nLast fruit: orange\r\nbannana costs 2.2 dollars.\r\nlemon costs 1.1 dollars.\r\norange costs 3.3 dollars.\r\n<\/pre>\n<span id=\"VArrays\"><h2>VArrays<\/h2><\/span>\n","protected":false},"excerpt":{"rendered":"<p>Nested Tables * Contains Associated Arrays * Aka Index-by tables. * Contain sets of key-value pairs similar to hash tables. * Keys are unique and can be numbers or strings. * The key_type can be numeric, either BINARY_INTEGER or PLS_INTEGER. &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=1382\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[35],"tags":[],"class_list":["post-1382","post","type-post","status-publish","format-standard","hentry","category-oracle"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-mi","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1382"}],"version-history":[{"count":1,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1382\/revisions"}],"predecessor-version":[{"id":1659,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1382\/revisions\/1659"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}