Single quotation mark nesting in SQL statements (direct nesting must be avoided) and SQL nesting

Source: Internet
Author: User

Single quotation mark nesting in SQL statements (direct nesting must be avoided) and SQL nesting

In SQL statements, we will inevitably use single quotes for nesting, but direct Nesting is definitely not acceptable. In java, it is also impossible to use backslashes for escape characters, in SQL, single quotes are used as escape characters.

For example, the following example shows the statement examples in the Stored Procedure query.

Exec cndoup_getpageofrecords @ pagesize = 10, @ currentpage = 1, @ columns = '*', @ tablename = 'room ', @ condition = 'roomtypelike' % standard ROOM % '', @ asccolumn = 'roomid', @ bitordertype = 1, @ pkcolumn = 'roomid'

The red part reports an error. It should be written as @ condition = 'roomtypelike ''% standard room % '''. The blue part is not double quotation marks, but two single quotation marks.


Nested quotation marks in javascript

When splicing a JS string, the double quotation marks must be single quotation marks, and the single quotation marks must be double quotation marks. This loop! However, all double quotation marks are acceptable, that is, the double quotation marks in the double quotation marks must be escaped!

SQL statement string nesting

-- Use two quotation marks
1. exec sp_test 'where loginname = ''jay '''
2. create proc sp_test
(
@ Condition varchar (200)
)
As
Declare @ SQL varchar (2000)
Set @ SQL = 'select * from userinfo'
Set @ SQL = @ SQL + @ condition
Exec (@ SQL)

Wish helpful

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.