1. 程式人生 > >OCP-1Z0-051-V9 02-95題

OCP-1Z0-051-V9 02-95題

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

95. The  PRODUCTS table has the following structure:

name             Null            Type

PROD_ID          NOT NULL        NUMBER(4)

PROD_NAME                       VARCHAR2(25)

PROD_EXPIRY_DATE                DATE

Evaluate the following two SQL statements:

SQL>SELECT prod_id, NVL2(prod_expiry_date, prod_expiry_date + 15,'') 如果prod_expiry_date為null,則返回空,否則返回prod_expiry_date + 15

FROM products;

SQL>SELECT prod_id, NVL(prod_expiry_date, prod_expiry_date + 15) 如果prod_expiry_date為null,則返回prod_expiry_date + 15,否則返回prod_expiry_date

FROM products;

Which statement is true regarding the outcome?

A. Both the statements execute and give different results.

B. Both the statements execute and give the same result.

C. Only the first SQL statement executes successfully.

D. Only the second SQL statement executes successfully.

Answer: A   答案解析: 此題考的本意是NVL和NVL2之間邏輯計算的區別。   1、NVL 參考地址: http://blog.csdn.net/rlhua/article/details/11805803 2、NVL2  

Purpose

NVL2 lets you determine the value returned by a query based on whether a specified expression is null or not null.

If expr1 is not null, then NVL2 returns expr2. Ifexpr1 is null, then NVL2 returns expr3.

如果expr1非空,則返回expr2,如果expr1是空值,則返回expr3

The argument expr1 can have any data type. The arguments expr2 andexpr3 can have any data types except LONG.

expr1 可以是任意資料型別, expr2 and expr3 可以是任意資料型別,但不能是LONG型別,且資料型別要一致,或者隱式轉換為一致,或者顯示轉換為一致。

If the data types of expr2 and expr3 are different, then Oracle Database implicitly converts one to the other.

如果expr2 andexpr3 資料型別不同,則隱式轉為相同

 If they cannot be converted implicitly, then the database returns an error.

如果不能隱式轉換,則報錯。

If expr2 is character or numeric data, then the implicit conversion is implemented as follows:

  • If expr2 is character data, then Oracle Database converts expr3 to the data type ofexpr2 before returning a value unless expr3 is a null constant.

  • In that case, a data type conversion is not necessary, and the database returnsVARCHAR2 in the character set of expr2.

  • 如果expr2 是字元型別,則將expr3 轉換為expr2相同的資料型別。

  • If expr2 is numeric data, then Oracle Database determines which argument has the highest numeric precedence, implicitly converts the other argument to that data type, and returns that data type.

官方參考:http://docs.oracle.com/cd/E11882_01/server.112/e41084/functions120.htm#sthref1315

搭建環境:

1、建立表,插入資料。

[email protected]> create table products   2  (prod_id number(4) not null,   3  prod_name varchar2(25),   4  prod_expiry_date date);   Table created.   [email protected]> insert into products values(1,'tomato',sysdate);   1 row created.   [email protected]> select * from products;      PROD_ID PROD_NAME                 PROD_EXPI ---------- ------------------------- ---------          1 tomato                    18-SEP-13   2、開始測試: [email protected]> SELECT prod_id, NVL2(prod_expiry_date, prod_expiry_date + 15,'') from products;      PROD_ID NVL2(PROD ---------- ---------          1 03-OCT-13                                              prod_expiry_date非空,則返回prod_expiry_date + 15   [email protected]> SELECT prod_id, NVL(prod_expiry_date, prod_expiry_date + 15) from products;      PROD_ID NVL(PROD_ ---------- ---------          1 18-SEP-13 prod_expiry_date非空,則返回prod_expiry_date            

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述