1

这是我的 sql:

insert into
        LIST_ENTRIES(MANDATOR_KEY, SERVICE_IDENTIFIER, SERVICE_IDENTIFIER2,
        REASON_CODE, BLOCK_TYPE, VALID_FROM, VALID_TO, LISTS_KEY, VERSION)
        values
        ('Abra2', 'abrakadabra',NULL,8,0,SYSDATE,SYSDATE,
        SELECT DISTINCT ID, VERSION FROM LISTS
        WHERE SERVICE_KEY = '10s3f10-111'
        AND LIST_COLOR = 2
        AND MANDATOR_KEY = 'ASD');

我得到例外

00936. 00000 -  "missing expression"

如果我只是运行子选择:

 SELECT DISTINCT ID, VERSION FROM LISTS
            WHERE SERVICE_KEY = '10s3f10-111'
            AND LIST_COLOR = 2
            AND MANDATOR_KEY = 'ASD'

我得到结果11, 145

怎么了?为什么我不能用子选择插入 2 个值。我检查了这本手册,这里有效: http ://www.techonthenet.com/sql/insert.php

4

1 回答 1

1

这可以使用INSERT INTO...SELECT语句来完成,

INSERT INTO LIST_ENTRIES(MANDATOR_KEY, SERVICE_IDENTIFIER, SERVICE_IDENTIFIER2, REASON_CODE, BLOCK_TYPE, VALID_FROM, VALID_TO, LISTS_KEY, VERSION)
SELECT  'Abra2', 'abrakadabra',NULL,8,0,SYSDATE,SYSDATE, ID, VERSION 
FROM    LISTS
WHERE   SERVICE_KEY = '10s3f10-111' AND 
        LIST_COLOR = 2 AND 
        MANDATOR_KEY = 'ASD'
于 2013-02-20T14:13:09.323 回答