create or replace type list_of_names_t is
table of varchar2(100);
Type created.
declare
big_brained_species list_of_names_t := list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
begin
for rec in (
select column_value species_name
from table ( big_brained_species )
order by species_name
) loop
dbms_output.put_line(rec.species_name);
end loop;
end;
Statement processed.
Bonobo
Dolphin
Gorilla
Human
Octopus
Raven
Whale
declare
big_brained_species list_of_names_t := list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
begin
for rec in (
select column_value species_name
from table (big_brained_species)
order by species_name
) loop
dbms_output.put_line(rec.species_name);
end loop;
end;
Statement processed.
Bonobo
Dolphin
Gorilla
Human
Octopus
Raven
Whale
declare
big_brained_species list_of_names_t := list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
begin
for rec in (
select column_value species_name
from table (big_brained_species)
where column_value like '%o%'
) loop
dbms_output.put_line(rec.species_name);
end loop;
end;
Statement processed.
Bonobo
Gorilla
Octopus
Dolphin
declare
big_brained_species list_of_names_t := list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
begin
for rec in (
select column_value || '-' || e.last_name name
from table (big_brained_species) bbs, hr.employees e
where substr (bbs.column_value, 1, 1) = substr (e.last_name, 1, 1)
) loop
dbms_output.put_line(rec.name);
end loop;
end;
Statement processed.
Bonobo-Baer
Bonobo-Baida
Bonobo-Banda
Bonobo-Bates
Bonobo-Bell
Bonobo-Bernstein
Bonobo-Bissot
Bonobo-Bloom
Bonobo-Bull
Dolphin-Davies
Dolphin-De Haan
Dolphin-Dellinger
Dolphin-Dilly
Dolphin-Doran
Gorilla-Gates
Gorilla-Gee
Gorilla-Geoni
Gorilla-Gietz
Gorilla-Grant
Gorilla-Grant
Gorilla-Greenberg
Gorilla-Greene
Human-Hall
Human-Hartstein
Human-Higgins
Human-Himuro
Human-Hunold
Human-Hutton
Octopus-OConnell
Octopus-Olsen
Octopus-Olson
Octopus-Ozer
Raven-Rajs
Raven-Raphaely
Raven-Rogers
Raven-Russell
Whale-Walsh
Whale-Weiss
Whale-Whalen
create or replace package brainiacs is
big_brained_species list_of_names_t := list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
end;
Package created.
select column_value species_name
from table ( brainiacs.big_brained_species )
order by species_name
ORA-06553: PLS-221: 'BIG_BRAINED_SPECIES' is not a procedure or is undefinedMore Details: https://docs.oracle.com/error-help/db/ora-06553
begin
for rec in (
select column_value species_name
from table ( brainiacs.big_brained_species )
order by species_name
) loop
dbms_output.put_line(rec.species_name);
end loop;
end;
Statement processed.
Bonobo
Dolphin
Gorilla
Human
Octopus
Raven
Whale
create or replace function big_brained_species return list_of_names_t is
begin
return list_of_names_t(
'Human',
'Bonobo',
'Gorilla',
'Octopus',
'Raven',
'Whale',
'Dolphin'
);
end;
Function created.
select column_value species_name
from table ( big_brained_species )
order by species_name
SPECIES_NAME | Bonobo | Dolphin | Gorilla | Human | Octopus | Raven | Whale |
---|
select column_value species_name
from big_brained_species
order by species_name
ORA-04044: procedure, function, package, or type is not allowed hereMore Details: https://docs.oracle.com/error-help/db/ora-04044
select column_value species_name
from big_brained_species ()
order by species_name
SPECIES_NAME | Bonobo | Dolphin | Gorilla | Human | Octopus | Raven | Whale |
---|
create or replace package brainiacs
is
type species_rt is record (name varchar2(100), average_size varchar2(100));
type species_aat is table of species_rt index by pls_integer;
big_brained_species species_aat := species_aat(
-10000 => species_rt ('Human', 'Medium'),
1000 => species_rt ('Bonobo', 'Medium'),
2000 => species_rt ('Gorilla', 'Large'),
3000 => species_rt ('Octopus', 'Small'),
4000 => species_rt ('Raven', 'Very Small'),
5000 => species_rt ('Whale', 'Very Large'),
6000 => species_rt ('Dolphin', 'Medium')
);
end;
Package created.
begin
for rec in (
select name, average_size
from table ( brainiacs.big_brained_species )
order by name desc
) loop
dbms_output.put_line(rec.average_size || ' ' || rec.name);
end loop;
end;
Statement processed.
Very Large Whale
Very Small Raven
Small Octopus
Medium Human
Large Gorilla
Medium Dolphin
Medium Bonobo
create or replace package brainiacs
is
type species_rt is record (name varchar2(100), average_size varchar2(100));
type species_aat is table of species_rt index by pls_integer;
function big_brained_species (p_like in varchar2 default '%') return species_aat;
end;
Package created.
create or replace package body brainiacs
is
function big_brained_species (
p_like in varchar2 default '%'
) return species_aat is
begin
return species_aat(
-10000 => species_rt('Human', 'Medium'),
1000 => species_rt('Bonobo', 'Medium'),
2000 => species_rt('Gorilla', 'Large'),
3000 => species_rt('Octopus', 'Small'),
4000 => species_rt('Raven', 'Very Small'),
5000 => species_rt('Whale', 'Very Large'),
6000 => species_rt('Dolphin', 'Medium')
);
end;
end;
Package Body created.
begin
for rec in (
select name, average_size
from table ( brainiacs.big_brained_species() )
order by name desc
) loop
dbms_output.put_line(rec.average_size || ' ' || rec.name);
end loop;
end;
ORA-06550: line 4, column 32: PLS-00382: expression is of wrong typeMore Details: https://docs.oracle.com/error-help/db/ora-06550
declare
l_species brainiacs.species_aat := brainiacs.big_brained_species();
begin
for rec in (
select name, average_size
from table ( l_species )
order by name desc
) loop
dbms_output.put_line(rec.average_size || ' ' || rec.name);
end loop;
end;
Statement processed.
Very Large Whale
Very Small Raven
Small Octopus
Medium Human
Large Gorilla
Medium Dolphin
Medium Bonobo