SQLite quote

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

SQLite quote() function

Description

The quote(X) function returns a string which is the value of its argument suitable for inclusion into another SQL statement. Strings are surrounded by single-quotes with escapes on interior quotes as needed.

Syntax

quote(X);

Argument

Name Description
X A string.

SQLite Version : 3.8.5

Example of SQLite quote() function

The following SQLite statement returns a string 'w3re' 'source'.

  1. SELECT quote('w3re''source');  

Here is the result.

quote('w3re''source')
------------------------------
'w3re''source'

Example of SQLite quote() function using table

Sample table : departments

department_id  department_name  manager_id  location_id
-------------  ---------------  ----------  -----------
10             Administration   200         1700
20             Marketing        201         1800
30             Purchasing       114         1700
40             Human Resources  203         2400
50             Shipping         121         1500
60             IT               103         1400
70             Public Relation  204         2700
80             Sales            145         2500
90             Executive        100         1700
100            Finance          108         1700
110            Accounting       205         1700
120            Treasury                     1700
130            Corporate Tax                1700
140            Control And Cre              1700
150            Shareholder Ser              1700
160            Benefits                     1700
170            Manufacturing                1700
180            Construction                 1700
190            Contracting                  1700
200            Operations                   1700
210            IT Support                   1700
220            NOC                          1700
230            IT Helpdesk                  1700
240            Government Sale              1700
250            Retail Sales                 1700
260            Recruiting                   1700
270            Payroll                      1700

The following statement returns the department_name and department_name enclosed with a single quote for those departments whose department_id is larger than 100.

  1. SELECT department_name, quote(department_name)   
  2. FROM departments  
  3. WHERE department_id>150;  

Here is the result.

department_name  quote(department_name)
---------------  ----------------------
Marketing        'Marketing'
Purchasing       'Purchasing'
Human Resources  'Human Resources'
Shipping         'Shipping'
IT               'IT'
Public Relation  'Public Relations'
Sales            'Sales'
Executive        'Executive'
Benefits         'Benefits'
Manufacturing    'Manufacturing'
Construction     'Construction'
Contracting      'Contracting'
Operations       'Operations'
IT Support       'IT Support'
NOC              'NOC'
IT Helpdesk      'IT Helpdesk'
Government Sale  'Government Sales'
Retail Sales     'Retail Sales'
Recruiting       'Recruiting'
Payroll          'Payroll'