Home > OS >  why am i getting this error. Can anyone help me?
why am i getting this error. Can anyone help me?

Time:05-17

The following Oracle statement:

CREATE OR REPLACE PACKAGE BODY pk1
IS 
    FUNCTION RETURN_BOOLEAN(v_accno bank.accno%TYPE) 
    RETURN BOOLEAN
    IS
        BEGIN
            SELECT COUNT(*) INTO v_count 
            FROM bank 
            WHERE accno = v_accno;
                IF v_count = 0 THEN
                    RETURN TRUE;
                ELSE 
                    RETURN FALSE;
                END IF;
END;

Gives me the following error:

13/4 PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin end function pragma procedure Errors: check compiler log

CodePudding user response:

What is opened, must be closed - you didn't close package body. It is a good habit to specify which procedure you're actually closing (see all END lines).

Also, you have to declare a variable (v_count).

SQL> CREATE OR REPLACE PACKAGE pk1
  2  AS
  3     FUNCTION return_boolean (v_accno bank.accno%TYPE)
  4        RETURN BOOLEAN;
  5  END pk1;
  6  /

Package created.

SQL> CREATE OR REPLACE PACKAGE BODY pk1
  2  IS
  3     FUNCTION return_boolean (v_accno bank.accno%TYPE)
  4        RETURN BOOLEAN
  5     IS
  6        v_count  NUMBER;
  7     BEGIN
  8        SELECT COUNT (*)
  9          INTO v_count
 10          FROM bank
 11         WHERE accno = v_accno;
 12
 13        IF v_count = 0
 14        THEN
 15           RETURN TRUE;
 16        ELSE
 17           RETURN FALSE;
 18        END IF;
 19     END return_boolean;
 20  END pk1;
 21  /

Package body created.

SQL>

Note that you could have simplified the return statement to just one line:

RETURN v_count = 0;

(no need for IF-THEN-ELSE).

CodePudding user response:

The function declaration also needs a closing END keyword. Either just END; or END <function_name>; works.

CREATE OR REPLACE PACKAGE BODY pk1
IS 
    FUNCTION RETURN_BOOLEAN(v_accno bank.accno%TYPE) 
    RETURN BOOLEAN
    IS
      v_count NUMBER;
        BEGIN
            SELECT COUNT(*) INTO v_count 
            FROM bank 
            WHERE accno = v_accno;
                IF v_count = 0 THEN
                    RETURN TRUE;
                ELSE 
                    RETURN FALSE;
                END IF;
  END RETURN_BOOLEAN;
END;

ah and you missed the declaration of v_count

  • Related