Initialising a pl/sql record type
Use a function to act as a kind of "constructor" function (look at function f()):
DECLARE
TYPE ty_emp IS RECORD(
id INTEGER,
name VARCHAR(30),
deptcode VARCHAR(10)
);
TYPE ty_tbl_emp IS TABLE OF ty_emp;
tbl_emp ty_tbl_emp;
FUNCTION f ( -- <==============
id INTEGER,
name VARCHAR,
deptcode VARCHAR) RETURN ty_emp IS
e ty_emp;
BEGIN
e.id := id;
e.name := name;
e.deptcode := deptcode;
RETURN e;
END f;
BEGIN
tbl_emp := ty_tbl_emp(
f(1, 'Johnson', 'SALES'),
f(2, 'Peterson', 'ADMIN'));
Dbms_Output.put_line(tbl_emp(2).name);
END;
No, there is not. You have to assign each value explicitly. Documentation reference here.
Record types are really designed for holding rows from SELECT statements.
....
type location_record_type is record (
street_address varchar2(40),
postal_code varchar2(12),
city varchar2(30),
state_province varchar2(25),
country_id char(2) not null := 'US'
);
type location_record_nt is table of location_record_type;
loc_recs location_record_nt;
begin
select street_name
, pcode
, city
, region
, country_code
bulk collect into loc_recs
from t69
where ....
Obviously for cases where the query isn't a SELECT * FROM a single table (because in that scenario we can use %ROWTYPE
instead.