Fork me on GitHub

Oracle和Mysql获取uuid的方法对比

场景:orm框架用mybatis,需要往数据库新增一条数据,用Oracle和mysql数据库分别需要怎么实现?

mysql方法,用mysql提供的uuid函数

<insert id="add" parameterType="com.t.model.ActionModel" databaseId="mysql">
        insert into t_config
        (uuid, `condition`, flag, create_time, project_name,tips,status,tf_name,parent_flag)
		values 
		(uuid(),#{condition},#{flag},#{createTime},#{projectName},#{tips},#{status},#{tfName},#{parentFlag})
	</insert>

oracle方法,主要用神奇的dual,select sys_guid() from dual

<insert id="add" parameterType="com.t.model.ActionModel" databaseId="oracle">
		<selectKey keyProperty="uuid" resultType="java.lang.String" order="BEFORE">
            select sys_guid() from dual
        </selectKey>
        insert into  t_config
        (uuid, condition, flag,  create_time, project_name,tips,status,tf_name,parent_flag)
		values 
		(#{uuid},#{condition},#{flag},#{createTime},#{projectName},#{tips},#{status},#{tfName},#{parentFlag})
	</insert>

posted @ 2019-04-13 23:15  smileNicky  阅读(921)  评论(0编辑  收藏  举报