DB2 Load from delimitited Files - escape " in Fields doesn't work

自闭症网瘾萝莉.ら 提交于 2019-12-13 04:56:54

问题


I bet it's totaly simple and i just don't see it, but i don't get it ..

I execute the following command in DB2 command line processor:

DB2 LOAD FROM "DB_ACC_PASS_REGEXP.del" OF DEL METHOD P (1, 2, 3, 4, 5) MESSAGES "DB_ACC_PASS_REGEXP.del.msg" INSERT INTO DB_ACC_PASS_REGEXP (APP_ID,APREGEXP,EXPLAIN_TEXT,ID,OPT_KZ) NONRECOVERABLE INDEXING MODE REBUILD

Which loads the Data specified in following File into the database.

1,"[a-z]",,1,0

1,"[A-Z]",,2,0

1,"[0-9]",,3,0

1,"[!|\"|§|$|%|&|/|(|)|=|?|`|´|*|+|~|'|#|-|_|.|:|,|;|µ|<|>| |°|^]",,4,0

   ^

Here is the Problem

The Problem is, that only 3 of these 4 inserts will be accepted. The last one will be rejected, because DB2 Load doesn't notice the escape character before the double quotation mark.

if I change the last line to:

1,"[!|x|§|$|%|&|/|(|)|=|?|`|´|*|+|~|'|#|-|_|.|:|,|;|µ|<|>| |°|^]",,4,0

   ^

Here is the changed character

there is no problem ..

WHY doesn't the escape character "\" work??

edit Okay.. I just tryed it the oracle way now and that works ... I escape " with another " so my Line looks like

1,"[!|""|§|$|%|&|/|(|)|=|?|`|´|*|+|~|'|#|-|_|.|:|,|;|µ|<|>| |°|^]",,4,0

But that's only a way to do it .. That doesn't explain why IBM offers the Backslash as an escape character (http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.cmd.doc%2Fdoc%2Fr0008305.html)


回答1:


Using LOAD with ascii / delimited files requires to tune the file type modifiers (look on Table 6 and Table 8 of the docu page you linked). I am not quite sure, but I can't remember using backslash as escape character in DB2.

You can either use another character delimiter as double quotes with chardel option or force no character delimiter with nochardel option.

BUT ...

In your case you need special characters as regular expressions, so you will always need to escape " with "" and ' with ''. I think there is no other way to get this working.



来源:https://stackoverflow.com/questions/21984132/db2-load-from-delimitited-files-escape-in-fields-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!