Initialize Record in Declaration Section!
DECLARE
TYPE species_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
l_elephant species_rt := species_rt ('Elephant', 'Savannah', '10000');
PROCEDURE display_species (
species_in species_rt DEFAULT species_rt ('Not Set', 'Global', 0))
IS
BEGIN
DBMS_OUTPUT.put_line ('Species: ' || species_in.species_name);
DBMS_OUTPUT.put_line ('Habitat: ' || species_in.habitat_type);
DBMS_OUTPUT.put_line ('# Left: ' || species_in.surviving_population);
END;
BEGIN
display_species (l_elephant);
/* Use the default */
display_species ();
END;
create table species
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
)
Sorry, Not For %ROWTYPE Record Types!
DECLARE
l_elephant species%rowtype := species%rowtype ('Elephant', 'Savannah', '10000');
BEGIN
NULL;
END;
Use Named Notation in Qualified Expression
DECLARE
TYPE species_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
l_elephant species_rt
:= species_rt (species_name => 'Elephant',
surviving_population => '10000',
habitat_type => 'Savannah');
PROCEDURE display_species (
species_in species_rt DEFAULT species_rt ('Not Set', 'Global', 0))
IS
BEGIN
DBMS_OUTPUT.put_line ('Species: ' || species_in.species_name);
DBMS_OUTPUT.put_line ('Habitat: ' || species_in.habitat_type);
DBMS_OUTPUT.put_line ('# Left: ' || species_in.surviving_population);
END;
BEGIN
display_species (l_elephant);
/* Use the default */
display_species ();
END;
Types Must Match!
DECLARE
TYPE species1_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
TYPE species2_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
l_species1 species1_rt := species1_rt ('Elephant', 'Savannah', '10000');
l_species2 species2_rt;
BEGIN
l_species2 := l_species1;
END;
Field by Field for Different "Same" Types
DECLARE
TYPE species1_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
TYPE species2_rt IS RECORD
(
species_name VARCHAR2 (100),
habitat_type VARCHAR2 (100),
surviving_population INTEGER
);
l_species1 species1_rt := species1_rt ('Elephant', 'Savannah', '10000');
l_species2 species2_rt;
BEGIN
l_species2 :=
species2_rt (l_species1.species_name,
l_species1.habitat_type,
l_species1.surviving_population);
END;