Oracle 複製任意表一行的SQL語句(測試Ok),oraclesql

來源:互聯網
上載者:User

Oracle 複製任意表一行的SQL語句(測試Ok),oraclesql

測試了很久,網上說的方法很多,其實都是錯誤的,正確的寫法:

declare    cursor rowAll is select * from tb_news where 1=1;    row1 tb_news%rowtype;    i int;    begin         i := 0;    for row1 in rowAll    loop                row1.id := fn_gen_getid('tb_news');        row1.addtime := sysdate;        row1.starttime := sysdate;        row1.adduserid := -100;        insert into tb_news values row1;        commit;    end loop;end;

 誤打誤撞,亂寫一通,沒想到這樣可以。不過我在查詢時段使用dbms_output.put_line(sysdate); 怎麼都報錯,崩潰!by default7#zbphp.com


sql 用語句複製一行資料至另一個同結構的表

sql 語句 測試了下 沒什麼問題
insert into sys_t_system備份 select top 1 * from sys_t_system where
第一個欄位 not in (select top 149 第一個欄位 from sys_t_system )

149的意思是 取得的記錄不在 149條內
1的意思是 取得幾條記錄

比如 你想取得 第151 到 160
insert into sys_t_system備份 select top 10 * from sys_t_system where
第一個欄位 not in (select top 150 第一個欄位 from sys_t_system )
 
教個oracle 的 sql語句問題例如表A有一條資料主鍵a,然後複製這條資料插入A,主鍵改為b,線上指導

insert into A(pk,col1,col2...)
select b as pk,col1,col2...
from A
where pk=a;
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.