oracle之--动态sql(execute immediate ‘ ‘)

动态sql--execute immediate ' '

原因:ddl语句,truncate语句 不能直接使用,需要封装起来

sql 复制代码
--动态sql--execute immediate ' '====因为ddl,truncate 不能直接使用,需要封装起来
--1.TRUNCATE table 
declare 
BEGIN
--truncate table emp_4;
	execute immediate 'truncate table emp_4';--立即执行清除表数据(工作中经常使用)
end;

--2.create table emp_4 as selcet * from emp;--备份表(工作中经常使用)
declare 
BEGIN
	execute immediate 'create table emp_4 as selcet * from emp';
end;

--3.alter table emp_4 ADD aaa number;---添加aaa表字段
declare 
BEGIN
	execute immediate 'alter table emp_4 ADD aaa number';
end;

--4.alter table emp_4 modify aaa varchar2(10);---修改aaa的字段类型
declare 
BEGIN
	execute immediate 'alter table emp_4 modify aaa varchar2(10)';
end;

--5.alter table emp_4 drop COLUMN aaa;--删除aaa表字段
declare 
BEGIN
	execute immediate 'alter table emp_4 drop COLUMN aaa';
end;

--6.alter table emp_4 rename column aaa to bbb;--修改字段名
declare 
BEGIN
	execute immediate 'alter table emp_4 rename column aaa to bbb';
end;

--7.alter table emp_4 rename to emp_8;--修改表名
declare 
BEGIN
	execute immediate 'alter table emp_4 rename to emp_8';
end;

--8.drop table emp_4 ;--删除表
declare 
BEGIN
	execute immediate 'drop table emp_4';
end;
相关推荐
jnrjian1 小时前
FRA中 keep的backup set 不保险
sql·oracle
2501_941148151 小时前
多语言微服务架构与边缘计算技术实践:Python、Java、C++、Go深度解析
数据库
w***z502 小时前
MYSQL 创建索引
数据库·mysql
章鱼哥7303 小时前
[特殊字符] SpringBoot 自定义系统健康检测:数据库、Redis、表统计、更新时长、系统性能全链路监控
java·数据库·redis
5***E6853 小时前
MySQL:drop、delete与truncate区别
数据库·mysql
记得记得就1513 小时前
【MySQL数据库管理】
数据库·mysql·oracle
Austindatabases4 小时前
给PG鸡蛋里面挑骨头--杭州PostgreSQL生态大会
数据库·postgresql
秃了也弱了。4 小时前
MySQL空间函数详解,MySQL记录经纬度并进行计算
android·数据库·mysql
星环处相逢4 小时前
MySQL数据库管理从入门到精通:全流程实操指南
数据库·mysql
h***04775 小时前
SpringBoot集成Flink-CDC,实现对数据库数据的监听
数据库·spring boot·flink