OCP 1Z0 051 17

17. View the E xhibit and examine the data in the EMPLOYEES table. 
You want to generate a report showing the total compensation paid to each employee to   date. 
You issue the following query: 
SQL>SELECT ename ' joined on ' hiredate      
', the total compensation paid is '     
TO_CHAR(ROUND(ROUND(SYSDATE-hiredate)/365) * sal + comm)     
"COMPENSATION UNTIL DATE"     
FROM employees; 
What is the outcome?  
OCP 1Z0 051 17_第1张图片
A. It generates an error because the alias is not valid. 
B. It executes successfully and gives the correct output. 
C. It executes successfully but does not give the correct output. 
D. It generates an error because the usage of the   ROUND function in the expression is not valid. 
E. It generates an error because the concatenation operator can be used to combine only two items. 
考点:null
null与任何值四则运算结果均为空值
SQL> select 1 + null as c2,2 as c3 from dual;
        C2         C3
---------- ----------
                    2
Executed in 0.016 seconds

在oracle中,字符串与null连接不为空

SQL> select '有值' || null as "不为空"  from dual;
不为空
------
有值
Executed in 0.016 seconds

我们以emp表为例显示该题结果

SQL> select * from emp;
     EMPNO ENAME      JOB               MGR HIREDATE           SAL       COMM     DEPTNO
---------- ---------- ---------- ---------- ----------- ---------- ---------- ----------
      7369 SMITH      CLERK            7902 1980-12-17         800                    20
      7499 ALLEN      SALESMAN         7698 1981-2-20         1600        300         30
      7521 WARD       SALESMAN         7698 1981-2-22         1250        500         30
      7566 JONES      MANAGER          7839 1981-4-2          2975                    20
      7654 MARTIN     SALESMAN         7698 1981-9-28         1250       1400         30
      7698 BLAKE      MANAGER          7839 1981-5-1          2850                    30
      7782 CLARK      MANAGER          7839 1981-6-9          2450                    10
      7788 SCOTT      ANALYST          7566 1982-12-9         3000                    20
      7839 KING       PRESIDENT             1981-11-17        5000                    10
      7844 TURNER     SALESMAN         7698 1981-9-8          1500          0         30
      7876 ADAMS      CLERK            7788 1983-1-12         1100                    20
      7900 JAMES      CLERK            7698 1981-12-3          950                    30
      7902 FORD       ANALYST          7566 1981-12-3         3000                    20
      7934 MILLER     CLERK            7782 1982-1-23         1300                    10
14 rows selected
Executed in 0.032 seconds

SQL> 
SQL> SELECT ename || ' joined on ' || hiredate ||
  2         ', the total compensation paid is ' ||
  3         to_char(round(round(SYSDATE - hiredate) / 365) * sal + comm) "COMPENSATION UNTIL DATE"
  4    FROM emp;
COMPENSATION UNTIL DATE
--------------------------------------------------------------------------------
SMITH joined on 17-12月-80, the total compensation paid is
ALLEN joined on 20-2月 -81, the total compensation paid is 53100
WARD joined on 22-2月 -81, the total compensation paid is 41750
JONES joined on 02-4月 -81, the total compensation paid is
MARTIN joined on 28-9月 -81, the total compensation paid is 42650
BLAKE joined on 01-5月 -81, the total compensation paid is
CLARK joined on 09-6月 -81, the total compensation paid is
SCOTT joined on 09-12月-82, the total compensation paid is
KING joined on 17-11月-81, the total compensation paid is
TURNER joined on 08-9月 -81, the total compensation paid is 49500
ADAMS joined on 12-1月 -83, the total compensation paid is
JAMES joined on 03-12月-81, the total compensation paid is
FORD joined on 03-12月-81, the total compensation paid is
MILLER joined on 23-1月 -82, the total compensation paid is
14 rows selected
Executed in 0.078 seconds



Answer: C 

你可能感兴趣的:(OCP 1Z0 051 17)