oracle insert into values 批量插入

方式一

#oracle多条插入 insert all

xxxxx

select 1 from dual;

方式二

insert into tableName(column1(主键),column2,column3...)
  select value1 column1,value2 column2,value3 column3 from dual
  union all
  select value1 column1,value2 column2,value3 column3 from dual
  union all
  select value1 column1,value2 column2,value3 column3 from dual
  union all
  select value1 column1,value2 column2,value3 column3 from dual

 

扫描二维码关注公众号,回复: 16700755 查看本文章

方式三

begin
  insert into oracle_table ( id, code ) values( 1 , '1' );  
  insert into oracle_table ( id, code ) values( 2 , '2' );  
  insert into oracle_table ( id, code ) values( 3 , '3' );   
  insert into oracle_table ( id, code ) values( 4 , '4' );
end;

 

最近做了一些笔记

#切换页面
su#切换root
mkdir -p /opt/oracledbfile #创建文件
chmod -R 777 /opt/oracledbfile/ #授权

# 创建表空间
 create tablespace mydemo datafile '/opt/oracledbfile/mydemo.dbf' 
    size 200m autoextend on next 50m maxsize 20480m;
#创建账户密码
create user cm identified by ok default tablespace mydemo;
#授权
grant connect,resource to cm;
#ok
conn cm/ok

# 查询oracle表
 cd "/root"
 su oracle
sqlplus
select  * from userinfos;

#oracle多条插入 insert all xxxxx select 1 from dual;

#mapper中 加入keyProperty="id" useGeneratedKeys="true"

#可以获取id

#serverTimezone = GMT%2b8调时区

#useGeneratedKeys 取值范围true、false 默认值是:false。 含义:设置是否使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中。

keyProperty 取id的key值,主要是在主键是自增的情况下,添加成功后可以直接使用主键值,其中keyProperty的值是对象的属性值,不是数据库表中的字段名。

#连接数据库
su oracle 
sqlplus
cm
ok
desc uesrinfos;
#会出现元数据 int类型(38)位          
#varchar2(20) 位 会自动处理utf-8字符
#select max(userid),username,min(birthday) from uesrinfos group by username; 分组的时候 在oracle中要为其他字段定义排序规制
#DML 语句(数据操作语i) Insert、 Update、 Delete、 Merge
#DDL 语句(数据定义语i) Create, Alter, Drop, Truncate
#DCL 语句(数据控制语i) Grant、 Revoke
#事务控制语句Commit、Rollback, Savepoint
#授权
grant connect,resource to cm;
# select userid||username from uesrinfos; ||类似加
#distinct 去除重复行 (影响效率 查询 逐行逐列)
#使用like 记得加索引 加快速度
#select username from uesrinfos where instr(username,'zhang')!=0;
类似like的模糊查询 效率略高se
# select * from dual;  默认表 可以用来测试

#oracle函数背诵
# select abs(-11) from dual;
#select ceil(11.5),ceil(-11.5) from dual;       ceil 正右负左
#select floor(11.5),floor(-11.5) from dual;   floor正左负右
#select power(2,3) from dual; 返回2的3次方的值
#select exp(3) from dual; 
# select log(2,8) from dual; 求2的几次方 为8
# select mod(10,3) from dual;
#select round (3.5) from dual;
#select trunc(3.9) from dual;
#select sqrt(100) from dual;
#select concat('a','b') from dual;
#select initcap('hello world,cm!!!are you ok') from dual; 首字母大写
#select lower('SSSXXXXXXXHelloAAA')  from dual; 全小写
#select upper('SSSXXXXXXXHelloAAA')  from dual; 全大写
#select instr('hello world hello hadoop','hello') from dual;
#select instr('hello world hello hadoop','hello',1,2) from dual;
#select lpad('1000',5,'0') from dual; 左补位
#select rpad('1000',5,'0') from dual; 右补位
#select trim(' abcd ') from dual; 去空格
#select trim('a' from 'abbd') from dual;  去a
#select substr('1308888888',3,8) test from dual; 截取字符串
#select add_months(birthday,3) from uesrinfos; 加3个月
#select last_day(sysdate) from dual;
#select months_between(sysdate,to_date('1999-9-12','yyyy-MM-dd')) from dual;
#select trunc(sysdate) from dual;
#select trunc(to_date('2022-6-23','yyyy-MM-dd'),'day') from dual;
#select next_day(sysdate,1) from dual; 查日期
#select extract(YEAR from timestamp '1999-9-7 0:0:0')  as datess from dual;  截取年月日
#select current_timestamp from dual;
#select rowid,rownum,userid,username from uesrinfos; 伪列 rowid 
# select * from uesrinfos order by userid desc; 查询倒叙
# select rownum no,a.* from uesrinfos a where rownum<=4;
# select * from (select rownum no,a.* from uesrinfos a where rownum<=4) tab where tab.no>2; oracle 分页方案
#arrayList       前包后不包
#delete from emp e 
where e.rowid>(select min(x.rowid)
from emp x
where x.emp_no = e.emp_no
); 伪类去重法
#delete from uesrinfos a where rowid>(select min(rowid) from uesrinfos b where a.username=b.username); 删除重复
#select *  from uesrinfos a where rowid=(select min(rowid) from uesrinfos b where  a.username=b.username)  查询不重复
#select *  from uesrinfos a where rowid=(1,2);
#mysql 去重的三个方式 distinct  groupby  伪列去重法 
#ALTER TABLE old_table_name RENAME TO new_table_name;(大写为系统命令) 
#alter table userinfos rename column age to birthyear; 修改列名

#
select sum(birthyear) from userinfos ;
select count(birthyear) from userinfos;
select e.e/d.d from (select sum(birthyear) e  from userinfos) e ,(select count(birthyear) d from userinfos) d;
#

#update userinfos set birthyear=(select e.e/d.d from (select sum(birthyear) e  from userinfos) e ,(select count(birthyear) d from userinfos) d) where birthyear=null;  空位补充
#select nvl(birthyear,25) from userinfos; 空位补充2
#select userid,username,birthday,nvl(birthyear,k.e) from userinfos ,(select avg(birthyear) e from userinfos) k;空位补充3


 

猜你喜欢

转载自blog.csdn.net/just_learing/article/details/125377510