1 DECLARE
2 TYPE NumTab IS TABLE OF NUMBER(4) INDEX BY BINARY_INTEGER;
3 TYPE NameTab IS TABLE OF CHAR(15) INDEX BY BINARY_INTEGER;
4 pnums NumTab;
5 pnames NameTab;
6 t1 NUMBER(5);
7 t2 NUMBER(5);
8 t3 NUMBER(5);
9
10
11 BEGIN
12 FOR j IN 1..5000 LOOP -- load index-by tables
13 pnums(j) := j;
14 pnames(j) := 'Part No. ' || TO_CHAR(j);
15 END LOOP;
16 t1 := dbms_utility.get_time;
17 FOR i IN 1..5000 LOOP -- use FOR loop
18 INSERT INTO parts VALUES (pnums(i), pnames(i));
19 END LOOP;
20 t2 := dbms_utility.get_time;
21 FORALL i IN 1..5000 -- use FORALL statement
22 INSERT INTO parts VALUES (pnums(i), pnames(i));
23 get_time(t3);
24 dbms_output.put_line('Execution Time (secs)');
25 dbms_output.put_line('---------------------');
26 dbms_output.put_line('FOR loop: ' || TO_CHAR(t2 - t1));
27 dbms_output.put_line('FORALL: ' || TO_CHAR(t3 - t2));
28* END;
DECLARE
TYPE NumList IS TABLE OF NUMBER;
depts NumList := NumList(10, 20, 30);
BEGIN
FORALL j IN depts.FIRST..depts.LAST
UPDATE emp2 SET job = job || ' (temp)'
WHERE deptno = depts(j);
-- raises a "value too large" exception
EXCEPTION
WHEN OTHERS THEN
COMMIT;
END;
DECLARE
TYPE assoc_array IS TABLE OF VARCHAR2(30)
INDEX BY VARCHAR2(30);
state_array assoc_array;
BEGIN
state_array('Alaska') := 'Juneau';
state_array('California') := 'Sacramento';
state_array('Oregon') := 'Salem';
state_array('Washington') := 'Olympia';
dbms_output.put_line(state_array('Alaska'));
dbms_output.put_line(state_array('California'));
dbms_output.put_line(state_array('Oregon'));
dbms_output.put_line(state_array('Alaska'));
END;
分享到:
相关推荐
The characterized lookup table can be utilized in open-loop torque control algorithms, and is verified to achieve high torque control accuracy and suitable for torque control of IPM in automotive ...
type 集合类型名 is table of 元素类型 index by 下标类型; 变量名集合类型名 begin 集合类型名(唯一下标):=元素; end; --嵌套表集合 declare type 嵌套类型名 is table of 元素类型名; --无参初始化 ...
TYPE emp_table IS TABLE OF employee%ROWTYPE INDEX BY BINARY_INTEGER; emps emp_table; emps_max BINARY_INTEGER; BEGIN OPEN all_emps; FETCH all_emps BULK COLLECT INTO emps; CLOSE all_emps; -- ...
-- 私有类型 TYPE employee_table IS TABLE OF employee_record; END my_package;` **3.6.7 重载包级子程序** - 包级子程序可以被重载,即多个具有相同名称但参数列表不同的子程序。 - 示例:`PACKAGE my_package ...
- **定义类型**: `type v_table is table of varchar2(30) index by binary_integer;` 定义了一个名为 `v_table` 的类型,它是一个通过BINARY_INTEGER索引的VARCHAR2(30)类型的表。 - **初始化数组**: `my_table v_...
TYPE nt_table IS TABLE OF NUMBER; P nt_table := NT_TABLE(1, 2, 3); BEGIN ... END; ``` **注意事项** - 嵌套表可以存储在数据库中。 - 嵌套表不保证元素的顺序。 - 当嵌套表为NULL时,整个集合无法引用。 ...
TYPE emp_record_type IS RECORD (ename emp.ename%TYPE, sal emp.sal%TYPE); emp_record emp_record_type; BEGIN SELECT ename, sal INTO emp_record FROM emp WHERE empno = &no; END; ``` #### 1.3 嵌入...
declare type v_table is table of varchar2(30) index by binary_integer; my_table v_table; 在上面的代码中,我们首先声明了一个可变数组类型 `v_table`,它可以存储任意数量的字符串元素。然后,我们创建了一个...
CREATE OR REPLACE TYPE ty_str_split IS TABLE OF VARCHAR2(4000); ``` 接下来,我们将创建一个名为`fn_split`的函数,它接受两个参数:`p_str`表示需要被分割的字符串,`p_delimiter`表示用于分割字符串的分隔符...
type my_text_table_type is table of varchar2(200) index by binary_integer; ``` 2. **声明这种类型的变量**:一旦定义了类型,就可以声明一个变量来使用这个类型。 ```sql l_text_table my_text_table_...
TYPE sal_list IS TABLE OF emp.sal%TYPE; sals sal_list; BEGIN -- 限制结果集大小为100行 SELECT sal BULK COLLECT INTO sals FROM emp WHERE rownum ; -- 获取表中大约10%的行 SELECT sal BULK COLLECT ...
TYPE numtab IS TABLE OF varchar2(50) INDEX BY BINARY_INTEGER; arr numtab; i integer:=1; BEGIN for i in 1..15 loop arr(i):=i; dbms_output.put_line('arr['||i||']='||arr(i)); end loop; dbms_...
声明PL/SQL表需要定义类型,例如`TYPE typename IS TABLE OF col_def INDEX BY BINARY_INTEGER;`,然后声明该类型的实例,如`Tablename typename;`。 引用PL/SQL表时,通过主键值来访问其行,例如`tablename(key_...
TYPE table_type2 IS TABLE OF tempuser.testtable.recordnumber%TYPE INDEX BY BINARY_INTEGER; -- 定义名为table_type2的一维表类型 table1 table_type1; -- 定义table_type1类型的变量table1 table2 table_...
1. 定义一个记录类型,然后在关联数组声明中使用`is table of RecordType`。 2. 使用表的行类型,声明为`is table of TableName%rowtype`。 3. 使用游标返回的行类型,声明为`is table of CursorName%rowtype`。 **...
TYPE my_text_table_type IS TABLE OF VARCHAR2(200) INDEX BY BINARY_INTEGER; l_text_table my_text_table_type; l_index NUMBER; BEGIN FOR emp_rec IN (SELECT * FROM emp) LOOP l_text_table(emp_rec....
TYPE nt_ic01 IS TABLE OF ic01%ROWTYPE; l_nt_ic01 nt_ic01 := nt_ic01(); n_startTime NUMBER; BEGIN n_startTime := DBMS_UTILITY.GET_TIME; FOR rec_ic01 IN (SELECT * FROM ic01 WHERE ROWNUM ) LOOP l_...
TYPE topsalary_table_type IS TABLE OF employees.salary%TYPE; topsalary_table topsalary_table_type; v_salary employees.salary%TYPE; BEGIN -- 获取最高薪水的员工 SELECT SALARY BULK COLLECT INTO ...