Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

sql - How to create insert statements script from two tables

I'm using oracle SQL and I need to insert data to multiple users but I need to create insert statements first and replace only user id from the first insert statement as below :

1- This is the insert statement :

    INSERT INTO SYS_USER_FUNCTIONS ( USER_ID, FUNCTION_ID_PARENT, FUNCTION_ID_CHILD, A, U,
    D, V, R, CREATING_USER, CREATING_DATE, CREATING_TIME, LAST_UPDATE_DATE, LAST_UPDATE_COUNT,
    LAST_UPDATE_USER, LAST_UPDATE_TRANSACTION, S ) 
   VALUES ( 'JAD', 'DOCMDOC', 'OPDA100', 1, 1, 2, 1, 2, 'ZYAD', 20210112, 1515, 20210112
    , 1, 'ZYAD', 'I', 2); 

COMMIT;

2- I need to generate insert statements and replace only `

USER_ID

and select USER_ID from the following table

SELECT USER_ID 
FROM USERS 
WHERE USER_FUNCTION = 'DOCMDOC'

How can I do that ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you just want insert . . . select:

INSERT INTO SYS_USER_FUNCTIONS ( USER_ID, FUNCTION_ID_PARENT, FUNCTION_ID_CHILD, A, U,
    D, V, R, CREATING_USER, CREATING_DATE, CREATING_TIME, LAST_UPDATE_DATE, LAST_UPDATE_COUNT,
    LAST_UPDATE_USER, LAST_UPDATE_TRANSACTION, S ) 
   SELECT u.id, 'DOCMDOC', 'OPDA100', 1, 1, 2, 1, 2, 'ZYAD', 20210112, 1515, 20210112
    , 1, 'ZYAD', 'I', 2
   FROM Users
   WHERE USER_FUNCTION = 'DOCMDOC';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...