如果我通过TADOCommand.execute发送此SQL语句:
WITH tab_temp
AS (SELECT 1 AS id, 'trl' AS cd_used FROM DUAL
UNION ALL
SELECT 1 AS id, 'upf' AS cd_used FROM DUAL
UNION ALL
SELECT 2 AS id, 'upf' AS cd_used FROM DUAL
UNION ALL
SELECT 3 AS id, 'trl' AS cd_used FROM DUAL
UNION ALL
SELECT 3 AS id, 'trl' AS cd_used FROM DUAL)
SELECT t.id,
LISTAGG (t.cd_used, '') WITHIN GROUP (ORDER BY t.cd_used DESC)
"cd_used"
FROM (SELECT DISTINCT
id,
CASE
WHEN COUNT (DISTINCT cd_used) OVER (PARTITION BY id) = 1
THEN
cd_used || 'Only'
ELSE
cd_used
END
cd_used
FROM tab_temp) t
GROUP BY t.id;
它说:
CREATE TABLE Spice ( MODEL TEXT NOT NULL, PART TEXT NOT NULL PRIMARY KEY, SECTION TEXT NOT NULL, FOOTPRINT TEXT NOT NULL, NODELIST TEXT NOT NULL );
但如果我将SECTION重命名为SECTION2,它就可以了。我试着引用它" SECTION"和'部分'但它出现在名称中。我应该以某种方式定义引号或转义字符? 我使用MS Access,我可以创建一个名为SECTION的字段!
答案 0 :(得分:3)
以下对我来说很好:
AdoCommand1.CommandText :=
'CREATE TABLE Spice ( MODEL TEXT NOT NULL, PART TEXT NOT NULL PRIMARY KEY, [SECTION] TEXT NOT NULL, FOOTPRINT TEXT NOT NULL, NODELIST TEXT NOT NULL );';
AdoCommand1.Execute;
请注意SECTION周围的方括号,这可以避免在大多数情况下SQL关键字和对象名称之间发生冲突。
答案 1 :(得分:-2)
Section是SQL中的保留字,因此您不应该使用它来命名对象。有关单词的完整列表,请参阅以下链接。