PL/SQL Error
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: PL/SQL Error

  1. #1
    Join Date
    Jun 2002
    Posts
    17

    Exclamation

    DECLARE
    var_remark VARCHAR2(75)
    := 'ABCDEFGHIJ ';
    BEGIN
    IF ( (var_remark IS NULL)
    OR (SUBSTR(
    var_remark,
    1,
    3) <> 'ABC')
    OR (SUBSTR(
    var_remark,
    1,
    3) <> 'DEF'))
    THEN
    DBMS_OUTPUT.put_line(
    'THIS IS NOT CORRECT ');
    ELSE
    DBMS_OUTPUT.put_line(
    'THIS IS CORRECT ');
    END IF;
    END;


    If i run this script i am getting THIS IS NOT CORRECT but I should get 'THIS IS CORRECT '

    Can any point out what error i am doing. May be i am making a silly mistake.

    Thanks

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,027
    This statement resolves to true
    since you have three conditions joinen by or's
    if only one is true the entire statement is true.
    And that is what is hapening.

    SUBSTR(var_remark,1,3) <> 'ABC')

  3. #3
    Join Date
    Jun 2002
    Posts
    17
    But I should get the answer as THIS IS CORRECT.

  4. #4
    Join Date
    Jun 2000
    Location
    Madrid, Spain
    Posts
    7,447
    at least format properly

    Code:
    DECLARE
      var_remark VARCHAR2(75) := 'ABCDEFGHIJ ';
    BEGIN
      IF var_remark IS NULL OR SUBSTR(var_remark,1,3) <> 'ABC' OR SUBSTR(var_remark,1,3) <> 'DEF'
      THEN
        DBMS_OUTPUT.put_line('THIS IS NOT CORRECT ');
      ELSE
        DBMS_OUTPUT.put_line('THIS IS CORRECT ');
      END IF;
    END;
    /
    var_mark 1, 3 is not DEF then condition satisfied therefore THIS IS NOT CORRECT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width