oracle语句的执行顺序
1 2 3 4 5 6 7 | 查询语句的执行顺序: 1 、FROM 子句:执行顺序为从后往前、从右到左。数据量较少的表尽量放在后面。 2 、WHERE子句:执行顺序为自下而上、从右到左。将能过滤掉最大数量记录的条件写在WHERE 子句的最右。 3 、GROUP BY:执行顺序从左往右分组,最好在GROUP BY前使用WHERE将不需要的记录在GROUP BY之前过滤掉。 4 、HAVING 子句:消耗资源。尽量避免使用,HAVING 会在检索出所有记录之后才对结果集进行过滤,需要排序等操作。 5 、SELECT子句:少用*号,尽量取字段名称。ORACLE 在解析的过程中, 通过查询数据字典将*号依次转换成所有的列名, 消耗时间。 6 、ORDER BY子句:执行顺序为从左到右排序,消耗资源 |
1 2 | --查询所有的表空间 select * from Dba_Tablespaces; |
1 2 | --查看表空间下的所有表 select bb.TABLE_NAME from dba_tables bb where bb.TABLESPACE_NAME= 'TESTSPACE' |
1 2 | --查询当前用户默认的表空间 select * from user_users; |
1 2 3 4 5 6 7 8 9 10 11 12 | --建表语句 create table public_memo( ids varchar2( 32 ) not null , title varchar2( 255 ) not null , contents clob not null , address varchar( 255 ) not null , longitude number( 13 , 10 ) not null , dimension number( 13 , 10 ) not null , created_date date, updated_date date, status varchar2( 4 ) not null ) |
字段加注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | comment on table public_memo is '备忘录' ; comment on column public_memo.ids is '主键id' ; comment on column public_memo.title is '标题' ; comment on column public_memo.contents is '内容' ; comment on column public_memo.address is '地址' ; comment on column public_memo.longitude is '经度' ; comment on column public_memo.dimension is '纬度' ; comment on column public_memo.created_date is '创建时间' ; comment on column public_memo.updated_date is '修改时间' ; comment on column public_memo.status is '状态' ; |
1 2 | --修改字段名称 alter table public_memo rename column dimension to latitude; |
sql数据准备
1 2 3 4 5 6 7 8 9 | insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status) values (sys_guid(), '1' , '23' , '浦东大道' , 12.1234 , 13.2345 ,sysdate,sysdate, '1' ); insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status) values (sys_guid(), '2' , '24' , '浦东大道001' , 12.1234 , 13.2345 ,sysdate,sysdate, '2' ); insert into public_memo(ids,title,contents,address,longitude,latitude,created_date,updated_date,status) values (sys_guid(), '3' , '25' , '浦东大道002' , 12.1234 , 13.2345 ,sysdate,sysdate, '3' ); |
1 2 | --创建索引 create index ix_title on public_memo(title) initrans 16 online |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异