# How can I embed quotes within an SQL statment whilst using apoc.periodic.iterate

**URL:** <https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135>\
**Category:** Procedures & APOC\
**Tags:** jdbc, apocperiodiciterate\
**Created:** [October 18, 2019, 11:41am UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135 "2019-10-18T11:41:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew.swanton](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew.swanton/32/4113_2.png) [@andrew.swanton](https://community.neo4j.com/u/andrew.swanton)\
**Post date:** [October 18, 2019, 11:41am UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135/1 "2019-10-18T11:41:10Z")

</div>

Hi,

I have a very large data set I want to into neo4j from a database. However the SQL statement needed to select the data requires the use of single quotes which is causing the load to fail.

I know i could just create a view in the database which includes all my logic, then simply `select * from myView`. But I wonder if there is an alternative way.

```auto
CALL apoc.periodic.iterate("
CALL apoc.load.jdbc('jdbc:oracle:thin:@database:port/service_name',
 'select * 
  from MyTable
 where id <> ' ' //the quotes here are causing the error
 ',
 [],
 {credentials:{user: 'user', password: 'pasword'}}) YIELD row RETURN row
"
,"
CREATE (:entity {id: row.id}
		)
", {batchSize:10000, iterateList:true, parallel:true});

```

error

`Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure `apoc.periodic.iterate`: Caused by: org.neo4j.cypher.internal.v3_5.util.SyntaxException: Invalid input ''': expected whitespace, comment, '.', node labels, '[', "=~", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 5, column 16 (offset: 134))`

I have tried escaping the quotes but this didn't work either

```auto
CALL apoc.periodic.iterate("
CALL apoc.load.jdbc('jdbc:oracle:thin:@database:port/service_name',
 'select * 
  from MyTable
 where id <> \' \' //the quotes here are causing the error
 ',
 [],
 {credentials:{user: 'user', password: 'pasword'}}) YIELD row RETURN row
"
,"
CREATE (:entity {id: row.id}
		)
", {batchSize:10000, iterateList:true, parallel:true});

```

---

<div class="post-metadata">

**Author:** ![nsmith\_piano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nsmith_piano/32/6037_2.png) [@nsmith\_piano](https://community.neo4j.com/u/nsmith_piano)\
**Post date:** [October 18, 2019, 8:10pm UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135/2 "2019-10-18T20:10:43Z")

</div>

Does this work?

```auto
where id <> chr(32)

```

It wouldn't help with other queries, but it might work for your case.

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [October 18, 2019, 10:40pm UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135/3 "2019-10-18T22:40:44Z")

</div>

I hate dealing with nested quoting issues myself. If at all possible, try to create the string earlier, and pass the variable in instead. Something like this:

```auto
WITH 'select * 
  from MyTable
 where id <> " "  
 ' as query
CALL apoc.periodic.iterate("
CALL apoc.load.jdbc('jdbc:oracle:thin:@database:port/service_name',
 query,
 [],
 {credentials:{user: 'user', password: 'pasword'}}) YIELD row RETURN row
"
,"
CREATE (:entity {id: row.id}
		)
", {batchSize:10000, iterateList:true, parallel:true, params:{query:query} });

```

Though if you're going to do this, you may as well parameterize it and pass it in instead of defining it in a WITH clause.

---

<div class="post-metadata">

**Author:** ![andrew.swanton](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew.swanton/32/4113_2.png) [@andrew.swanton](https://community.neo4j.com/u/andrew.swanton)\
**Post date:** [October 21, 2019, 8:53am UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135/4 "2019-10-21T08:53:43Z")

</div>

Yes this does work.

However if I wanted to do where id = 'ABC' I would have to do some like `where id = cha(65) || chr(66) || chr(67)` which quickly become unreadable, and hard to maintain.

I should have made my initial problem a little more complex

---

<div class="post-metadata">

**Author:** ![andrew.swanton](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew.swanton/32/4113_2.png) [@andrew.swanton](https://community.neo4j.com/u/andrew.swanton)\
**Post date:** [October 21, 2019, 8:59am UTC](https://community.neo4j.com/t/how-can-i-embed-quotes-within-an-sql-statment-whilst-using-apoc-periodic-iterate/11135/5 "2019-10-21T08:59:02Z")

</div>

Thank for this.

I'm new to neo4j and this would have taken ages to figure out. I'll have a go at parameterizing this myself
