oracle导出特殊字符,如何从包含特殊字符的oracledb导出varchar2并从bash处理它(how to export a varchar2 from oracledb containing...

如何从包含特殊字符的oracledb导出varchar2并从bash处理它(how to export a varchar2 from oracledb containing special characters and process it from bash)

我想从oracledb导出数据,然后使用bash脚本进行处理。 但是输出可能包含特殊字符(如换行符等),这使得处理普通文件变得很困难。 所以我试着用相应的字符串对64进行编码

UTL_ENCODE.base64_encode(utl_raw.cast_to_raw(...))

然后输出文件将包含如下行:

SOME_TEXT | base64_encoded_string

这使我很容易处理文本文件,但解码过程不能很好地输出是胡言乱语:

while read line

do

name=${line%|*}

str64=${line#*|}

str_dec=`echo ${str64} | base64 --decode`

echo "${name} : ${str_dec}"

done

这可能是因为字符串在oracle中首次被转换为raw。

那我怎样才能正确解码字符串?

或者,我如何编码(保护)可以轻松解码的字符串,这也有帮助?

顺便说一句:bash在cygwin中运行。

I want to export data from an oracledb and then process with a bash script. However the output may contain special characters (like new-line, etc) which makes it hard to process the plain file. So I have tried to base64 encode the relevant strings with

UTL_ENCODE.base64_encode(utl_raw.cast_to_raw(...))

The output file will then contain lines like :

some_text|base64_encoded_string

which gives me easy to process text files however the decoding process doesn't work very well output is gibberish:

while read line

do

name=${line%|*}

str64=${line#*|}

str_dec=`echo ${str64} | base64 --decode`

echo "${name} : ${str_dec}"

done

That's probably because the string was first cast to raw in oracle.

So how can I correctly decode the string ?

Alternatively, how can I encode (protect) the string that can be easily decoded, that would help as well ?

btw.: bash is running in cygwin.

原文:https://stackoverflow.com/questions/29273820

更新时间:2019-12-27 02:52

最满意答案

实际上它很简单......我只需要将结果转换回varchar2

replace(

replace(

utl_raw.cast_to_varchar2(

UTL_ENCODE.base64_encode(utl_raw.cast_to_raw(...))

), chr(10), ''

), chr(13), ''

)

它解码得很好,不得不从结果中删除cr / lf换行符。

Actually it was pretty simple... I just had to cast the result back to a varchar2

replace(

replace(

utl_raw.cast_to_varchar2(

UTL_ENCODE.base64_encode(utl_raw.cast_to_raw(...))

), chr(10), ''

), chr(13), ''

)

and it decoded fine, had to remove cr/lf line breaks from the result aswell.

2015-03-27

相关问答

最新的ODP.NET文档 - 从2012年9月开始的“11.2版本5生产(11.2.0.3.0)” - 在“实体框架相关提示,限制和已知问题”部分中说明了以下已知问题,该部分解决了以下错误:问题代码块中的“if”语句: 如果在LINQ / ESQL查询的WHERE子句中绑定了2,000个或更多字符的字符串,或者长度为4,000个字节或更长的字节数组,则会遇到“ORA-00932:不一致的数据类型”错误。 如果在LINQ / ESQL查询的WHERE子句中使用映射到BLOB,CLOB,NCLOB,L

...

我通过在更新步骤之前创建KEY_LEN为LEN(键)的派生列来解决问题。 然后我在更新中使用它作为第三个参数: UPDATE Table SET column1 = ? where KEY = SUBSTR(?,0,?)

I've resolved the problem by creating the derived column with KEY_LEN as LEN(key) before the update step. Then I've used it in update as th

...

实际上它很简单......我只需要将结果转换回varchar2 replace(

replace(

utl_raw.cast_to_varchar2(

UTL_ENCODE.base64_encode(utl_raw.cast_to_raw(...))

), chr(10), ''

), chr(13), ''

)

它解码得很好,不得不从结果中删除cr / lf换行符。 Actually it was pretty simple... I just had to cast th

...

我相信dbms_xmlgen的问题是技术上只有五个XML实体。 你的例子有一个数字HTML实体,它对应于Unicode: http://theorem.ca/~mvcorks/cgi-bin/unicode.pl.cgi?start=0100&end=017F Oracle有一个UNISTR函数,在这里很有帮助: select unistr('sloven\010dina') from dual;

我已经在上面的例子010d 269转换为它的十六进制等价的010d (在Unicode中是U+01

...

在Oracle 12.1之前,VARCHAR2列仅限于在数据库字符集中存储4000字节的数据,即使它被声明为VARCHAR2(4000 CHAR)。 由于字符串中的每个字符都需要UTF-8字符集中的2个字节的存储空间,因此您无法在列中存储超过2000个字符。 当然,如果你的一些字符实际上只需要1个字节的存储空间,或者其中一些字符需要超过2个字节的存储空间,那么这个数字就会改变。 另见这个答案 。 Prior to Oracle 12.1, a VARCHAR2 column is limited

...

你的maven条目看起来很奇怪。 您正在尝试使用oracle 12c增强功能但仍然使用来自oracle 10 10.3.6.0 jar。 此外,如果您的jdk高于jdk6,您可能必须使用ojdbc7 Your maven entry looks strange. You are trying to utilize oracle 12c enhancement but still, you are using jar from oracle 10

...

由于table1.value列已编制索引,因此您不希望将其用于比较,因为这会阻止使用索引。 所以你需要修改你正在查找的值: SELECT table1.ID FROM table1 WHERE table1.VALUE = RPAD('123-45', 12)

Oracle将使用您显示的查询隐式执行此操作,并仍将使用索引。 如果您正在加入表格,那么相同,但是在连接期间是否填充或修剪取决于驱动程序是哪个表: SELECT table1.ID, table2.ID

FROM table1

JOIN

...

限制为每行32K,它包括为每行交互式报告生成的列值和HTML文本。 尝试删除链接或自定义HTML(如果有)。 Limit is 32K per row and it includes column values and HTML text that gets generated for each row of interactive report. Try removing links or custom HTML, if any.

您需要在表中使用CHECK constraint 。 以下应该足够CHECK (regexp_like(surname,'^[[:alpha:]]+$')) 。 其中[[:alpha:]]是字母字符类。 因此,只考虑字母表。 让我们看一个测试用例 - SQL> CREATE TABLE TEST(

2 surname VARCHAR2(10),

3 CONSTRAINT constraint_name CHECK (regexp_like(surname,'^[[:alpha:]]+$

...

通常,我对所有字符串变量或常量声明使用VARCHAR2而不是CHAR,原因很简单,因为VARCHAR2语义更符合我的期望。 这里的问题是,如果开发人员对常量长度的计数不准确,如果声明为CHAR,它将在空白处用空格填充,而如果声明为VARCHAR2,它将被简单地存储而不用填充。 考虑: DECLARE

strFixed CHAR(20) := 'This is a string';

strVariable VARCHAR2(20) := 'This is a string';

BEGI

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值