如何获取SAP HANA数据库中最后插入的记录标识符?

时间:2018-09-04 12:42:07

标签: database sap hana

这是我的存储过程,我正在尝试获取最后插入的DepartmentId。没有MAX(DepartmentId)

,就不会寻找触发器和任何解决方案
CREATE PROCEDURE "BPPRA_CUSTOM_APP"."AddUpdateMaster_Department"(IN DepartmentId BIGINT,Department nvarchar(100),Description nvarchar(100),UserId int)
    LANGUAGE SQLSCRIPT
    --READS SQL DATA 
AS
BEGIN
    if DepartmentId>0
    then
        update "BPPRA_CUSTOM_APP"."Master_Department" set "Department"=Department,"Description"=Description ,"ModifiedUserId"=UserId,"ModifiedDate"=CURRENT_TIMESTAMP 
        where "DepartmentId"= :DepartmentId;
        select  DepartmentId  FROM DUMMY;
    ELSE    

    insert into "BPPRA_CUSTOM_APP"."Master_Department" ("Department","Description","CreatedUserId","CreatedDate") 
                                                 values(Department,Description,UserId,CURRENT_TIMESTAMP);   

    END IF;
END; 

1 个答案:

答案 0 :(得分:1)

在插入查询之后,只需使用此:

select current_identity_value() FROM DUMMY;

它将返回最新的插入值