douliu7929
2012-03-29 19:09
浏览 40

如何在Oracle中插入PHP中的特殊字符?

I want to insert data with special character in oracle tables. My code is like this-:

$query1 ="INSERT INTO sample(po_number , created_at , customer_firstname , customer_lastname , customer_email , 
shipping_description , ship_to_firstname, ship_to_lastname, ship_to_company, ship_to_street, ship_to_city, ship_to_country_id, ship_to_postcode, ship_to_telephone, increment_id) VALUES(".$result_str_order.")"; 


where $result_str_order = '100','21-Mar-2011','Sam','Right','sam.right@sasmple.com','Flight','Samy',
'RTR','SR INC','222,M.G.Bank's-Pipeline/Rd','Newyork','US','411230','999856230','20000507'

Now, in case of ship_to_street, I need to insert 222,M.G.Bank's-Pipeline/Rd but it contains special character like ,',-,/ etc.so how to insert special characters in oracle db?

图片转代码服务由CSDN问答提供 功能建议

我想在oracle表中插入具有特殊字符的数据。 我的代码是这样的 - :

  $ query1 =“INSERT INTO sample(po_number,created_at,customer_firstname,customer_lastname,customer_email,
shipping_description,ship_to_firstname,ship_to_lastname,ship_to_company,ship_to_street  ,ship_to_city,ship_to_country_id,ship_to_postcode,ship_to_telephone,increment_id)VALUES(“。$ result_str_order。”)“;  
 
 
其中$ result_str_order ='100','21-Mar-2011','Sam','Right','sam.right @sasmple.com','Flight','Samy',
'  RTR','SR INC','222,MGBank's-Pipeline / Rd','Newyork','US','411230','999856230','20000507'
   
  
 

现在,如果是ship_to_street,我需要插入 222,MGBank's-Pipeline / Rd 但它包含特殊字符,如', - ,/ etcso 如何在oracle db中插入特殊字符?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dougu4027 2012-03-29 19:13
    已采纳

    The only character you need to escape is ' (because you're using single quotes as string delimiters). So that's:

    $query1 ="INSERT INTO sample(po_number , created_at , customer_firstname , customer_lastname , customer_email , 
    shipping_description , ship_to_firstname, ship_to_lastname, ship_to_company, ship_to_street, ship_to_city, ship_to_country_id, ship_to_postcode, ship_to_telephone, increment_id) VALUES(".$result_str_order.")"; 
    
    
    where $result_str_order = '100','21-Mar-2011','Sam','Right','sam.right@sasmple.com','Flight','Samy',
    'RTR','SR INC','222,M.G.Bank\'s-Pipeline/Rd','Newyork','US','411230','999856230','20000507'
    
    已采纳该答案
    打赏 评论
  • dsi37923 2012-03-29 19:12

    Use a Replace method (on your variables, not the entire query) to duplicate single quotes.

    打赏 评论
  • dtja73027 2015-12-23 12:45

    You can use quoted string like q'[$visitComment]' where $visitComment is a variable that contains a special character string.

    Or you can bind externally INSERT INTO sample(column) values (:columnval); oci_bind_by_name($result, ':columnval',$string);

    Where $result is $result = oci_parse($conn, $query);

    Note:- This will work only for variable containing string.

    打赏 评论

相关推荐 更多相似问题