在PL/SQL中導入100萬條數據可以使用以下方法:
DECLARE
i NUMBER := 1;
BEGIN
WHILE i <= 1000000 LOOP
INSERT INTO your_table (column1, column2, ...) VALUES (value1, value2, ...);
i := i + 1;
END LOOP;
END;
/
DECLARE
TYPE your_table_type IS TABLE OF your_table%ROWTYPE;
your_table_data your_table_type;
BEGIN
-- 構建數據
FOR i IN 1..1000000 LOOP
your_table_data(i).column1 := value1;
your_table_data(i).column2 := value2;
-- ...
END LOOP;
-- 插入數據
FORALL i IN 1..your_table_data.COUNT
INSERT INTO your_table VALUES your_table_data(i);
END;
/
首先,創建外部表的定義并指定數據文件的路徑和格式:
CREATE TABLE your_external_table (
column1 datatype,
column2 datatype,
...
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY your_directory
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
BADFILE your_directory:'your_table.bad'
LOGFILE your_directory:'your_table.log'
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
column1,
column2,
...
)
)
LOCATION ('your_file.csv')
);
然后,將外部表中的數據插入到目標表中:
INSERT INTO your_table (column1, column2, ...)
SELECT column1, column2, ...
FROM your_external_table;
以上是一些導入大量數據的方法,具體選擇哪種方法取決于數據的來源和格式以及性能要求。