create_scope.sql 564 B

12345678910111213141516171819202122
  1. CREATE OR REPLACE FUNCTION scope() RETURNS integer AS $$
  2. << outerblock >>
  3. DECLARE
  4. quantity integer := 30;
  5. BEGIN
  6. RAISE NOTICE 'Quantity here is %', quantity; -- Prints 30
  7. quantity := 50;
  8. --
  9. -- Create a subblock
  10. --
  11. DECLARE
  12. quantity integer := 80;
  13. BEGIN
  14. RAISE NOTICE 'Quantity here is %', quantity; -- Prints 80
  15. RAISE NOTICE 'Outer quantity here is %', outerblock.quantity; -- Prints 50
  16. END;
  17. RAISE NOTICE 'Quantity here is %', quantity; -- Prints 50
  18. RETURN quantity;
  19. END;
  20. $$ LANGUAGE plpgsql;