Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the problem of & # 039; single quotation marks in string when oracle inserts string data

Shulou Source: shulou.com Published: 2022-05-31 20:08:46 11月10日 Update

This article is about how to solve the problem of 'single quotation marks in strings when oracle inserts string data. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Use insert into (field1,field2...) Values ('val1','val2'...) An error is reported if there are single quotation marks in the value.

How to deal with it: determine whether the val1,val2 contains single quotation marks, and if so, replace the single quotation marks' with two single quotation marks'.

Organize fields and field values into a HashTable, and then abstract a function getSqlByHashTable () that organizes sql statements:

HashTable ht = new HashTable (); ht.add (field1,val1); ht.add (field2,val2); ht.add (field3,val3);. Public string getSqlByHashTable (string tablename,HashTable ht) {StringBuilder sb=new StringBuilder (); sb.append ("insert into" + tablename+ "("); StringBuilder fsb=new StringBuilder (); StringBuilder vsb=new StringBuilder (); foreach (var key in ht.Keys) {fsb.append (key+ ","); string value=ht [key]; if (value.trim ()) = ") {value=" } else {if (value.Contains ("'")) {value=value.replace ("'", "'");} value= "'" + value+ "'";} vsb.append (value+ ",");} sb.append (fsb.toString (). Substring (0Med fsb.toString (). Length-1)) Sb.append (") values ("); sb.append (vsb.toString (). Substring (0dsb.toString (). Length-1)); sb.append (")"); return sb.toString ();} Thank you for reading! This is the end of this article on "how to solve the problem of 'single quotation marks in the string when oracle inserts string data". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Quotation marks characters strings data questions content fields more articles good practical two functions articles methods see knowledge sentences will report reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Linux Huawei Shulou Tech Info