⑴ oracle 存储过程 数组循环
declare
type typ_rec is record of (student.name%type, student.age%type); --集合变量
type typ_tab is table of typ_rec index by binary_integer; --以集合变量为单位的table数组
rec_sql typ_rec;
another_rec student%rowtype; --跟rec_sql一样
begin
--for循环里的rec_tmp不用定义,可以自动生成的
for rec_tmp in (select t.name, t.age from student t) loop
dbms_output.putline(rec_tmp.name || ' ''s age + 1 = ' || to_char(rec_tmp.age + 1) );
end loop;
exception
when others then
return;
end;
⑵ oracle存储过程中循环for in是如何使用的
1、首先编写存储过程的整体结构,如下图所示定义变量。
⑶ 如何在oracle建一个存储过程来遍历数组,新手求解
SQL code
DECLARE
-- 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;
⑷ oracle存储过程中循环查询返回多个结果集怎么集合在一起
你可以先把数据集保存到array里面,完了之后再用一次性的导出来。
又或者你可以检查你的循环查询,是否能用一条sql来完成。