一、以下用法适用于oracle
sys_guid():随机生成一个全球唯一标识符
sysdate:当前时间;例如:select * from table where date>sysdate;
trunc(sysdate):截取系统时间,参考:https://blog.csdn.net/bestcxx/article/details/51646017
sequence_name.nextval :自增长的字段,需要开发提供sequence_name
oracle 中的 || 起连接作用:'aaa'|| ','|| 'bbb'|| ','|| 'ccc'
结果是:aaa,bbb,ccc
可以通过python脚本造数据,因为变量相对容易设置一些
二、Oracle连接和sql执行
示例是oracle,mysql同理只是引用的包不同;
guid在python中通过引用uuid包来生成,用法:
guid=uuid.uuid1()
import cx_Oracle host='' port='' side='' user='' password='' desc='{}:{}/{}'.format(host,port,side) db=cx_Oracle.connect(user,password,desc) sql='' try: cr=db.cursor() #创建游标 cr.execute(sql) db.commit() except Exception as e: print('connect error:',e) finally: db.close
二、单表插入
declare i integer;--integer是pl/sql支持的类型。可以用oracle中的number begin for j in 1..2 loop insert into 表名 (字段名) values (值); end loop; end;
三、多表插入(适用于有关联的2个表)
declare i integer; j integer; begin for i in 1..2 loop insert into 表名1 (字段名) values (值); for j in 1..2 loop insert into 表名2 (字段名) values (值); end loop; end loop; end;