Oracle's in function does not accept string parameters (error: invalid number)

Recently encountered a weird problem,

I need to pass parameters to the database stored procedure in the foreground.

The data in the parameter is passed in like this 1355000004, 1355000005, 1355000005.

Finally, when the parameter is put into the stored procedure, an error of "invalid number" will be reported.

However, if you take out the SQL statement separately and bring in the value in the parameter, you can successfully query the desired result.

At first I thought that the format of the value passed in was incorrect.

I made it into an array and passed it in,

Shape like: '1355000004','1355000005','1355000005'

Found that it still didn't work, and reported the same error.

Finally, I asked the seniors before I knew the reason.

Because Oracle does not have an array, only a result set.
The in function only accepts a single-column result set.

Finally, I used this code to deal with it

(select regexp_substr('aaa,bbb,ccc','[^,]+', 1, level) as id_arr from dual connect by level <= length('aaa,bbb,ccc')-length(regexp_replace('aaa,bbb,ccc', ','))+1)

The above code is to convert the comma-separated string into a single-column result set.

In this way, the in function can be used.

Guess you like

Origin blog.csdn.net/qq_39331713/article/details/103079860