Language PL/SQL
(Another take on Oracle's DB language)
| Date: | 11/13/09 |
| Author: | Tysher |
| URL: | n/a |
| Comments: | 0 |
| Info: | n/a |
| Score: |
DECLARE
i NUMBER := 100;
FUNCTION p(n NUMBER) RETURN VARCHAR2 IS
BEGIN
RETURN CASE WHEN n=1 THEN 'no more'
WHEN n=0 THEN to_char(99)
ELSE to_char(n-1) END || ' bottle' ||
(CASE WHEN n=2 THEN ''
ELSE 's' END) || ' of beer';
END p;
BEGIN
LOOP
EXIT WHEN i = 0;
dbms_output.put_line(UPPER(substr(p(i),1,1)) || substr(p(i),2) || ' on the wall, ' ||
p(i) || '.');
i := i-1;
dbms_output.put_line(CASE WHEN i=0 THEN 'Go to the store and buy some more, '
ELSE 'Take one down and pass it around, ' END ||
p(i) || ' on the wall.');
dbms_output.new_line();
END LOOP;
END;
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