Oracle pl/sql 常用sql__修訂版

來源:互聯網
上載者:User

---字串轉日期
select to_date('2011-11-30 18:00:00', 'yyyy-mm-dd hh24:mi:ss') from dual;
--select * from scott.dept d where e.deptno=d.deptno and d.deptno=10;
select sysdate, add_months(sysdate, 12) from dual;

--時間和數字直接加減
select sysdate+6/24/60,sysdate from dual;--目前時間加上6分鐘
--樣本:用於and子句中的時間加減
select r.replytime,c.sendtime,c.sendtime+6/24/60
  from prplsmsreply r, prplsmscontent c
 where r.parentid = c.id
 and r.replytime < c.sendtime+6/24/60;--here

--加法
select sysdate,add_months(sysdate,12) from dual;        --加1年
select sysdate,add_months(sysdate,1) from dual;        --加1月
select sysdate,to_char(sysdate+7,'yyyy-mm-dd HH24:MI:SS') from dual;   --加1星期
select sysdate,to_char(sysdate+1,'yyyy-mm-dd HH24:MI:SS') from dual;   --加1天
select sysdate,to_char(sysdate+1/24,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1小時
select sysdate,to_char(sysdate+1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1分鐘
select sysdate,to_char(sysdate+1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --加1秒
--減法
select sysdate,add_months(sysdate,-12) from dual;        --減1年
select sysdate,add_months(sysdate,-1) from dual;        --減1月
select sysdate,to_char(sysdate-7,'yyyy-mm-dd HH24:MI:SS') from dual;   --減1星期
select sysdate,to_char(sysdate-1,'yyyy-mm-dd HH24:MI:SS') from dual;   --減1天
select sysdate,to_char(sysdate-1/24,'yyyy-mm-dd HH24:MI:SS') from dual;  --減1小時
select sysdate,to_char(sysdate-1/24/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --減1分鐘
select sysdate,to_char(sysdate-1/24/60/60,'yyyy-mm-dd HH24:MI:SS') from dual;  --減1秒

--begin:增加SEQ_PRPDBANKOUTLETS
drop sequence SEQ_PRPDBANKOUTLETS_test;

create sequence SEQ_PRPDBANKOUTLETS_test
increment by 1
start with 100001
 maxvalue 999999999999999999999999999
 minvalue 1
 cache 20;
--end:增加SEQ_PRPDBANKOUTLETS

--增加欄位begin
alter table PrpLBankAccount_test add lossType char(2) not null;
--增加欄位end

--添加欄位備忘
comment on column PrpLaccountModify_test.PayObjectCode_test is '支付對象代碼';
--添加欄位備忘
--添加表備忘
comment on table PrpLaccountModify_test is '收付帳號修改申請表';
--添加表備忘

--增加索引
create index idx_cmainsub_mainno_test on prpcmainsub_test (mainpolicyno );
--刪除索引
drop index idx_cmainsub_mainno_test;

--修改欄位
alter table PrpLaccountModify_test modify lossType CHAR(2) not null;

--修改資料(update)
update Prpdcode_test a set a.codecname = '全車盜搶' where a.codetype='DamageCode' and a.codecode='815';

--增加(單行形式)

--user_objects
select  * from user_objects where object_name=upper('prpdbankoutlets');

 

 

--利用endtime欄位更新endtime欄位本身

update prpdcheckshift a set a.endtime = to_date(to_char(a.endtime, 'yyyy-mm-dd')||' 23:59:59','yyyy-mm-dd hh24:mi:ss');

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.