oracle普通索引改唯一索引,Oracle唯一索引功能替代[通俗易懂]

oracle普通索引改唯一索引,Oracle唯一索引功能替代[通俗易懂]Oracle唯一索引在字段全部为NULL时,不做唯一性判断,允许重复插入,而在8t中即使均为NULL值也会做重复值判断,在某些场景下客户会存在此类需求,在数据量不大不存在性能问题的情况下可以考虑通过如下方式进行替代示例表createtable”informix”.secconstitute(iddecimal(20,0)notnull,codevarchar(32),namevar…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

Oracle唯一索引在字段全部为NULL时,不做唯一性判断,允许重复插入,而在8t中即使均为NULL值也会做重复值判断,在某些场景下客户会存在此类需求,在数据量不大不存在性能问题的情况下可以考虑通过如下方式进行替代

示例表

create table “informix”.secconstitute

(

id decimal(20,0) not null ,

code varchar(32),

name varchar(64),

sec_id decimal(20,0),

meas_id decimal(20,0),

constitute_type decimal(10,0),

order_no decimal(10,0),

meas_value decimal(22,6),

ttc_therm decimal(22,6),

region_id decimal(10,0),

replicate_flag decimal(10,0),

download_region decimal(10,0),

operator_str varchar(64),

factor_str varchar(64),

if_reverse decimal(3,0),

condi_type decimal(10,0),

primary key (id) constraint “informix”.pk_secconstitute

) extent size 64 next size 64 lock mode row;

revoke all on “informix”.secconstitute from “public” as “informix”;

create unique index “informix”.idx_secid_measid_constitutetype_orderno

on “informix”.secconstitute (sec_id,meas_id,constitute_type,

order_no) using btree in dbs3;

思路

1.删除原唯一索引替换为普通索引维持索引功能

2.通过触发器调用SPL进行非NULL值的唯一性判断,必要时中止操作

代码如下

drop index if exists index_438_1;

create index index_438_1 on secconstitute(sec_id,meas_id,constitute_type,order_no);

drop procedure if exists p4_ti_secconstitute_proc;

create procedure p4_ti_secconstitute_proc() referencing new as new for secconstitute

define v_str varchar(100);

define v_col varchar(100);

define v_sql lvarchar(500);

define v_count int8;

define v_flag int;

let v_col=”;

let v_str=”;

let v_count=0;

let v_sql=”;

if new.sec_id is not null or new.meas_id is not null or new.constitute_type is not null or new.order_no is not null then

if new.sec_id is not null then

let v_col=’sec_id’;

let v_str=’sec_id=’||new.sec_id;

else

let v_col=’sec_id’;

let v_str=’sec_id is null’;

end if;

if new.meas_id is not null then

if v_col != ” then

let v_col=v_col||’,’||’meas_id’;

else

let v_col=’meas_id’;

end if;

if v_str != ” then

let v_str=v_str||’ and meas_id=’||new.meas_id;

else

let v_str=’meas_id=’||new.meas_id;

end if;

else

if v_col != ” then

let v_col=v_col||’,’||’meas_id’;

else

let v_col=’meas_id’;

end if;

if v_str != ” then

let v_str=v_str||’ and meas_id is null’;

else

let v_str=’meas_id is null’;

end if;

end if;

if new.constitute_type is not null then

if v_col != ” then

let v_col=v_col||’,’||’constitute_type’;

else

let v_col=’constitute_type’;

end if;

if v_str != ” then

let v_str=v_str||’ and constitute_type=’||new.constitute_type;

else

let v_str=’constitute_type=’||new.constitute_type;

end if;

else

if v_col != ” then

let v_col=v_col||’,’||’constitute_type’;

else

let v_col=’constitute_type’;

end if;

if v_str != ” then

let v_str=v_str||’ and constitute_type is null’;

else

let v_str=’constitute_type is null’;

end if;

end if;

if new.order_no is not null then

if v_col != ” then

let v_col=v_col||’,’||’order_no’;

else

let v_col=’order_no’;

end if;

if v_str != ” then

let v_str=v_str||’ and order_no=’||new.order_no;

else

let v_str=’order_no=’||new.order_no;

end if;

else

if v_col != ” then

let v_col=v_col||’,’||’order_no’;

else

let v_col=’order_no’;

end if;

if v_str != ” then

let v_str=v_str||’ and order_no is null’;

else

let v_str=’order_no is null’;

end if;

end if;

if v_str != ” then

let v_sql=’select count(*) from secconstitute where ‘||v_str||’ group by ‘||v_col;

prepare p from v_sql;

declare c cursor for p;

open c;

fetch c into v_count;

free p;

close c;

free c;

end if;

if v_count >1 then

raise exception -746,0,’Duplicated Sec_Id,Meas_Id,Constitue_Type,Order_No Value Founded!!’;

end if;

end if;

end procedure;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192910.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • linux配置ntp时间同步客户端(小红帽系统怎么关闭程序)

    NTP网络时间服务器在LINUX系统设置方法(小红帽版)NTP网络时间服务器在LINUX系统设置方法(小红帽版)第一种方法:1.Linux系统使用命令行配置:在Linux上面执行ntpdate:ntpdate1Array2.168.0.1#1Array2.168.0.1是NTP服务器的IP2.使用hwclock命令,把时间写入bioshwclock-w如果想定时进行时间校准,可以使用crond服务来定时执行。编辑/etc/crontab文件加入下面一行:308**

    2022年4月10日
    76
  • Tensor 和 NumPy 相互转换

    Tensor 和 NumPy 相互转换Tensor和NumPy相互转换我们很容易用numpy()和from_numpy()将Tensor和NumPy中的数组相互转换。但是需要注意的一点是:这两个函数所产生的Tensor和NumPy中的数组共享相同的内存(所以他们之间的转换很快),改变其中一个时另一个也会改变!1.Tensor转NumPya=torch.ones(6)b=a.numpy()print(a,b)a+=1print(a,b)b+=1print(a,b)tensor([1.,1.

    2022年10月19日
    2
  • 六、策略模式—旅行的交通工具 #和设计模式一起旅行#[通俗易懂]

    兵无常势,水无常形,能因敌变化而取胜者,谓之神! ——《孙子兵法》故事背景旅行开始,我和设计模式mm要去的目的地很多,去往不同目的地可以选择的交通工具也是多样的,从北京到上海,我们可以选择自驾游、乘坐飞机、高铁,甚至是骑单车等等方式!每一种交通工具到达目的的时间也不同,假如从北京到上海,乘坐飞机两个小时,高铁五个小时,自驾游3天(3*24小时),每一种交通费也不一样!假…

    2022年2月27日
    48
  • PINN学习记录(2)

    PINN学习记录(2)PINN 学习记录 2 PINN 基于解物理的方程的应用 所以我自己学习了一段时间 参考了网上很多的开源项目 末尾会贴出一些 自己总结了一下思路解微分方程 1 ODEf x f x f x f x f x f x f 0 1f 0 1f 0 1 网络构造这里说明一下 之后用 nn module 来解决 这只是建立一个通用网络 importtorchi nnasnnimport nn Module

    2025年6月11日
    2
  • [图像]Canny检测的Matlab实现(含代码)「建议收藏」

    [图像]Canny检测的Matlab实现(含代码)「建议收藏」图象的边缘是指图象局部区域亮度变化显著的部分,该区域的灰度剖面一般可以看作是一个阶跃,既从一个灰度值在很小的缓冲区域内急剧变化到另一个灰度相差较大的灰度值。Canny边缘检测基本特征如下:(1)必须满足两个条件:①能有效地抑制噪声;②必须尽量精确确定边缘的位置。(2)根据对信噪比与定位乘积进行测度,得到最优化逼近算子。这就是Canny

    2022年5月30日
    128
  • 妙计想了一千五,明朝依旧卖豆腐[通俗易懂]

    妙计想了一千五,明朝依旧卖豆腐

    2022年3月6日
    59

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号