如何在REST API的URL中传递列表? [英] How do I pass a list in url for a REST api?
问题描述
我正在尝试将ID列表传递给REST api(apex ords).
I am trying to pass a list of IDs to a REST api (apex ords).
我有一个类似这样的网址:
I have a url like this :
https://apex.oracle.com/***/apex/anime_keeper/ak/getAnimeList/:ids
当我这样做时:
https://apex.oracle.com/***/apex/anime_keeper/ak/getAnimeList/1
我得到id为1的商品,但如果这样做:
I get the item with id = 1 but if I do :
https://apex.oracle.com/***/apex/anime_keeper/ak/getAnimeList/1,2,3
我收到500个内部服务器错误
I get a 500 Internal Server Error
我应该如何设置URL格式,以便可以在where id in (ids)
中使用aps ords中的1,2,3列表?
How should I format my url so I can use the 1,2,3 list in a where id in (ids)
in apex ords?
如果可以的话,这是ords的屏幕截图:
this is a screenshot of ords if it can help :
推荐答案
如果ORDS无法将csv值分开,则该SQL将无法正常工作.这样sql原样将检查id in ( '1,2,3')
而不是id in ( 1,2,3)
That SQL won't work becase ORDS does not split the csv values out. So that sql as-is will be checking for id in ( '1,2,3')
not id in ( 1,2,3)
有多种方法可以实现意图.
There's multiple ways to accomplish what the intent is.
例如,使用XMLTABLE
For example, using XMLTABLE
SELECT rownum,object_id
FROM user_objects
WHERE rownum IN (
select (column_value).getstringval() csv_values
FROM
xmltable(('"' || REPLACE(:ids, ',', '","')|| '"'))
)
这里还提到了其他方法: 使用"IN"表示Oracle SQL中replace()函数的输出中带有逗号分隔的字符串的子句
There are other ways mentioned here: Using the "IN" clause with a comma delimited string from the output of a replace() function in Oracle SQL
这里的ORDS REST API完全可以实现您的预期.
Here's an ORDS REST API doing exactly what you intend.
这篇关于如何在REST API的URL中传递列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!