首页 > 数据库技术 > 详细

oracle 操作

时间:2018-11-19 12:14:31      阅读:32      评论:0      收藏:0      [点我收藏+]

标签:uniq   get   use   change   reat   修改字段   integer   replace   提醒   

--(新增一条数据)
Declare
cnt Number;
Begin
Select count(*) into cnt From T_IM_MESSAGE_TEMPLATE WHERE S_TEMPLATE_ID = ‘SBI-1227‘;
IF cnt = 0 Then
insert into T_IM_MESSAGE_TEMPLATE (S_TEMPLATE_ID, S_MESSAGE_NAME)
values (‘SBI-1227‘, ‘已下达指令提醒‘);
insert into T_IM_MESSAGE_REMINDTYPE (S_TEMPLATE_ID, S_REMIND_TYPE)
values (‘SBI-1227‘, ‘0‘);
END IF;
END;
/


--- (新增表)
declare
icnt number;
begin
select count(1)
into icnt
from user_tables a
where a.TABLE_NAME = ‘T_BANK_BOND_MARKET_RESULTS‘;
if icnt = 0 then
EXECUTE IMMEDIATE ‘CREATE TABLE T_BANK_BOND_MARKET_RESULTS
(
N_ID NUMBER(10) NOT NULL,
N_SET_ID NUMBER(10) NOT NULL,
D_UPDATE_TIME DATE
)‘;

EXECUTE IMMEDIATE ‘CREATE INDEX IDX_BANK_MARKET_RESULTS_ID ON T_BANK_BOND_MARKET_RESULTS(N_ID)‘;
EXECUTE IMMEDIATE ‘CREATE SEQUENCE SEQ_BANK_MARKET_RESULTS_ID
MINVALUE 0
MAXVALUE 999999999999
START WITH 1
INCREMENT BY 1
CACHE 5‘;
end if;
end;
/
-- Add comments to the columns
comment on column T_BANK_BOND_MARKET_RESULTS.n_set_id
is ‘规则id‘;
comment on column T_BANK_BOND_MARKET_RESULTS.d_update_time
is ‘最后更新时间‘;


-- (新增索引)
DECLARE
CNT NUMBER;
BEGIN
SELECT COUNT(*) INTO CNT FROM USER_INDEXES T WHERE T.INDEX_NAME = ‘IDX__GS_REALDEAL_DATE‘;
IF CNT = 0 THEN
EXECUTE IMMEDIATE ‘CREATE UNIQUE INDEX IDX__GS_REALDEAL_DATE ON T_BANK_GS_REALDEAL (S_TRADE_DATE,L_TRADE_NO)‘;
END IF;
END;
/

--新增序列
declare
cn integer;
begin
cn := -1;
select count(*) into cn from user_sequences a where lower(a.sequence_name)=‘seq_bank_trade_balance_check‘;
if cn = 0 then
execute immediate ‘
create sequence seq_bank_trade_balance_check
minvalue 1
maxvalue 999999999999
start with 1
increment by 1
cache 20‘;
end if;
end;
/

--新增方法
create or replace function FUNC_GET_TRADE_SEAT(l_combi_id_p in number,
s_exchange_p in varchar2)
return varchar2 is

s_result idc.t_conf_tradeseat.s_seat_id%type;
begin

begin
select a.s_seat_id
INTO s_result
from (select a.*,
b.l_combi_id l_combi_idb,
max(a.l_combi_id) over(partition by a.l_fund_id, a.s_exchange, b.l_combi_id) l_combi_id2
from idc.t_conf_tradeseat a, idc.t_fmn_combiinfo b
where a.l_fund_id = b.l_fund_id
and a.s_trade = ‘1‘
and (a.l_combi_id = b.l_combi_id or a.l_combi_id = -1)) a
where l_combi_id = l_combi_id2
and a.l_combi_idb = l_combi_id_p
and a.s_exchange = s_exchange_p
and rownum = 1;
exception
when others then
s_result := null;
end;
return s_result;
end FUNC_GET_TRADE_SEAT;
/
--修改字段类型
alter table t_bank_cfets_trade modify ( S_QUOTE_TYPE varchar2(20));

--删除字段
DECLARE
VN_COUNT INTEGER;
BEGIN
--T_BANK_CFETS_REQUEST_QUOTE表删除字段--L_RESULTS_ID
VN_COUNT:= 0;
SELECT COUNT(1)
INTO VN_COUNT
FROM USER_TAB_COLS
WHERE TABLE_NAME = ‘T_BANK_CFETS_REQUEST_QUOTE‘
AND COLUMN_NAME = ‘L_RESULTS_ID‘;
IF VN_COUNT = 1 THEN
EXECUTE IMMEDIATE ‘ALTER TABLE T_BANK_CFETS_REQUEST_QUOTE DROP COLUMN L_RESULTS_ID ‘;
END IF;
end;
/

oracle 操作

标签:uniq   get   use   change   reat   修改字段   integer   replace   提醒   

原文:https://www.cnblogs.com/blogsaspx/p/9982118.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号