PLSQL:VARBIABLE:=序列。NEXTVAL或选择序列。将NEXTVAL转换成变量?

时间:2021-03-13 06:32:46

What is difference in PL/SQL from:

PL/SQL的区别在于:

CREATE OR REPLACE FUNCTION WBAR_TEST_1 RETURN NUMBER IS
  LN_TMP NUMBER;
BEGIN
  LN_TMP := SOME_SEQUENCE.NEXTVAL;
  RETURN LN_TMP;
END WBAR_TEST_1;

and

CREATE OR REPLACE FUNCTION WBAR_TEST_2 RETURN NUMBER IS
  LN_TMP NUMBER;
BEGIN
  SELECT SOME_SEQUENCE.NEXTVAL INTO LN_TMP FROM DUAL;
  RETURN LN_TMP;
END WBAR_TEST_2;

I think that second approach is only for history purposes only.

我认为第二种方法仅用于历史目的。

1 个解决方案

#1


11  

The first one became available with Oracle 11g, prior to that you had to SELECT seq_name.nextVal FROM dual. What is the difference? Well, the first one is easier to read in my opinion.

第一个在Oracle 11g中可用,在此之前您必须选择seq_name。从双nextVal。的区别是什么?嗯,我认为第一个比较容易理解。

What is more, Tim Hall on his site wrote that, according to documentation, the first (new) approach can improve performance. He performed some tests, but the difference was marginal.

更重要的是,Tim Hall在他的网站上写道,根据文档,第一个(新)方法可以提高性能。他做了一些测试,但差别很小。

Read more on Tim Hall's site: Sequences and NEXTVAL in PL/SQL

阅读更多关于Tim Hall的站点:PL/SQL中的序列和NEXTVAL。

On the other hand, as stated here About using NEXTVAL in PL/SQL - Oracle 11g, the underlying implementation of fetching the nextVal value hasn't changed, so in fact there should be no difference.

另一方面,正如这里所说的,在PL/SQL - Oracle 11g中使用NEXTVAL,获取NEXTVAL值的底层实现没有改变,所以实际上应该没有区别。

#1


11  

The first one became available with Oracle 11g, prior to that you had to SELECT seq_name.nextVal FROM dual. What is the difference? Well, the first one is easier to read in my opinion.

第一个在Oracle 11g中可用,在此之前您必须选择seq_name。从双nextVal。的区别是什么?嗯,我认为第一个比较容易理解。

What is more, Tim Hall on his site wrote that, according to documentation, the first (new) approach can improve performance. He performed some tests, but the difference was marginal.

更重要的是,Tim Hall在他的网站上写道,根据文档,第一个(新)方法可以提高性能。他做了一些测试,但差别很小。

Read more on Tim Hall's site: Sequences and NEXTVAL in PL/SQL

阅读更多关于Tim Hall的站点:PL/SQL中的序列和NEXTVAL。

On the other hand, as stated here About using NEXTVAL in PL/SQL - Oracle 11g, the underlying implementation of fetching the nextVal value hasn't changed, so in fact there should be no difference.

另一方面,正如这里所说的,在PL/SQL - Oracle 11g中使用NEXTVAL,获取NEXTVAL值的底层实现没有改变,所以实际上应该没有区别。