#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    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
    BEGIN
    IF n <= 2 THEN
    RETURN 1;
    ELSE
    RETURN fibonacci(n-2) + fibonacci(n-1);
    END fibonacci;

    numbere BINARY_DOUBLE;
    counter NUMBER;
    BEGIN
    DBMS_OUT.PUT_LINE('Enter an integer: ');
    numbere := &input;
    IF numbere < 30
    counter := 5;
    ELSE
    counter := 10;
    FOR i IN..counter LOOP
    numbere := fibonacci(numbere)
    DBMS_OUT.PUT_LINE(i || ': ' || numbere || '***')
    END LOOP;
    DBMS_OUT.PUT_LINE('Final value: ' || numbere);
    END myPACKAGE;
    /
    Last edited by WebDev85; October 24th, 2013 at 06:59 PM. Reason: some know it all mocking me
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    834
    Rep Power
    387

    Cool


    Originally Posted by WebDev85
    I made this script but I still don't quite understand if the syntax completely. I just wanted to create . . . E t c . . .
    Perhaps you could learn all about packages, procedures and functions if you Read This Fine Manual:

    OracleŽ Database PL/SQL Language Reference
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    whatever


    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    oh yea


    Second of all, all of the code you see, I had to use java doc and pl/sql programming by oracle TO CREATE.
    GENIUS
    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.
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    834
    Rep Power
    387

    Thumbs down


    Originally Posted by WebDev85
    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.
    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:
    Code:
    SQL> CREATE OR REPLACE PACKAGE myPACKAGE AS
      2  CREATE OR REPLACE FUNCTION fibonacci
      3  (n BINARY_DOUBLE) RETURN BINARY_DOUBLE IS
      4  BEGIN
      5  IF n <= 2 THEN
      6  RETURN 1;
      7  ELSE
      8  RETURN fibonacci(n-2) + fibonacci(n-1);
      9  END fibonacci;
     10
     11  numbere BINARY_DOUBLE;
     12  counter NUMBER;
     13  BEGIN
     14  DBMS_OUT.PUT_LINE('Enter an integer: ');
     15  numbere := &input;
     16  IF numbere < 30
     17  counter := 5;
     18  ELSE
     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;
     26  /
    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:
    
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    2/1      PLS-00103: Encountered the symbol "CREATE" when expecting one of
             the following:
             end function pragma procedure subtype type <an identifier>
             <a double-quoted delimited-identifier> current cursor delete
             exists prior
    
    SQL>

IMN logo majestic logo threadwatch logo seochat tools logo