October 21st, 2013, 11:00 PM
Package creation/calling package
I made this script but I still don't quite understand if the syntax is correct. I just wanted to create a function and call it in an anonymous block. I then wanted it to use a variable as a parameter in an iteration and output the variable every iteration. It's done basically but I know it's not 100% right. The fibonacci function looks like its going to loop an infinite number of times if the parameter is greater than 2.
CREATE OR REPLACE PACKAGE myPACKAGE AS
CREATE OR REPLACE FUNCTION fibonacci
(n BINARY_DOUBLE) RETURN BINARY_DOUBLE IS
IF n <= 2 THEN
RETURN fibonacci(n-2) + fibonacci(n-1);
DBMS_OUT.PUT_LINE('Enter an integer: ');
numbere := &input;
IF numbere < 30
counter := 5;
counter := 10;
FOR i IN..counter LOOP
numbere := fibonacci(numbere)
DBMS_OUT.PUT_LINE(i || ': ' || numbere || '***')
DBMS_OUT.PUT_LINE('Final value: ' || numbere);
Last edited by WebDev85; October 24th, 2013 at 06:59 PM.
Reason: some know it all mocking me
October 22nd, 2013, 04:22 PM
Perhaps you could learn all about packages, procedures and functions if you Read This Fine Manual:
Originally Posted by WebDev85
OracleŽ Database PL/SQL Language Reference
October 24th, 2013, 06:21 PM
The manual is horrible. I'm also using PL/SQL Programming written by Oracle. Well, I'm going to assume that it's correct since nobody is posting or that nobody on this forum knows about PL/SQL.
October 24th, 2013, 06:28 PM
I use oracle doc, java doc by oracle, PL/SQL manual by oracle.
Keep your snide comments to yourself. I don't understand a lot of the syntax of PL/SQL and I work with over 7 languages. So, please help me or do not post discouraging comments. All I want to know is ANYTHING WRONG WITH THE SCRIPT THAT "I" WROTE. SO OBVIOUSLY I UNDESTAND SOME THINGS....THANK YOU.
October 24th, 2013, 06:34 PM
Second of all, all of the code you see, I had to use java doc and pl/sql programming by oracle TO CREATE.
AND THIRD OF ALL WHEN I CAME TO THIS FORUM I TYPED PL/SQL AND HELP INTO GOOGLE...OKAY SO TAKE THE WORD HELP OUT OF YOUR SEARCH WORDS.
October 28th, 2013, 01:27 PM
Obviously you don't understand anything and it seems you did not even consult the manual to be able to code using the CORRECT syntax:
Originally Posted by WebDev85
SQL> CREATE OR REPLACE PACKAGE myPACKAGE AS
2 CREATE OR REPLACE FUNCTION fibonacci
3 (n BINARY_DOUBLE) RETURN BINARY_DOUBLE IS
5 IF n <= 2 THEN
6 RETURN 1;
8 RETURN fibonacci(n-2) + fibonacci(n-1);
9 END fibonacci;
11 numbere BINARY_DOUBLE;
12 counter NUMBER;
14 DBMS_OUT.PUT_LINE('Enter an integer: ');
15 numbere := &input;
16 IF numbere < 30
17 counter := 5;
19 counter := 10;
20 FOR i IN..counter LOOP
21 numbere := fibonacci(numbere)
22 DBMS_OUT.PUT_LINE(i || ': ' || numbere || '***')
23 END LOOP;
24 DBMS_OUT.PUT_LINE('Final value: ' || numbere);
25 END myPACKAGE;
Enter value for input: 99
old 15: numbere := &input;
new 15: numbere := 99;
Warning: Package created with compilation errors.
SQL> show error
Errors for PACKAGE MYPACKAGE:
2/1 PLS-00103: Encountered the symbol "CREATE" when expecting one of
end function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete