DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: PL/SQL question

  1. #1
    Join Date
    Jul 2001
    Posts
    59

    Question

    The NetG CBT course has the following page:

    The example on the screen illustrates the scope rules.
    Notice that the variables declared in one subblock cannot
    be referenced in the other subblock. That is because a
    block cannot reference variables declared in other blocks
    nested at the same level.

    DECLARE
    a CHAR;
    b REAL;
    BEGIN
    --identifiers available here: a
    DECLARE
    a INTEGER;
    c REAL;
    BEGIN
    --identifiers available here: a
    END;
    END;
    /

    Can someone please tell me why "b" is not available in the first block and why "c" is not available in the second block?
    It seems to me like "a CHAR" and "b REAL" should be available Globally and "a INTEGER" and "c REAL" should be available only in the subblock. I don't get it.

    A misprint, or am I not getting their jist? Maybe what they are saying is that the first BEGIN statement is a subblock and not the highest level block. In that case it makes some sense, but wouldn't that mean that "b REAL" should be available to the lower block? Or is it only the Global variables that can be shared by all lower blocks in the main DECLARE statement?

    So, if that is true then it all makes sense. The diagram should have looked like this:

    DECLARE
    --Global variables are here
    BEGIN
    ...
    DECLARE
    a CHAR;
    b REAL;
    BEGIN
    --identifiers available here: a
    DECLARE
    a INTEGER;
    c REAL;
    BEGIN
    --identifiers available here: a
    END;
    END;
    END;
    /

    NO -- because I still don't understand why "b REAL" is not availble where the first "--identifiers available here: a" is at.
    AND why "c REAL" is not availble where the second "--identifiers available here: a" is at.

    UGGGGH!!!!!


  2. #2
    Join Date
    Oct 2001
    Posts
    3
    yes,

    i was looking at that section as well (cbt) and the statement makes no sence to me either
    -in regard to the scope of two sub blocks on the same level

    to me it should be:

    DECLARE
    a CHAR;
    b REAL;
    BEGIN
    --identifiers available here: a (char) & b
    DECLARE
    a INTEGER;
    c REAL;
    BEGIN
    --identifiers available here: a (integerl) b & c
    END;
    DECLARE
    d CHAR;
    BEGIN
    --identifiers available here: a (char) b & d
    END;
    END;
    /

    ?????????? -- i hope so as i am sitting the exam tomorrow

  3. #3
    Join Date
    Jul 2001
    Posts
    59
    Originally posted by DDIRE
    ?????????? -- i hope so as i am sitting the exam tomorrow
    Looks to me like we are thinking the same thing. I hope we are BOTH right!

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