NULL(Snowflake Scripting)

NULL은 “no-op”(작업 없음) 문으로 사용할 수 있습니다.

참고

Using NULL as a statement is uncommon. NULL is usually used as a value, rather than as a statement.

As a value, NULL means “no value.” For more information, see the Wikipedia article on SQL NULL.

When working with semi-structured data types, such as JSON, you might need to distinguish between NULL as an SQL value and NULL as a JSON value (also called “VARIANT NULL”).

참고

Snowflake Scripting 구문은 Snowflake Scripting 블록 내에서만 유효합니다.

구문

NULL;
Copy

사용법 노트

  • The NULL statement can be executed only inside Snowflake Scripting code.

  • 예외 처리기의 NULL 문은 상위 수준 처리기가 없는 경우에 코드가 중단되지 않고 계속 실행되도록 보장해 줍니다.

  • A NULL statement in a branch does nothing; however, it communicates to the reader that the author of the code explicitly considered the condition for which the branch would execute. In other words, the NULL shows that the branch condition wasn’t overlooked or accidentally omitted.

  • NULL 문을 사용하기 전에 대안을 고려하십시오.

    예를 들어 예외 처리기로 저장 프로시저를 작성한다고 가정하겠습니다. 대부분의 저장 프로시저에서는 각각의 비 예외 코드 경로가 값을 반환해야 하는 경우에 예외 처리기를 수반하는 각 코드 경로 역시 값을 반환해야 합니다. 그러한 경우에는 NULL 문을 실행하지 마십시오. 대신에 NULL, 빈 결과 세트 또는 오류 표시기를 명시적으로 반환해 보십시오.

    CONTINUE 처리기를 사용하여 예외 블록에서 문을 실행하고 오류를 일으킨 문 바로 다음에 오는 문으로 계속 진행할 수도 있습니다. 자세한 내용은 Handling an exception in Snowflake Scripting 섹션을 참조하십시오.

Examples

다음 코드에서는 예외 처리기에 NULL 문을 사용하여 예외가 (호출자에게 전달되지는 않고) 포착되지만 아무런 구체적인 작업도 수행되지 않도록 합니다.

CREATE PROCEDURE null_as_statement()
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
BEGIN
  SELECT 1 / 0;
  RETURN 'If you see this, the exception was not thrown/caught properly.';
EXCEPTION
  WHEN OTHER THEN
      NULL;
END;
$$
;
Copy

저장 프로시저를 호출합니다.

CALL null_as_statement();
Copy
+-------------------+
| NULL_AS_STATEMENT |
|-------------------|
| NULL              |
+-------------------+

참고

The NULL value returned by the CALL statement isn’t directly due to the NULL statement in the exception. Instead, the return value is NULL because the stored procedure didn’t execute an explicit RETURN statement.

예외 처리기의 각 분기를 포함하여, 저장 프로시저가 명시적으로 값을 반환하도록 하는 것이 좋습니다.