1.把一个A表的某些记录 形成B表,应用场景:备份某些记录到B表
create table B as select * from A t where t.zxjd is null or t.zxwd is null
2.删除A表的某些数据
delete from A t where t.zxjd is null or t.zxwd is null
3.把A表某字段前面重复的字符删除
两种方式:一是字符串截取,二是用空值替换:
这个是替换语句:update A t set t.dzqc =Replace(t.z,'山东省','')
4.给A表添加一个ID字段,并从1不断增加
首先,给表添加ID字段,字段类型是NUMBER
其次,在PLSQL里面创建一个序列:
-- Create sequence
create sequence TEST
minvalue 1
maxvalue 99999999
start with 2101401
increment by 1
cache 20;
最后更新A表:
update A t set t.id = test.nextval
设置这个表创建触发器,让它添加记录的时候,自动增加ID
create or replace trigger aoto_add_id
before insert
on A
for each row
declare
primary_key_value number;
begin
select test.nextval into primary_key_value from dual; //test.nextval 是上面创建的序列
:new.id:=primary_key_value;
end aoto_add_id
创建完毕触发器,要执行。
5.给A表的时间戳字段添加系统的时间戳:
update a t set t.gxsj = (systimestamp)
格式化查看这个时间戳字段:
select to_char(t.gxsj,'YYYY-MM-DD HH24:MI:SS.FF') from A_POI t
建表的时候时间戳字段自动添加系统时间戳:
create
table
test(id
int
, t
timestamp
default
systimestamp)