Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

Variable scoping in BigQuery stored procedure

I am trying to create nested BEGIN..END blocks within the body of BigQuery stored procedure. The code is as follows:

CREATE OR REPLACE PROCEDURE dataset.proc(IN p_var1 INT64, OUT out_param STRING)
BEGIN
  DECLARE p_abc INT64;
  DECLARE p_bcd INT64;
  BEGIN
   DECLARE p_abc INT64 DEFAULT 0;                     //Error Here : re-declaration cannot occur.
   WHILE (p_abc <= p_bcd) DO
      BEGIN
        SET p_abc  =  p_abc + 1;
      END;
   END WHILE;
  END;
END;

The above stored procedure doesn't compile because of the redeclaration. Unlike in traditional databases, like Netezza or Teradata, I can easily perform such type of variable scoping.

Is there some way to do this on BigQuery or not possible at all?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The documentation says:

It is an error to declare a variable with the same name as a variable declared earlier in the current block or in a containing block.

So I would say it is impossible to create a variable with the same name in the case you described.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...