简体   繁体   中英

Inserting string with special characters into a column

How can I successfully run such a query in SqlDeveloper?

execute immediate q'#
                    insert into results(SrcProcedure) 
                                values('d/&'s*73;.f45')
                    #';

You need to learn the escaping rules for your language. In SQL, ' is a special character. The escape for it is '' :

execute immediate q'#
                insert into results(SrcProcedure) 
                            values(''d/&''''s*73;.f45'')
                #';

Rule: For each level of nesting, you need to duplicate all single quotes.

d/&'s*73;.f45
'd/&''s*73;.f45'
...values(''d/&''''s*73;.f45'')...

You can get away with less quotes if you use q'{...}' :

execute immediate q'{
                insert into results(SrcProcedure) 
                            values('d/&''s*73;.f45')
                }';

Related:

The problem is that you are trying to insert the value d/&'s*73;.f45 and the ' character is interpreted as the end of the value.

You need to escape the ' character:

execute immediate q'#
                insert into results(SrcProcedure) 
                            values('d/&''s*73;.f45')
                #';

Or you can nest the alternative quoting mechanism to avoid any string escaping:

execute immediate q'#
                insert into results(SrcProcedure) 
                            values(q'!d/&'s*73;.f45!')
                #';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM