sqlplus命令语法:
#sqlplus usr/pwd@//host:port/sid
#usr:用户名
#pwd:密码
#host:数据库服务器IP
#port:端口
#sid:数据库标识符
sqlplus命令连接Oracle示例:
[oracle@mzl ~]$ sqlplus risenet/1@//192.168.130.99:1521/risenet
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Feb 18 15:53:34 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
#测试数据库select查询语句
SQL>select instance_name,status from v$instance
INSTANCE_NAMESTATUS
---------------- ------------
risenet OPEN
SQL>
按照你现有的表创建历史数据:
create table khqfbd_1(khn int,
khqxh int,
khmc varchar2(20),
qsrq varchar2(8),
jsrq varchar2(8),
bz varchar2(100))
insert into khqfbd_1 values (2024,1,'第一季度','20240101','20240331','1')
insert into khqfbd_1 values (2024,2,'第二季度','20240401','20240630','1')
insert into khqfbd_1 values (2024,3,'第三季度','20240701','20240930','1')
insert into khqfbd_1 values (2024,4,'第四季度','20241001','20241231','1')
commit
执行:
declarev_year int
begin
select max(khn) into v_year from khqfbd_1
insert into khqfbd_1
values
(v_year+1, 1, '第一季度', v_year+1 || '0101', v_year+1 || '0331', '1')
insert into khqfbd_1
values
(v_year+1, 2, '第二季度', v_year+1 || '0401', v_year+1 || '0630', '1')
insert into khqfbd_1
values
(v_year+1, 3, '第三季度', v_year+1 || '0701', v_year+1 || '0930', '1')
insert into khqfbd_1
values
(v_year+1, 4, '第四季度', v_year+1 || '1001', v_year+1 || '1231', '1')
commit
end
执行后结果:
在insert into语句中添加指定的字段即可。
如以下数据:
test1表中:
test表与test1表结构相同,但目前无数据,现在要求将test1中的id插入到test中,不处理name字段,可用如下语句:
insert into test(id) select id from test1commit
执行后,test表中数据如下:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)