Topic: SQL*Plus and PL/SQL >> Fibonacci
|
Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property.
You may review the entire Oracle Certification Program Candidate Agreement online Here.
|
|
|
|
| focusora |
Posted: Jul 11, 2008 01:53:34 AM |
Total Post: 18
Joined: May, 2008
|
Hi all.,
i created fibonacci function , it works fine but i need out put in string
format :
Present code if i call 5 | function gives : 5
but
i need output for all in string sequence like :
call (5)
function must give : 1,1,2,3,5
how can i proceed this loop., assist please.,
COde
===
CREATE OR REPLACE FUNCTION MTNL.FIBONACCI_REC (in_number IN NUMBER)
RETURN NUMBER DETERMINISTIC
AS
BEGIN
CASE
WHEN in_number = 1 THEN RETURN 1;
WHEN in_number = 2 THEN RETURN 1;
ELSE RETURN (FIBONACCI_REC (in_number - 1) + FIBONACCI_REC (in_number - 2));
END CASE;
END;
|
|
|
shake |
| Posted: Jul 11, 2008 04:25:19 AM | |
|
Total Post: 85
Joined: Jun, 2008
|
DECLARE
in_number NUMBER := 10;
n1 NUMBER := 1;
n2 NUMBER := 1;
n3 NUMBER;
cnt NUMBER;
BEGIN
IF in_number <= 0 THEN
dbms_output.put_line('Invalid input');
END IF;
IF in_number = 1 THEN
dbms_output.put_line(n1);
ELSE
IF in_number = 2 THEN
dbms_output.put_line(n1);
dbms_output.PUT_LINE(n2);
ELSE
dbms_output.put_line(n1);
dbms_output.PUT_LINE(n2);
cnt := 2;
LOOP
EXIT WHEN cnt = in_number;
n3 := n1 + n2;
dbms_output.PUT_LINE(n3);
n1 := n2;
n2 := n3;
cnt := cnt + 1;
END LOOP;
END IF;
END IF;
END;
|
|
|
|
|
positive |
| Posted: Jul 13, 2008 01:07:12 AM | |
|
Total Post: 483
Joined: Jun, 2008
|
http://neworacledba.blogspot.com/
|
|
|
|
|
| Time Zone: EDT |
Send this thread to your friend |
|
|
|
|
Forum Rules & Description
Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user
|
| |
Get FREE Magazines
|
Top 10 Forum User
|
| Murtuja Khokhar | 857 |
| Mohammed Taj | 746 |
| positive fanatic | 483 |
| Jayanta Sur | 479 |
| Vigyan Kaushik | 386 |
| Vinoth Kumar | 364 |
| Gopu Gopi | 340 |
| Gitesh Trivedi | 322 |
| neeraj sharma | 258 |
| Ramesh Jois | 246 |
|
|