Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report