[英]Read and insert data from .txt file to Oracle SQL DB [PL/SQL, Unix Scripting]
i have an input file: $home/dir/subdir/input.txt
我有一个输入文件:
$home/dir/subdir/input.txt
content of input.txt: input.txt 的内容:
123,0000,11111,3,1,X
124,0001,11112,3,1,Y
125,0002,,4,2,Y
129,0003,11114,4,2,X
I have a table where col1, col2, col3 cannot be null:我有一张表,其中 col1、col2、col3 不能是 null:
col1 ![]() |
col2 ![]() |
col3 ![]() |
col4 ![]() |
col5 ![]() |
col6 ![]() |
col7 ![]() |
col8 ![]() |
col9 ![]() |
---|---|---|---|---|---|---|---|---|
123 ![]() |
0000 ![]() |
11111 ![]() |
3 ![]() |
1 ![]() |
X ![]() |
|||
124 ![]() |
0001 ![]() |
11112 ![]() |
3 ![]() |
1 ![]() |
Y![]() |
|||
129 ![]() |
0003 ![]() |
11114 ![]() |
4 ![]() |
2 ![]() |
X ![]() |
How do I insert the contents of input.txt
to the table accordingly?如何将
input.txt
的内容相应地插入到表中? using pl/sql and unix scripting使用 pl/sql 和 unix 脚本
You can use the regexp_substr
function.您可以使用
regexp_substr
function。
In the following example, I used the regexp_like
function to confirm it was in the given format.在下面的示例中,我使用了
regexp_like
function 来确认它是给定的格式。 Adjust it as you like.随心所欲地调整它。
Example:例子:
SELECT regexp_substr(string, '[^,]+', 1, 1) as col2,
regexp_substr(string, '[^,]+', 1, 2) as col3,
regexp_substr(string, '[^,]+', 1, 3) as col4,
regexp_substr(string, '[^,]+', 1, 4) as col7,
regexp_substr(string, '[^,]+', 1, 5) as col8,
regexp_substr(string, '[^,]+', 1, 6) as col9,
FROM table
WHERE REGEXP_LIKE(string, '[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[A-Za-z]+');
Result:结果:
COL1 ![]() |
COL2 ![]() |
COL3 ![]() |
COL4 ![]() |
COL5 ![]() |
COL6 ![]() |
COL7 ![]() |
COL8 ![]() |
COL9 ![]() |
---|---|---|---|---|---|---|---|---|
- ![]() |
123 ![]() |
0000 ![]() |
11111 ![]() |
- ![]() |
- ![]() |
3 ![]() |
1 ![]() |
X ![]() |
- ![]() |
129 ![]() |
0003 ![]() |
11114 ![]() |
- ![]() |
- ![]() |
4 ![]() |
2 ![]() |
X ![]() |
- ![]() |
124 ![]() |
0001 ![]() |
11112 ![]() |
- ![]() |
- ![]() |
3 ![]() |
1 ![]() |
Y![]() |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.