create_assocarray5.sql

来自「介绍Oracle PL SQL编程」· SQL 代码 · 共 75 行

SQL
75
字号
/* * create_assocarray5.sql * Chapter 6, Oracle10g PL/SQL Programming * by Ron Hardman, Michael McLaughlin and Scott Urman * * This script demonstrates initialization and assignment with a numeric * index value to an associative array. */SET ECHO ONSET SERVEROUTPUT ON SIZE 1000000DECLARE  -- Define a varray of twelve strings.  TYPE months_varray IS VARRAY(12) OF STRING(9 CHAR);     -- Define an associative array of strings.  TYPE calendar_table IS TABLE OF VARCHAR2(9 CHAR)    INDEX BY BINARY_INTEGER;  -- Declare and construct a varray.  month MONTHS_VARRAY :=     months_varray('January','February','March'                 ,'April','May','June'                 ,'July','August','September'                 ,'October','November','December');  -- Declare an associative array variable.  calendar CALENDAR_TABLE;BEGIN  -- Check if calendar has no elements.  IF calendar.COUNT = 0 THEN    -- Print a title    DBMS_OUTPUT.PUT_LINE('Assignment loop:');    DBMS_OUTPUT.PUT_LINE('----------------');    -- Loop through all the varray elements.    FOR i IN month.FIRST..month.LAST LOOP      -- Initialize a null associative array element.      calendar(i) := '';      -- Print an indexed element from the associative array.      DBMS_OUTPUT.PUT_LINE(        'Index ['||i||'] is ['||calendar(i)||']');      -- Assign the numeric index valued varray element      -- to an equal index valued associative array element.      calendar(i) := month(i);     END LOOP;    -- Print a title    DBMS_OUTPUT.PUT(CHR(10));    DBMS_OUTPUT.PUT_LINE('Post-assignment loop:');    DBMS_OUTPUT.PUT_LINE('---------------------');    -- Loop through all the associative array elements.    FOR i IN calendar.FIRST..calendar.LAST LOOP      -- Print an indexed element from the associative array.      DBMS_OUTPUT.PUT_LINE(        'Index ['||i||'] is ['||calendar(i)||']');    END LOOP;  END IF;END;/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?