如何从已创建的表中在oracle sql developer中插入数据

时间:2014-12-16 14:42:28

标签: mysql database oracle

我目前正在尝试将数据输入到我的一个表中,但链接到数据库中的另一个表,下面的代码是我发现的但是它一直处于null状态,我错过了什么或者我做错了?

INSERT INTO VOLUNTEER(VOLUNTEERID,membershipid,MEMBERNAME,MEMBERDAYTIMENO)
VALUES (1, 
       (SELECT MEMBERSHIPID FROM MEMBERSHIP WHERE MEMBERNAME = 'FRANCES'),
       (SELECT MEMBERNAME FROM MEMBERSHIP WHERE MEMBERNAME = 'FRANCES'),
       (SELECT MEMBERDAYTIMENO FROM MEMBERSHIP WHERE MEMBERNAME ='FRANCES')
);

我正在使用Oracle SQL数据库。

5 个答案:

答案 0 :(得分:0)

INSERT INTO VOLUNTEER(VOLUNTEERID, membershipid, MEMBERNAME, MEMBERDAYTIMENO)
   SELECT                       1, MEMBERSHIPID, MEMBERNAME, MEMBERDAYTIMENO
      FROM MEMBERSHIP WHERE MEMBERNAME = 'FRANCES';

答案 1 :(得分:0)

如果这与mySQL完全相似,那就是你想要的:

INSERT INTO VOLUNTEER(VOLUNTEERID,membershipid,MEMBERNAME,MEMBERDAYTIMENO)
  SELECT 1, MEMBERSHIPID, MEMBERNAME, MEMBERDAYTIMENO 
  FROM MEMBERSHIP WHERE MEMBERNAME ='FRANCES';

答案 2 :(得分:0)

试试这个:

INSERT INTO VOLUNTEER(VOLUNTEERID,membershipid,MEMBERNAME,MEMBERDAYTIMENO)
SELECT 1, MEMBERSHIPID, MEMBERNAME, MEMBERDAYTIMENO 
  FROM MEMBERSHIP WHERE MEMBERNAME ='FRANCES';

如果您需要知道插入行的数量,可以使用:

begin
    INSERT INTO VOLUNTEER(VOLUNTEERID,membershipid,MEMBERNAME,MEMBERDAYTIMENO)
    SELECT 1, MEMBERSHIPID, MEMBERNAME, MEMBERDAYTIMENO 
      FROM MEMBERSHIP WHERE MEMBERNAME ='FRANCES';

    dbms_out.put_line('Rows inserted: ' || sql%rowcount);
end;

答案 3 :(得分:0)

确保

SELECT MEMBERSHIPID FROM MEMBERSHIP WHERE MEMBERNAME = 'FRANCES'

正在返回您的相关数据。似乎不是。

答案 4 :(得分:0)

我想通了我说的是错误的信息,所以我现在已经修好了

INSERT INTO VOLUNTEER(VOLUNTEERID,membershipid,MEMBERNAME,MEMBERDAYTIMENO)
VALUES (2, (SELECT MEMBERSHIPID FROM MEMBERSHIP WHERE MEMBERSHIPID = 2),
   (SELECT MEMBERNAME FROM MEMBERSHIP WHERE MEMBERSHIPID = 2),
   (SELECT MEMBERDAYTIMENO FROM MEMBERSHIP WHERE MEMBERSHIPID = 2));

感谢您的回答:)