1、Excel分列的用法:
选择数据→数据→分列→分割符号→下一步
分割符号选逗号→下一步
点击目标区域输入框右侧的按钮,选择分开后所在的列
在Excel中连接两个单元格的函数concat,每一部分用逗号分割
2、写测试类往数据库表中插入数据
@SpringBootTest @RunWith(SpringJUnit4ClassRunner.class) @Slf4j public class TestDemo { @Resource private KkCbDao kkCbDao; @Resource private KkDao kkDao; @Test public void test10() { List<KkEntity> kkEntities = kkDao.selectAll(); // 查询站点信息 String[] dateStr = {"2021-04-20", "2021-04-25", "2021-04-30", "2021-05-01", "2021-05-05"}; DecimalFormat df = new DecimalFormat("####.####"); // 格式化为4位小数 for (String str : dateStr) { Date date = DateUtil.parse(str); kkEntities.stream().forEach(item -> { String price = df.format(new Random().nextFloat() * 100); // 生产小于100的随机数, KkCbEntity kkCbEntity = new KkCbEntity(); kkCbEntity.setDateP(date).setKkId(item.getId()).setPrice(Float.valueOf(price)); log.info("====> " + kkCbEntity); kkCbDao.insertSelective(kkCbEntity); }); } } }
链式编程使用注解:@Accessors(chain = true)
数据库表中数据
3、使用存储过程在数据库表中造数据
CREATE OR REPLACE PROCEDURE "PROD_TEST" (innum IN NUMBER DEFAULT '4000') AS i number := 1; outnum number := 1; BEGIN while i <= innum loop SELECT substr(cast(dbms_random.value(1,10) as varchar2(38)),0,6) into outnum FROM dual; insert into B_TEST(TEST01) values(outnum); i := i+1; end loop; END;
4、使用函数来造数据
CREATE OR REPLACE FUNCTION "test0001" (insnum IN NUMBER DEFAULT '4000', outnum OUT NUMBER) RETURN NUMBER AS i number := 1; BEGIN while i <= insNum loop SELECT substr(cast(dbms_random.value(1,10) as varchar2(38)),0,6) into outnum FROM dual; insert into B_TEST(TEST01) values(outnum); i := i+1; end loop; RETURN outnum; END;
下面这条SQL的含义是:将生成的随机数先转成字符串,然后截取前6位。
SELECT substr(cast(dbms_random.value(1,10) as varchar2(38)),0,6) FROM dual;