Header Ads

Header ADS

Literal Character Strings

 Literal Character Strings

Topic Introduction: In this tutorial, we will discuss using Literal Character Strings. In SQL query we return column value but sometimes need to add some literal character with the database column or alone to show meaningful information or data. Description and example are given below to clear of using literal strings.  







1. A literal is a character, a number, or a date that is included in the SELECT statement.
2. Date and character literal values must be enclosed within single quotation marks (' ').
3. Each character string is output once for each row returned.

Using Literal Character Strings


SELECT first_name || ' ' || last_name || ' is a ' || job_id
           AS "Employee Details"
  FROM employees; 



In this Query ' is a ' is a literal character string. to add this to my query I have used a single quotation (' ').



Alternative Quote (q) Operator

1. Specify your own quotation mark delimiter.
2. Select any delimiter.
3. Increase readability and usability.


SELECT department_name || q'[ Department's Manager Id: ]' || manager_id
           AS "Department and Manager"
  FROM departments; 



Many SQL statements use character literals in expressions or conditions. If the literal itself contains a
single quotation mark, we can use the quote (q) operator and select your own quotation mark
delimiter.


No comments

Theme images by Deejpilot. Powered by Blogger.