这是我的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"
如果我只是运行subselect:
SELECT DISTINCT ID, VERSION FROM LISTS
WHERE SERVICE_KEY = '10s3f10-111'
AND LIST_COLOR = 2
AND MANDATOR_KEY = 'ASD'
我得到的结果为11, 145
有什么不对?为什么我不能使用subselect insert 2 vales。我查看这本手册,这里有效: http://www.techonthenet.com/sql/insert.php
答案 0 :(得分: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'