問題描述
我有一個包含 20000 個 ID 的 xls
I have a xls with 20000 IDs
我需要在 Col1 中提取具有這些 ID 的表的行
I need to extract the rows of a table that have these IDs in Col1
在 Oracle SQL 中是否有一種聰明的方法可以做到這一點?
Is there a clever way to do this in Oracle SQL ?
我對該數據庫只有讀權限.
I only have a read access to this db.
我想對 20000 個 ID 進行切片,以便將前 1000 個放在變量 p_list1 中,將下一個 1000 個放在變量 p_list2 中,等等,然后使用 IN 子句和聯合來獲得整個結果
I thought to slice the 20000 IDs, in order to put the first 1000 in a variable p_list1 , the next 1000 in a variable p_list2, ect and use a IN clause and union to get the whole result
但我不習慣在查詢中使用參數.
But I'm not used to use paramters in my query.
你能看一下嗎?
預先感謝您的幫助
DECLARE
p_list1 VARCHAR2(10) := '''id1''','''id2''','''id3''',..ect
BEGIN
execute immediate 'select * from table1 where Col1 in ('|| p_list ||')' ;
END;
推薦答案
如果可以創建臨時表,可以這樣進行:
If you can create a temporary table, you can proceed in this way:
- 創建臨時表
- 使用 EXISTS 子句重新編寫查詢,如下所示:
SELECT *
FROM table1
WHERE EXISTS(select 1 from temp_table tt WHERE tt.id = table1.Col1)
這篇關于具有 20000 個值的 SQL 子句的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!