DECLARE @sql nvarchar() DECLARE @cou int SET @sql='INSERT INTO people values('''+'xiaohong'+''');select @temp=@@IDENTITY' EXEC sp_executesql @sql, N'@temp int out', @cou OUT INSERT INTO child VALUES(@cou, '小兰') CREATE PROC chjj @name nvarchar() AS BE…
CREATE OR REPLACE FUNCTION SEQ1 (v_bname in VARCHAR2) return NUMBER is v_bcount NUMBER; BEGIN execute immediate 'select count(*) from '||v_bname into v_bcount; dbms_output.put_line(v_bname||'------------------'||v_bcount); return(v_bcount+1); end SEQ…
我们都知道Mybatis在插入单条数据的时候有两种方式返回自增主键: 1.对于支持生成自增主键的数据库:useGenerateKeys和keyProperty. 2.不支持生成自增主键的数据库:<selectKey>. 但是怎对批量插入数据返回自增主键的解决方式网上看到的还是比较少,至少百度的结果比较少. Mybatis官网资料提供如下: First, if your database supports auto-generated key fields (e.g. MySQL and SQL…
postgresql不支持last_insert_id()方法,恶心到啦: 不过还好它有其他的解决方案: 创建一个测试数据表: CREATE TABLE test.test18 ( id serial NOT NULL, ddd character varying ) 一.先过去不重复的主键id,然后再插入 获取他的Sequence,select nextval('test.test18_id_seq'),然后再插入即可! 二.返回主键id insert into test.test18 (dd…
1.Java代码: 1.1 entity类: User.java public class User { private int userId; private String userName; private String password; private String comment; //这里要添加 setter and getter 略 } 1.2 DAO类: UserDao.java public interface UserDao { public int insertAndGe…
一. 1.两个参数都是int类型() 例子: 1 < select id="searchClassAllNum" resultType="int"> select count(*) from parkclass pc join parkclasstag pct on(pc.classtaglevel=pct.id) join parent p on(pc.parentid=p.id) where pc.parkid=#{0} and pct.id=#{…