Which two SQL statements would execute successfully?

See the structure of the PROGRAMS table:

Which two SQL statements would execute successfully? (Choose two.)

See the structure of the PROGRAMS table:

Which two SQL statements would execute successfully? (Choose two.)

A.
SELECT NVL(ADD_MONTHS(END_DATE,1),SYSDATE)
FROM programs;

B.
SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
FROM programs;

C.
SELECT NVL(MONTHS_BETWEEN(start_date,end_date),’Ongoing’)
FROM programs;

D.
SELECT NVL(TO_CHAR(MONTHS_BETWEEN(start_date,end_date)),’Ongoing’) FROM
programs;

Explanation:
NVL Function
Converts a null value to an actual value:
Data types that can be used are date, character, and number.
Data types must match:
NVL(commission_pct,0)
NVL(hire_date,’01-JAN-97′)
NVL(job_id,’No Job Yet’)
MONTHS_BETWEEN(date1, date2): Finds the number of months between date1 and date2
The result can be positive or negative. If date1 is later than date2, the result is positive; if date1 is
earlier than date2, the result is negative. The noninteger part of the result represents a portion of
the month.
MONTHS_BETWEEN returns a numeric value. – answer C NVL has different datatypes – numeric
and strings, which is not possible!
The data types of the original and if null parameters must always be compatible. They must either
be of the same type, or it must be possible to implicitly convert if null to the type of the original
parameter. The NVL function returns a value with the same data type as the original parameter.



Leave a Reply 13

Your email address will not be published. Required fields are marked *


Eamon

Eamon

Point of note.

Be careful with B

Here is why …

This works …
SELECT NVL(SYSDATE-END_DATE,SYSDATE) FROM programs;

PROGRAMS is actually a table in the SYS schema so you can test it there (WARNING, no messing about in SYS, OK)

1 SELECT PROG_ID, SYSDATE, END_DATE, SYSDATE-END_DATE, NVL(SYSDATE-END_DATE,SYSDATE)
2 — , TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
3 FROM programs
4* where PROG_ID !=4
SQL> /

PROG_ID SYSDATE END_DATE SYSDATE-END_DATE NVL(SYSDATE-END_DATE,SYSDATE)–,TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
———- ——— ——— —————- ———————————————————————-
1 21-SEP-15 06-AUG-15 46.7854745 46.7854745
2 21-SEP-15 27-JUL-15 56.7854745 56.7854745
3 21-SEP-15 17-JUL-15 66.7854745 66.7854745
5 21-SEP-15 27-JUN-15 86.7854745 86.7854745

However this doesnt work
SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE)) FROM programs;
because you cannot TO_DATE the number 46.7854745.
So the problem is this case is not due to NVL.

From Vietnam

From Vietnam

SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE)) FROM programs;

Sysdate – end_date => return value of Number, but sysdate is Date.
NVL(exp1, exp2) requires that type of exp1, and exp2 have to be the same.
That is the cause of error!

Q41 is really hard and time consuming to solve.

Eamon

Eamon

Woops, I forgot the most important point …..(Murphys law and all that)

The 2 arguments to NVL can have any data type. If their data types are different, then Oracle implicitly converts one to the other. So in my example above it implicitly converts a date to a number, this is possible because DATE is stored in a numeric format.

Sadiq Al Sahaf (Sojib)

Sadiq Al Sahaf (Sojib)

Yeah..!!
Correct Answer: A & D

Google

Google

Here are some hyperlinks to internet sites that we link to since we believe they’re worth visiting.

youtubemp3download3- Youtube to mp3 converter

youtubemp3download3- Youtube to mp3 converter

very couple of websites that happen to be comprehensive below, from our point of view are undoubtedly properly worth checking out

mobile app builder

mobile app builder

that could be the finish of this report. Right here youll find some sites that we think youll appreciate, just click the hyperlinks over

mobile app builder

mobile app builder

that could be the end of this report. Here youll discover some web-sites that we think youll appreciate, just click the hyperlinks over

SEO services in Lahore

SEO services in Lahore

one of our visitors not long ago advised the following website

social apps

social apps

below youll uncover the link to some sites that we feel you should visit

app maker free

app maker free

Sites of interest we’ve a link to

no startup fee work at home jobs

no startup fee work at home jobs

check below, are some entirely unrelated internet sites to ours, having said that, they’re most trustworthy sources that we use

Fenster

Fenster

just beneath, are quite a few absolutely not associated web sites to ours, having said that, they are certainly worth going over