您的位置:首页 > 数据库 > Oracle

【数据库】-Oracle常用语法

2017-06-23 16:42 274 查看
1、备份数据
create table copy_tableas select *from tablewhere 条件
注意:当where条件成立时,会复制表结构+表数据;当where条件不成立,只会创建相同的表结构,不会复制表数据
2、清空表数据  

delete from tablewhere 1=1

3、日期&时间

 时间:to_date('2017/5/27 11:21:50','yyyy-mm-dd hh24:mi:ss')


 日期:to_date('2017/5/27','yyyy-mm-dd')



4、存储过程

1)单表数据构造:

declare 

    i int:= 初始值;

    begin

        while(i<值) loop

            insert into 表(字段集) values (赋值);

            i:= i+1;

        end loop;

        commit;

    end;


2)主从表数据构造:

declare 

    i int:= 初始值;

    begin

        while(i<值) loop

            insert into 主表(主键,其他字段集...) values (i,其他属性值...);

            insert into 从表(主键,外键,其他字段集...) values (i,i,其他属性值...);

            i:= i+1;

        end loop;

        commit;

    end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: