方式一
#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
方式三
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
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/just_learing/article/details/125377510
文章转载自吼吼哈嘿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1270次阅读
2025-03-13 11:40:53
Oracle RAC ASM 磁盘组满了,无法扩容怎么在线处理?
Lucifer三思而后行
766次阅读
2025-03-17 11:33:53
Oracle+Deepseek+Dify 实现数据库数据实时分析
bicewow
685次阅读
2025-03-06 09:41:49
【ORACLE】ORACLE19C在19.13版本前的一个严重BUG-24761824
DarkAthena
564次阅读
2025-03-04 14:33:31
Oracle避坑指南|同名表导出难题:如何精准排除指定用户下的表?
szrsu
513次阅读
2025-03-05 00:42:34
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
453次阅读
2025-03-13 14:38:19
Ogg23ai高手必看-MySQL Innodb Cluster跟oracle的亲密接触
曹海峰
448次阅读
2025-03-04 21:56:13
【ORACLE】char类型和sql优化器发生的“错误”反应
DarkAthena
404次阅读
2025-03-04 23:05:01
什么,oracle 主机用户被删了?原来是虚惊一场!
Lucifer三思而后行
401次阅读
2025-03-03 21:12:09
Oracle 如何修改 db_unique_name?强迫症福音!
Lucifer三思而后行
341次阅读
2025-03-12 21:27:56