Oracle copies an SQL statement (test OK) for any table row, oraclesql

Source: Internet
Author: User

Oracle copies an SQL statement (test OK) for any table row, oraclesql

I tested it for a long time. There are many methods on the Internet, but they are all incorrect. The correct method is as follows:

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;

I did not expect this. However, I used dbms_output.put_line (sysdate) in the query window. I reported an error and crashed! By default7 # zbphp.com


SQL statement to copy a row of data to another table with the same structure

The SQL statement is tested.
Insert into sys_t_system backup select top 1 * from sys_t_system where
The first field not in (select top 149 first field from sys_t_system)

149 means that no more than 149 records are obtained.
1 indicates how many records are obtained.

For example, if you want to get 151st to 160
Insert into sys_t_system backup select top 10 * from sys_t_system where
The first field not in (select top 150 first field from sys_t_system)

An oracle SQL statement is taught. For example, table A has a data primary key A. copy the data and insert it into Table A. The primary key is changed to B.

Insert into A (pk, col1, col2 ...)
Select B as pk, col1, col2...
From
Where pk =;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.