DEPTID IN (:1) (Where :1 = '2000980', '2510901', '9120980', '7280980', '1510980', '1280980', '1200980', '1150980', '7120980')
The SQL did not return any values, nor did it error. I had a SQL trace set and it looked correct, but I assumed the bind functionality was appending quotes to my string literal. So I attempted to remove the first and last quotes on my string of departments and passed it to the SQL object.
DEPTID IN (:1) (Where :1 = 2000980', '2510901', '9120980', '7280980', '1510980', '1280980', '1200980', '1150980', '7120980)
Once again I was meet with futility. I asked our DBA if she could capture the SQL in the database, so I could see what was happening, but like many places a DBA time is a precious commodity. So I was left to my own devices. That is when I found this blog, on how to split a comma separated string and pass to IN clause of select statement. Armed with this information I created a new SQL object and named it SQL.ZZ_LIST, that looked like this:
select regexp_substr(:1,'[^, ]+', 1, level) from dual
connect by regexp_substr(:1, '[^, ]+', 1, level) is not null;
Please note that I had to modify the original regular expression from the blog from '[^,]'+ to '[^, ]+' to account for the space that is in my list of managed departments. Then I was able to modify my SQL object with the department IN list clause and passed it the string literal without adding any quotes around the value: Like this below:
DEPTID IN(%SQL(SQL.ZZ_LIST,:1)) (Where :1 = 2000980, 2510901, 9120980, 7280980, 1510980, 1280980, 1200980, 1150980, 7120980)
And this worked brilliantly!
If you know a way to do this in other databases please leave a comment.
Thank you, very useful.
ReplyDeleteI had the same problem with quotes in an sql statement
Thank you, I was just looking for this.
ReplyDelete