小编Lee*_*mbl的帖子

检查多个输入参数不起作用的约束UDF

我正在尝试在表上实现检查约束,以便在存在其中两列("Int_1"和"Int_2")已经具有我们尝试插入的值的记录的情况下无法插入记录例如:

ID     Name     Int_1     Int_2
1      Dave       1         2
Run Code Online (Sandbox Code Playgroud)

将(2,Steve,2,2)插入上表是可以的,(3,Mike,1,3),但是不允许插入Int_1和Int_2已经存在的值,即(4,Stuart,1 ,2)是非法的.

我认为定义我的表因此会起作用:

CREATE TABLE [Table](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](255) NOT NULL,
    [Int_1] [int] NOT NULL,
    [Int_2] [int] NOT NULL,
    CONSTRAINT [chk_Stuff] CHECK (dbo.chk_Ints(Int_1, Int_2)=1))
Run Code Online (Sandbox Code Playgroud)

其中:dbo.chk_Ints定义为:

CREATE FUNCTION [dbo].[chk_Ints](@Int_1 int,@Int_2 int)
RETURNS int
AS
BEGIN

DECLARE @Result int

IF NOT EXISTS (SELECT * FROM [Table] WHERE Int_1 = @Int_1 AND Int_2 = @Int_2)
BEGIN
    SET @Result = 1
END
ELSE 
BEGIN
    SET @Result = 0
END

RETURN @Result …
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server

3
推荐指数
1
解决办法
3429
查看次数

从JAXB强制转换null java.lang.Integer会产生0,而不是null

我有以下XML:

<person>
    <id/>
    <Identifier/>
    <Surname>TEST</Surname>
    <Forename1>TEST</Forename1>
    <Forename2/>
    <Title>MR</Title>
    <Gender>M</Gender>
</person>
Run Code Online (Sandbox Code Playgroud)

通过序列化以下类产生:

package anonymised.packagename;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = {
    "Id",
    "Identifier",
    "Surname",
    "Forename1",
    "Forename2",
    "Title",
    "Sex"
})

@XmlRootElement(name = "person")
public class person{

    @XmlElement(name = "id", nillable=true)
    protected Integer Id;
    public Integer getId(){
        return Id;
    }

    public void setId(Integer value){
        this.Id = value;
    }

    @XmlElement(name = "Identifier", nillable=true)
    protected String Identifier;
    public String getIdentifier(){
        return Identifier;
    } …
Run Code Online (Sandbox Code Playgroud)

java xml casting jaxb

2
推荐指数
1
解决办法
3718
查看次数

标签 统计

casting ×1

java ×1

jaxb ×1

sql-server ×1

t-sql ×1

xml ×1