{"id":127,"date":"2009-11-20T08:41:12","date_gmt":"2009-11-20T13:41:12","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2009\/11\/20\/how-to-use-the-ampersand-symbol-in-sql-statements-as-a-literal-value\/"},"modified":"2009-11-20T08:41:12","modified_gmt":"2009-11-20T13:41:12","slug":"how-to-use-the-ampersand-symbol-in-sql-statements-as-a-literal-value","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2009\/11\/20\/how-to-use-the-ampersand-symbol-in-sql-statements-as-a-literal-value\/","title":{"rendered":"How to use the ampersand (&#038;) symbol in SQL statements as a literal value"},"content":{"rendered":"<p>Because the ampersand symbol, &#8220;&#038;&#8221;, denotes the start of a variable, you might be caught off guard when you are trying to use it as a literal value.  For example:<\/p>\n<pre class=\"code\">\nSQL> select 'I like fish & chips' as x from dual;\n\nEnter value for chips: old   1: select 'I like fish & chips' as x from dual\nnew   1: select 'I like fish ' as x from dual\n\nX\n------------\nI like fish\n\n1 row selected.\n<\/pre>\n<p>Of course, this is not what what you intended; you meant for the literal string to appear as &#8220;I like fish &#038; chips&#8221;.  There are two ways for you to get around this problem.  The first method is to make sure the ampersand symbol is at the end of a string, thus requiring you to break up your sentence in one of the two following ways.<\/p>\n<pre class=\"code\">\nSQL> select 'I like fish &' || ' chips' as x from dual;\n\nX\n-------------------\nI like fish & chips\n\n1 row selected.\n\nSQL> select concat('I like fish &',' chips') as x from dual;\n\nX\n-------------------\nI like fish & chips\n\n1 row selected.\n<\/pre>\n<p>The second method is to escape the ampersand symbol in the following manner.<\/p>\n<pre class=\"code\">\nSQL> set escape on;\nSQL> select 'I like fish & chips' as x from dual;\n\nX\n-------------------\nI like fish & chips\n\n1 row selected.\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This note provides two ways for you to use the ampersand symbol, &#8220;&#038;&#8221;, as a literal value in an Oracle SQL statement.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-oracle"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}