What would be the outcome of the above query?

Evaluate the following query:

What would be the outcome of the above query?

Evaluate the following query:

What would be the outcome of the above query?

A.
It produces an error because flower braces have been used.

B.
It produces an error because the data types are not matching.

C.
It executes successfully and introduces an ‘s at the end of each PROMO_NAME in the
output.

D.
It executes successfully and displays the literal “{‘s start date was \} * for each row in the
output.

Explanation:
So, how are words that contain single quotation marks dealt with? There are essentially two
mechanisms available. The most popular of these is to add an additional single quotation
mark next to each naturally occurring single quotation mark in the character string Oracle
offers a neat way to deal with this type of character literal in the form of the alternative quote
(q) operator. Notice that the problem is that Oracle chose the single quote characters as the
special pair of symbols that enclose or wrap any other character literal. These characterenclosing symbols could have been anything other than single quotation marks.
Bearing this in mind, consider the alternative quote (q) operator. The q operator enables you
to choose from a set of possible pairs of wrapping symbols for character literals as
alternatives to the single quote symbols. The options are any single-byte or multibyte
character or the four brackets:
(round brackets), {curly braces}, [squarebrackets], or <angle brackets>. Using the q
operator, the character delimiter can effectively be changed from a single quotation mark to
any other character The syntax of the alternative quote operator is as follows:

q’delimiter’character literal which may include the single quotes delimiter’ where delimiter can
be any character or bracket.
Alternative Quote (q) Operator
Specify your own quotation mark delimiter.
Select any delimiter.
Increase readability and usability.
SELECT department_name || q'[ Department’s Manager Id: ]’
|| manager_id
AS “Department and Manager”
FROM departments;
Alternative Quote (q) Operator
Many SQL statements use character literals in expressions or conditions. If the literal itself
contains a single quotation mark, you can use the quote (q) operator and select your own
quotation mark delimiter.
You can choose any convenient delimiter, single-byte or multi byte, or any of the following
character pairs: [ ], { }, ( ), or < >.
In the example shown, the string contains a single quotation mark, which is normally
interpreted as a delimiter of a character string. By using the q operator, however, brackets []
are used as the quotation mark delimiters. The string between the brackets delimiters is
interpreted as a literal character string.



Leave a Reply 3

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


Surersh

Surersh

Correct Answer : D

The Tuk

The Tuk

SQL> select promo_name || q'(‘s start date was \)’ || promo_begin_date as “Promotion Launches”
2 from promotions ;

Promotion Launches
——————————————————————-
NO PROMOTION #’s start date was \01-JAN-99
newspaper promotion #16-108’s start date was \23-DEC-00
post promotion #20-232’s start date was \25-SEP-98
newspaper promotion #16-349’s start date was \10-JUL-98
internet promotion #14-471’s start date was \26-FEB-00
TV promotion #13-448’s start date was \06-AUG-00
internet promotion #25-86’s start date was \20-SEP-98
TV promotion #12-49’s start date was \10-AUG-00
post promotion #21-166’s start date was \25-SEP-98
newspaper promotion #19-210’s start date was \19-MAR-99
post promotion #20-282’s start date was \06-DEC-00

Diego Muñoz

Diego Muñoz

I think it is a tricky question. Answer C it is correct because “Add a ‘s for each PROMO_NAME ” and Answer D says : “displays the literal “{‘s start date was \}” it is not correct because “{}” are not display, the just limit the string