zoukankan      html  css  js  c++  java
  • orcle常用語句


    //創建表格
    create table UseInfo
    (
    userGUID varchar(
    32),
    useID varchar2(
    10),
    useName Nvarchar2(
    5),
    usePWD varchar2(
    16),
    useEmail varchar2(
    50),
    usePower integer,
    useWriterDate varchar2(
    8),
    useExportExcel real
    );


    //修改欄位大小
    alter table userinfo
    modify ( useName varchar2(
    10));


    //增加欄位
    alter table useinfo
    add (useNote varchar2(
    50));

    //刪除欄位
     alter table useinfo
     drop column userguid;

    //增加主鍵
     alter table useinfo
     add constraint useinfo_userGUID_pk
     primary key (useGUID);

    //刪除主鍵
    alter table  useinfo
    drop constraint useinfo_userGUID_pk;
    //增加外鍵
     alter table ConcernDetail
     add constraint ConcernDetail_ccdccbGUID_FK
     foreign key(ccdccbGUID) references ConcernBrand(ccbGUID);

    //得到指定行數的資料
    select * from erpuser.customer where rownum<4;

    //查看所有表
     select * from tab;

    //查看約束
    select owner,constraint_name,constraint_type,table_name from user_constraints where owner='WEBUSER';

    //冊除主鍵
    alter table brand_customer_lot_detaildrop constraint brand_customer_lot_detail_pk;

    //清除sql plus屏幕
    clear screen;

      //更新值
    1) 最简单的形式
       
    --经确认customers表中所有customer_id小于1000均为'北京'
       
    --1000以内的均是公司走向全国之前的本城市的老客户:)
       update customers
       
    set    city_name='北京'
       
    where  customer_id<1000

    2) 两表(多表)关联update -- 仅在where字句中的连接
       
    --这次提取的数据都是VIP,且包括新增的,所以顺便更新客户类别
       update customers  a       
    -- 使用别名
       
    set    customer_type='01' --01 为vip,00为普通
       
    where  exists (select 1
                      from   tmp_cust_city b
                      
    where  b.customer_id=a.customer_id
                     )

    3) 两表(多表)关联update -- 被修改值由另一个表运算而来
       update customers a   
    -- 使用别名
       
    set    city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)
       
    where  exists (select 1
                      from   tmp_cust_city b
                      
    where  b.customer_id=a.customer_id
                     )
       
    -- update 超过2个值
       update customers a   
    -- 使用别名
       
    set    (city_name,customer_type)=(select b.city_name,b.customer_type
                                         from   tmp_cust_city b
                                         
    where  b.customer_id=a.customer_id)
       
    where  exists (select 1
                      from   tmp_cust_city b
                      
    where  b.customer_id=a.customer_id
                     )

       //刪除表
    drop table CONCERNDETAIL;

       //插入資料
       insert into brand_customer_lot
     values(
    '2008010220','A00001','lot_200801020','A1');

      insert into brand_customer_lot_detail
     values('2008010220','CF','Acer',to_date('20080102','yyyy-mm-dd'),'Q',200,200000,'R');

    方法:
    round()是四舍五入,不是取整。 
    ceil()是进一,floor()是去尾,都是返回整数。 
    trunc()也是去尾,但是可以指定小数位数,不指定即为取整,所以也是对的。
  • 相关阅读:
    UVA 11488 Hyper Prefix Sets (字典树)
    UVALive 3295 Counting Triangles
    POJ 2752 Seek the Name, Seek the Fame (KMP)
    UVA 11584 Partitioning by Palindromes (字符串区间dp)
    UVA 11100 The Trip, 2007 (贪心)
    JXNU暑期选拔赛
    计蒜客---N的-2进制表示
    计蒜客---线段的总长
    计蒜客---最大质因数
    JustOj 2009: P1016 (dp)
  • 原文地址:https://www.cnblogs.com/scottckt/p/1023375.html
Copyright © 2011-2022 走看看