Language PL/PGSQL
(Version returning SETOF)
| Date: | 06/08/06 |
| Author: | Luis Carlos F. Dias |
| URL: | n/a |
| Comments: | 2 |
| Info: | n/a |
| Score: |
create or replace function BottlesOfBeerSong () returns SETOF text
as '
declare
i integer := 99 ;
out1 text := '''' ;
out2 text := '''' ;
begin
while (i >= 0) loop
out1 := i || '' bottles of beer on the wall, '' || i || '' bottles of beer.'' ;
if (i > 2) then
out2 := ''Take one down and pass it around, '' || i-1 || '' bottles of beer on the wall.'' ;
elsif (i = 2) then
out2 := ''Take one down and pass it around, 1 bottle of beer on the wall.'' ;
elsif (i = 1) then
out1 := ''1 bottle of beer on the wall, 1 bottle of beer.'' ;
out2 := ''Take one down and pass it around, no more bottles of beer on the wall.'' ;
elsif (i = 0) then
out1 := ''No more bottles of beer on the wall, no more bottles of beer.'' ;
out2 := ''Go to the store and buy some more, 99 bottles of beer on the wall.'' ;
end if ;
return next out1 ;
return next out2 ;
i := i - 1 ;
end loop ;
return ;
end ;
'
language 'plpgsql' ;
select * from BottlesOfBeerSong() ;
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
select * from BottlesOfBeerSong() ; <-- note the use of ( )
It could be:
create or replace view BottlesOfBeerSong as
select * from BottlesOfBeerSong() ;
and you could get the result calling
select * from BottlesOfBeerSong ;