我想以执行普通选择的类似方式导出表。我的意思是:
db2 -x "select varchar(SCHEMANAME, 16) SCHEMANAME,
varchar(OWNER, 10) OWNER,
varchar(OWNERTYPE, 10) OWNERTYPE
from syscat.schemata where SCHEMANAME like 'SYS%'"
输出为:
SYSCAT SYSIBM S
SYSFUN SYSIBM S
SYSIBM SYSIBM S
SYSIBMADM SYSIBM S
SYSIBMINTERNAL SYSIBM S
SYSIBMTS SYSIBM S
SYSPROC SYSIBM S
SYSPUBLIC SYSIBM S
SYSSTAT SYSIBM S
SYSTOOLS SYSIBM S
我想通过导出(定长列)生成相同的内容。我尝试过:
db2 "export to myfile.csv of del
modified by coldelX20
SELECT *
from syscat.schemata"
db2 "export to myfile.csv of del
modified by nochardel coldelX20
SELECT *
from syscat.schemata"
db2 "export to myfile.csv of del
modified by chardelX21 coldelX20
SELECT *
from syscat.schemata"
然后我得到了
SQL3017N A delimiter is not valid or is used more than once.
(不能重定向普通选择的输出)。
答案 0 :(得分:0)
Delimiter considerations for moving data:
分隔符限制
有许多限制措施可以防止 选择的定界符,将其视为数据的一部分 被感动。首先,定界符是互斥的。其次, a 定界符不能为二进制零,换行符, 回车或空格。同样,默认小数点 (。)不能是字符串定界符。最后,在DBCS环境中, 不支持竖线(|)字符定界符。
Db2 export
命令不支持使用空格作为定界符。此外,它不能用空格将值填充到最大列长度(以字符为单位)。
您可以自己构造一个列表达式,如下所示:
select
char(schemaname, 20)
-- ...
|| ' ' || char(create_time)
--- ...
|| ' ' || char(coalesce(char(auditpolicyid), '-'), 11)
-- ...
from syscat.schemata;
答案 1 :(得分:0)
尝试一下
export to myfile.csv of del
modified by nochardel
select rpad(left(SCHEMANAME,16) , 16 ) ||
rpad(left(OWNER,10), 10 ) ||
rpad(left(OWNERTYPE,10), 10)
from syscat.schemata