Reputation: 519
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','[email protected]','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?
Upvotes: 1
Views: 2543
Reputation: 71
I also have the same issue. I want to select this ■×× special character as a condition.
SELECT *
FROM tablename
WHERE table = '■××'
I used PHP MMSQL with oracle dB. To solved this, I used hex conversion RAWTOHEX
SELECT *
FROM tablename
WHERE RAWTOHEX(table) = '81A1817E817E' --this is the hex for symbol above
Upvotes: 1
Reputation: 183
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.
Upvotes: 0
Reputation: 174957
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','[email protected]','Flight','Samy',
'RTR','SR INC','222,M.G.Bank\'s-Pipeline/Rd','Newyork','US','411230','999856230','20000507'
Upvotes: 1
Reputation: 13655
Use a Replace method (on your variables, not the entire query) to duplicate single quotes.
Upvotes: 1