gpt4 book ai didi

oracle - 这些 PL/SQL 变量初始化是否等效?

转载 作者:行者123 更新时间:2023-12-02 09:31:52 26 4
gpt4 key购买 nike

所以我知道我可以使用以下任一方法初始化 PL/SQL 中的变量:

  • DEFAULT 关键字
  • := 赋值运算符

例如:

  • 计数器binary_integer DEFAULT 15;
  • 计数器binary_integer := 15;

这两种方法完全等同于PL/SQL引擎,还是有细微的差别?

最佳答案

是的,它们是等价的。

来自Oracle documentation

You can use the keyword DEFAULT instead of the assignment operator to initialize variables. You can also use DEFAULT to initialize subprogram parameters, cursor parameters, and fields in a user-defined record.

Use DEFAULT for variables that have a typical value. Use the assignment operator for variables (such as counters and accumulators) that have no typical value.

Example 2-8 Assigning Default Values to Variables with DEFAULT Keyword

SQL> DECLARE
2 blood_type CHAR DEFAULT 'O'; -- Same as blood_type CHAR := 'O';
3
4 hours_worked INTEGER DEFAULT 40; -- Typical value
5 employee_count INTEGER := 0; -- No typical value
6
7 BEGIN
8 NULL;
9 END;
10 /

PL/SQL procedure successfully completed.

SQL>

关于oracle - 这些 PL/SQL 变量初始化是否等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32231383/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com