Académique Documents
Professionnel Documents
Culture Documents
SQL> @ atsd1
Please enter the donor idno: 23456
SQL> @atsd2
Please enter the donor idno: 11111
SQL> @ atsd2a
Please enter the donor idno: 33333
VALUES(a_rec_donor);
*
ERROR at line 10:
ORA-06550: line 10, column 11:
PLS-00382: expression is of wrong type
ORA-06550: line 9, column 4:
PL/SQL: SQL Statement ignored
ROWTYPE SQL> DESC some_donor
Name Null? Type
------------------------------- -------- ----
IDNO VARCHAR2(5)
NAME VARCHAR2(15)
YRGOAL NUMBER(7,2)
SQL> @ atsd4
Please enter the donor idno: 22222
SET SERVEROUTPUT ON
DECLARE
TYPE t_table1 IS TABLE OF VARCHAR2(12)
INDEX BY BINARY_INTEGER;
v_table_var t_table1;
v_count_result NUMBER;
BEGIN
v_table_var(5) := 'Fifth week';
v_table_var(2) := 'Second week';
v_table_var(12) := 'Twelfth week';
v_table_var(6) := 'Sixth week';
v_count_result:= v_table_var.COUNT;
dbms_output.put_line('The count is: '||v_count_result);
END;
/
SET SERVEROUTPUT OFF
SQL> @ table1
The count is: 4
SET SERVEROUTPUT ON
DECLARE
Output:
TYPE t_table1 IS TABLE OF VARCHAR2(12)
INDEX BY BINARY_INTEGER;
v_table_var t_table1; SQL> @ table1a
v_count_result NUMBER; The current place is: 2
v_place NUMBER; The current place is: 5
BEGIN The current place is: 6
v_table_var(5) := 'Fifth week'; The current place is: 12
v_table_var(2) := 'Second week'; The count is: 4
v_table_var(12) := 'Twelfth week';
v_table_var(6) := 'Sixth week';
v_place := v_table_var.FIRST;
FOR x IN 1..4 LOOP
dbms_output.put_line('The current place is: ' || v_place);
v_place := v_table_var.NEXT(v_place);
END LOOP;
v_count_result:= v_table_var.COUNT;
dbms_output.put_line('The count is: '||v_count_result);
END;
/
SET SERVEROUTPUT OFF
TYPE..TABLE SQL> @table2
Enter value for in_num: 5
old 6: v_num NUMBER :=&in_num;
new 6: v_num NUMBER :=5;
SQL> edit table2
The count is: 4
SET SERVEROUTPUT ON The record exists
DECLARE
TYPE t_table1 IS TABLE OF VARCHAR2(12) PL/SQL procedure successfully completed.
INDEX BY BINARY_INTEGER;
v_table_var t_table1;
v_count_result NUMBER;
v_num NUMBER :=&in_num;
BEGIN
v_table_var(5) := 'Fifth week';
v_table_var(2) := 'Second week';
v_table_var(12) := 'Twelfth week';
v_table_var(6) := 'Sixth week';
v_count_result:= v_table_var.COUNT;
dbms_output.put_line('The count is: '||v_count_result);
IF v_table_var.EXISTS(v_num) THEN
dbms_output.put_line('The record exists');
ELSE
dbms_output.put_line('The record does not exist');
END IF;
END; SQL> @ table2
/ Enter value for in_num: 8
SET SERVEROUTPUT OFF old 6: v_num NUMBER :=&in_num;
new 6: v_num NUMBER :=8;
The count is: 4
The record does not exist
SET SERVEROUTPUT ON
DECLARE
input_area VARCHAR2(20) :='South Shore MA';
TYPE t_areacode_type IS TABLE OF VARCHAR2(20) Output:
INDEX BY BINARY_INTEGER;
v_area t_areacode_type; SQL> @ areacodett
v_index NUMBER; Rhode Island 401
BEGIN Southeastern MA 508
v_area(508) := 'Southeastern MA'; Boston MA 617
v_area(617) := 'Boston MA'; South Shore MA 781
v_area(781) := 'South Shore MA'; Match: South Shore MA 781
v_area(401) := 'Rhode Island';
v_area(999) := 'region not found';
v_index := v_area.FIRST;
LOOP
DBMS_OUTPUT.PUT_LINE(v_area(v_index) ||' ' || v_index);
EXIT WHEN v_index = v_area.LAST OR v_area(v_index) = input_area;
v_index := v_area.NEXT(v_index);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Match: ' || v_area(v_index) ||' ' || v_index);
END;
/
SET SERVEROUTPUT OFF
TYPE..TABLE
In this example, processing stops when Boston is encountered.
This causes the EXIT because v_area(v_index) = input_area.
SET SERVEROUTPUT ON
DECLARE
input_area VARCHAR2(20) :=Boston MA';
TYPE t_areacode_type IS TABLE OF VARCHAR2(20)
INDEX BY BINARY_INTEGER; Output:
v_area t_areacode_type;
v_index BINARY_INTEGER;
SQL> @ areacodett
BEGIN Rhode Island 401
v_area(508) := 'Southeastern MA'; Southeastern MA 508
v_area(617) := 'Boston MA'; Boston MA 617
v_area(781) := 'South Shore MA'; Match: Boston MA 617
v_area(401) := 'Rhode Island';
v_area(999) := 'region not found';
v_index := v_area.FIRST;
LOOP
DBMS_OUTPUT.PUT_LINE(v_area(v_index) ||' ' || v_index);
EXIT WHEN v_index = v_area.LAST OR v_area(v_index) = input_area;
v_index := v_area.NEXT(v_index);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Match: ' || v_area(v_index) ||' ' || v_index);
END;
/
SET SERVEROUTPUT OFF
TYPETABLE
In this example, there is no match for XXX MA, so when all
elements of the array have been completed, processing ends.
The LAST attribute is what makes this work. When v_index
which keeps getting incremented to the NEXT number finall
SQL> edit areacodett equals the last number in the table, processing ends.
SET SERVEROUTPUT ON
DECLARE
input_area VARCHAR2(20) :=XXX MA';
TYPE t_areacode_type IS TABLE OF VARCHAR2(20) Output:
INDEX BY BINARY_INTEGER;
v_area t_areacode_type; SQL> @ areacodett
v_index NUMBER; Rhode Island 401
BEGIN Southeastern MA 508
v_area(508) := 'Southeastern MA'; Boston MA 617
v_area(617) := 'Boston MA'; South Shore MA 781
v_area(781) := 'South Shore MA'; region not found 999
v_area(401) := 'Rhode Island'; Match: region not found 999
v_area(999) := 'region not found';
v_index := v_area.FIRST;
LOOP
DBMS_OUTPUT.PUT_LINE(v_area(v_index) ||' ' || v_index);
EXIT WHEN v_index = v_area.LAST OR v_area(v_index) = input_area;
v_index := v_area.NEXT(v_index);
END LOOP;
DBMS_OUTPUT.PUT_LINE('Match: ' || v_area(v_index) ||' ' || v_index);
END;
/
SET SERVEROUTPUT OFF