2

有没有可能,如果有的话,我SELECT ... INTO OUTFILE可以让它不包含任何字符。

到目前为止,这不起作用:

  SELECT hour_stamp,
         day_stamp,
         month_stamp,
         hour,
         day,
         month,
         year,
         quarter,
         day_of_week,
         week_of_year,
         SUBSTR(hour_text,1,24),
         SUBSTR(day_text,1,24)
    FROM date_dim
  INTO OUTFILE '/media/ssd0/temp/dates.tsv' 
  FIELDS TERMINATED BY '\t'
  ENCLOSED BY '';

我不确定引擎在这种情况下是否重要,但请注意我在 Linux 机器上使用 InfoBright 可能很重要。

输出如下:

1293840000000   1293840000000   1293840000000   0   1   1   2011    1   5   52  "2011-01-01T00:00:00"   "2011-01-01T00:00:00"
1293843600000   1293840000000   1293840000000   1   1   1   2011    1   5   52  "2011-01-01T01:00:00"   "2011-01-01T00:00:00"
1293847200000   1293840000000   1293840000000   2   1   1   2011    1   5   52  "2011-01-01T02:00:00"   "2011-01-01T00:00:00"
1293850800000   1293840000000   1293840000000   3   1   1   2011    1   5   52  "2011-01-01T03:00:00"   "2011-01-01T00:00:00"
4

3 回答 3

0

添加OPTIONALLY ENCLOSED BY ''可能会产生预期的效果。

于 2013-01-04T22:23:12.700 回答
0

试一试:

  SELECT hour_stamp,
         day_stamp,
         month_stamp,
         hour,
         day,
         month,
         year,
         quarter,
         day_of_week,
         week_of_year,
         SUBSTR(hour_text,1,24),
         SUBSTR(day_text,1,24)
    FROM date_dim
  INTO OUTFILE '/media/ssd0/temp/dates.tsv';

这是一个示例

mysql> desc veto.prova;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| provaemail | varchar(255) | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
2 rows in set (0.05 sec)

mysql> select * from veto.prova;
+----+--------------------------+
| id | provaemail               |
+----+--------------------------+
|  1 | redwards@logicworks.net  |
|  2 | rolandoedwards@yahoo.com |
+----+--------------------------+
2 rows in set (0.00 sec)

mysql> select id,provaemail from prova into outfile 'C:/lwdba/prova.txt';
Query OK, 2 rows affected (0.01 sec)

mysql>

它在磁盘上是什么样的???

C:\>cd lwdba

C:\LWDBA>type prova.txt
1       redwards@logicworks.net
2       rolandoedwards@yahoo.com

C:\LWDBA>

我尝试了一些奇怪的东西。我终止了\0

mysql> select id,provaemail,substr(provaemail,1,5) from prova into outfile 'C:/lwdba/prova9.txt' fields terminated by '\0';
Query OK, 2 rows affected, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Warning | 1475 | First character of the FIELDS TERMINATED string is ambiguous; please use non-optional and non-empty FIELDS ENCLOSED BY |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select id,provaemail,substr(provaemail,1,5) from prova into outfile 'C:/lwdba/prova8.txt' fields enclosed by '\0';
Query OK, 2 rows affected (0.00 sec)

mysql>

文件如下所示:

C:\LWDBA>type prova9.txt
1 redwards@logicworks.net redwa
2 rolandoedwards@yahoo.com rolan

C:\LWDBA>type prova8.txt
 1       redwards@logicworks.net         redwa
 2       rolandoedwards@yahoo.com        rolan

C:\LWDBA>

我使用\0它是因为它是一个空字符。

您看到的双引号异常可能是由于 InfoBright 存储引擎以及它如何呈现函数调用的字符输出。

这是一个奇怪的建议,但我不知道它是否会起作用......

如果您进行子查询,则数据始终存储在 MySQL 临时表中。更改查询:

mysql> select * from (select id,provaemail,substr(provaemail,1,5) as stuff from prova) A
-> A into outfile 'C:/lwdba/prova444.txt' fields terminated by '\0' enclosed by '\0';
Query OK, 2 rows affected (0.00 sec)

mysql>

在你的情况下,那将是

SELECT * FROM (
  SELECT hour_stamp,
         day_stamp,
         month_stamp,
         hour,
         day,
         month,
         year,
         quarter,
         day_of_week,
         week_of_year,
         SUBSTR(hour_text,1,24) ht,
         SUBSTR(day_text,1,24) dt
    FROM date_dim) A
  INTO OUTFILE '/media/ssd0/temp/dates.tsv';

看看这是否有不同的作用

于 2013-01-04T22:24:05.870 回答
0

你试过“空”吗?

SELECT hour_stamp,
     day_stamp,
     month_stamp,
     hour,
     day,
     month,
     year,
     quarter,
     day_of_week,
     week_of_year,
     SUBSTR(hour_text,1,24),
     SUBSTR(day_text,1,24)
FROM date_dim
INTO OUTFILE '/media/ssd0/temp/dates.tsv' 
FIELDS TERMINATED BY '\t'
ENCLOSED BY 'NULL';
于 2014-11-12T18:05:16.527 回答