JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區 » SQL 語法  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 SQL語法問題(急)
markk1933





發文: 4
積分: 0
於 2017-11-27 02:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Post is deleted

markk1933 edited on 2018-05-10 02:58
reply to postreply to post
作者 Re:SQL語法問題(急) [Re:markk1933]
LiaoLuke





發文: 106
積分: 0
於 2017-11-27 03:33 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
markk1933 wrote:
String sql = "INSERT INTO rawdata (rd_id, rd_comp_no,rd_card_no,rd_card_type, rd_trans_date, rd_driver_no, rd_route_no,rd_bus_no, rd_shuttle_code, rd_station_no, rd_iostatus, rd_file_name, rd_pro_date, rd_pro_code values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

請問這句該怎麼改成,重複的值不寫入,急用!! 謝謝 (rd_card_no,rd_trans_date) 如果重複就不寫入,沒重複就寫入


INSERT INTO table (column1, column2, ... )
SELECT expression1, expression2, ... FROM source_tables
[WHERE conditions];


table
The table in which to insert the records.
column1, column2
These are the columns in the table to insert values.
expression1, expression2
These are the values to assign to the columns in the table. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.
source_tables
Used when inserting records from another table. This is the source table when performing the insert.
WHERE conditions
Optional. Used when inserting records from another table. These are the conditions that must be met for the records to be inserted.


reply to postreply to post
作者 Re:SQL語法問題(急) [Re:markk1933]
kentyeh





發文: 642
積分: 6
於 2017-11-28 00:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
markk1933 wrote:
String sql = "INSERT INTO rawdata (rd_id, rd_comp_no,rd_card_no,rd_card_type, rd_trans_date, rd_driver_no, rd_route_no,rd_bus_no, rd_shuttle_code, rd_station_no, rd_iostatus, rd_file_name, rd_pro_date, rd_pro_code values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

請問這句該怎麼改成,重複的值不寫入,急用!! 謝謝 (rd_card_no,rd_trans_date) 如果重複就不寫入,沒重複就寫入

1
2
3
INSERT INTO rawdata (rd_id, rd_comp_no,rd_card_no,rd_card_type, rd_trans_date, rd_driver_no, rd_route_no,rd_bus_no, rd_shuttle_code, rd_station_no, rd_iostatus, rd_file_name, rd_pro_date, rd_pro_code 
SELECT ?,?,?,?,?,?,?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM rawdata WHERE rd_card_no= ? AND rd_trans_date= ?)

記得多帶兩個參數


reply to postreply to post
作者 Re:SQL語法問題(急) [Re:kentyeh]
markk1933





發文: 4
積分: 0
於 2017-11-28 00:50 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝

reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區 » SQL 語法

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8