0

I have to insert json data in database. Unable to add ambersand. I'm using below query.

insert into sample_table(column1, column2) values('Data1',
'{
   "Subject" : "Language",
   "List"    : {
   "Test Type"    : "Practical",
    "Mode"        : "Written & Oral",
   }  
 }'
); 

I have tried concat option, that is not working, Guide me to resolve this.

danielsepulvedab
  • 676
  • 1
  • 11
  • 22
Shailu
  • 163
  • 1
  • 5
  • 16
  • What RDBMS are you using? – danielsepulvedab Jul 26 '17 at 04:12
  • oracle @danielsepulvedab – Shailu Jul 26 '17 at 04:15
  • 1
    What client software are you using to run the sql? e.g. SQL*Plus will usually interpret `&` as the marker for a substitution string. – Jeffrey Kemp Jul 26 '17 at 05:46
  • "not working" isn't very helpful. What error do you get? – Alex Poole Jul 26 '17 at 07:18
  • @Alex Poole. I have used CONCAT() method. – Shailu Aug 09 '17 at 10:40
  • @Shailu - you haven't shown the actual code you're using (*how* are you using `concat()`?) or the error you get; you also haven't said which client you're using, which version of the client and database, or the column data type. If your problem isn't covered by the duplicate this is linked to, you have to explain - by [editing the question](https://stackoverflow.com/posts/45317236/edit) - what is happening in enough detail for us to help you. – Alex Poole Aug 09 '17 at 10:47
  • I have used below code: insert into sample_table(column1, column2) values('Data1', CONCAT('{ "Subject" : "Language", "List" : { "Test Type" : "Practical", "Mode" : "Written ' ,CONCAT('&' Oral", } }')) ); – Shailu Aug 09 '17 at 11:05
  • @Shailu - [**Edit the question**](https://stackoverflow.com/posts/45317236/edit). What about all the other points? Your second concat call is missing `,'"`, so just a typo perhaps. – Alex Poole Aug 09 '17 at 12:24

1 Answers1

0

If the ampersand is your problem, you can try something like:

insert into sample_table(column1, column2) values('Data1',
'{
   "Subject" : "Language",
   "List"    : {
   "Test Type"    : "Practical",
    "Mode"        : "Written ' || CHR(38) || ' Oral",
   }  
 }'
); 

That's the ASCII code for ampersand.

danielsepulvedab
  • 676
  • 1
  • 11
  • 22