当我使用HSQLDB 2.2.5运行以下脚本(q.sql
)时,results.csv
的内容将变为以下内容:
results.csv :
C1,C2
[null],e
a,b
q.sql:
DROP TABLE "PUBLIC"."TABLE1" IF EXISTS;
CREATE TABLE "PUBLIC"."TABLE1" (
"C1" VARCHAR(10),
"C2" VARCHAR(10),
"C3" VARCHAR(10)
);
INSERT INTO "PUBLIC"."TABLE1" ("C1", "C2", "C3") VALUES ('a', 'b', 'c');
INSERT INTO "PUBLIC"."TABLE1" ("C1", "C2", "C3") VALUES ('d', 'e', 'f');
DROP TABLE "PUBLIC"."TABLE2" IF EXISTS;
CREATE TABLE "PUBLIC"."TABLE2" (
"C1" VARCHAR(10),
"C2" VARCHAR(10),
);
INSERT INTO "PUBLIC"."TABLE2" ("C1", "C2") VALUES ('a', 'b');
INSERT INTO "PUBLIC"."TABLE2" ("C1", "C2") VALUES ('u', 'v');
DROP TABLE "PUBLIC"."TABLE3" IF EXISTS;
CREATE TABLE "PUBLIC"."TABLE3" (
"C1" VARCHAR(10),
"C2" VARCHAR(10)
);
INSERT INTO "PUBLIC"."TABLE3" (
"C1",
"C2"
)
SELECT
(SELECT
"T2"."C1" AS "T2C1"
FROM "PUBLIC"."TABLE2" "T2"
WHERE "T2"."C1" = "T1"."C1") AS "T2C1",
"T1"."C2" AS "T1C2"
FROM "PUBLIC"."TABLE1" "T1"
ORDER BY "T2C1", "T1C2";
* *DSV_COL_DELIM=,
* *DSV_ROW_DELIM=\n
* *DSV_TARGET_FILE=results.csv
\x "PUBLIC"."TABLE3"
如何更改我的脚本,使“[null]
”替换为“?”在生成的CSV文件中?
答案 0 :(得分:1)
取决于dbengine:
for hSQL ... 3个作品中的任何一个根据:hSQLDB.org
合并(MOST)
NVL(oracle)
IFNULL(MySQL的) 编辑添加(...(哎呀我忘了!)
SELECT
coalesce((SELECT
"T2"."C1" AS "T2C1"
FROM "PUBLIC"."TABLE2" "T2"
WHERE "T2"."C1" = "T1"."C1"),'?') AS "T2C1",
"T1"."C2" AS "T1C2"
FROM "PUBLIC"."TABLE1" "T1"
ORDER BY "T2C1", "T1C2";
答案 1 :(得分:0)