调用脚本的方式自动的创建或者是更新oracle数据库自带的Seq序列号的值
执行脚本:
CREATE OR REPLACE PACKAGE PKG_QUERY IS -- Author : ADMINISTRATOR
-- Created : 2016/12/8 星期四 10:28:37
-- Purpose : 用做查询游标 -- Public type declarations
TYPE CUR_QUERY IS REF CURSOR; END PKG_QUERY;
/ create or replace function create_seq_func(
seq_name in varchar2 ,/*seq名称*/
bus_table_name in varchar2,/*业务表名*/
pkcloumn_name in varchar2 /*业务表主键名*/
)
return varchar2
is
result varchar2(30000);
type ref_cursor_type is ref cursor;
cursor_ids ref_cursor_type;
cursor_ids_1 ref_cursor_type;
V_NUM number:=0;
v_max_seq number :=1;
v_max_seq_1 number :=1; v_max_sql varchar(4000);
v_max_sql_1 varchar(4000); v_sql_alter varchar(4000);
v_sequence_sql varchar(4000);
begin select count(0) into V_NUM from user_sequences where sequence_name = seq_name;
if V_NUM > 0 then v_max_sql_1:='select to_number(max('||pkcloumn_name||')+100) from '||bus_table_name||' t ';
dbms_output.put_line('_____0_______'||v_max_sql_1);
open cursor_ids_1 for v_max_sql_1 ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____1_______'||v_max_seq_1); ---把自动增长值设置为 业务表的最大值
v_sql_alter :='ALTER SEQUENCE '||seq_name||' INCREMENT BY '|| v_max_seq_1;
dbms_output.put_line('_____3_______'||v_sql_alter);
execute immediate v_sql_alter;
---获取下一个值
v_sql_alter :=' SELECT '||seq_name||'.NEXTVAL FROM DUAL ';
dbms_output.put_line('_____4_______'||v_sql_alter);
-- execute immediate v_sql_alter;
open cursor_ids_1 for v_sql_alter ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____4_1_______'||v_max_seq_1);
v_max_seq:=v_max_seq_1; ---把自动增长值设置为1
v_sql_alter :='ALTER SEQUENCE '||seq_name||' INCREMENT BY 1 ' ;
dbms_output.put_line('_____5_______'||v_sql_alter);
execute immediate v_sql_alter;
---获取下一个值
v_max_sql_1 :=' SELECT '||seq_name||'.NEXTVAL FROM DUAL ';
dbms_output.put_line('_____6_______'||v_max_sql_1); open cursor_ids_1 for v_max_sql_1 ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____2_______'||v_max_seq_1);
v_max_seq:=v_max_seq_1;
fetch cursor_ids_1 into v_max_seq_1;
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; fetch cursor_ids_1 into v_max_seq_1;
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; fetch cursor_ids_1 into v_max_seq_1;
dbms_output.put_line('_____2_______'||v_max_seq_1);
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; else
v_sequence_sql :='create sequence '||seq_name||' minvalue 1 maxvalue 999999 start with 1 increment by 1 cache 20';
dbms_output.put_line('_____11_______'||v_sequence_sql);
execute immediate v_sequence_sql; v_max_sql_1:='select to_number(max('||pkcloumn_name||')+100) from '||bus_table_name||' t ';
dbms_output.put_line('_____10_______'||v_max_sql_1);
open cursor_ids_1 for v_max_sql_1 ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____11_______'||v_max_seq_1); ---把自动增长值设置为 业务表的最大值
v_sql_alter :='ALTER SEQUENCE '||seq_name||' INCREMENT BY '|| v_max_seq_1;
dbms_output.put_line('_____13_______'||v_sql_alter);
execute immediate v_sql_alter;
---获取下一个值
v_sql_alter :=' SELECT '||seq_name||'.NEXTVAL FROM DUAL ';
dbms_output.put_line('_____4_______'||v_sql_alter);
-- execute immediate v_sql_alter;
open cursor_ids_1 for v_sql_alter ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____4_1_______'||v_max_seq_1);
v_max_seq:=v_max_seq_1; ---把自动增长值设置为1
v_sql_alter :='ALTER SEQUENCE '||seq_name||' INCREMENT BY 1 ' ;
dbms_output.put_line('_____5_______'||v_sql_alter);
execute immediate v_sql_alter;
---获取下一个值
v_max_sql_1 :=' SELECT '||seq_name||'.NEXTVAL FROM DUAL ';
dbms_output.put_line('_____6_______'||v_max_sql_1); open cursor_ids_1 for v_max_sql_1 ;
fetch cursor_ids_1 into v_max_seq_1;
/** 判断 是否有id 值查询出来 */
if cursor_ids_1%found then
while cursor_ids_1%found loop
dbms_output.put_line('_____2_______'||v_max_seq_1);
v_max_seq:=v_max_seq_1;
fetch cursor_ids_1 into v_max_seq_1;
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; fetch cursor_ids_1 into v_max_seq_1;
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; fetch cursor_ids_1 into v_max_seq_1;
dbms_output.put_line('_____17_______'||v_max_seq_1);
exit when cursor_ids%notfound or cursor_ids%notfound is null ;
end loop;
end if; end if; return v_max_seq;
EXCEPTION
WHEN OTHERS THEN RETURN v_max_seq; end;
/
脚本调用
使用plsql 的命令窗口调用:
variable seq varchar2 ;
execute :seq :=create_seq_func('GK_PAYREPORT_SEQ','GK_PAYREPORT','GK_PAYREPORT_ID') ;

调用脚本的方式自动的创建或者是更新oracle数据库自带的Seq序列号的值的更多相关文章
- 使用C#的两种方式OracleClient组件和OleDB组件连接ORACLE数据库
一.使用OracleClient组件连接Oracle .Net框架的System.Data.OracleClient.dll组件(ADO.Net组件),为连接和使用Oracle数据库提供了很大的方便. ...
- Spring Date Jpa on update current_timestamp 自动维护创建时间和更新时间
在数据库里设置默认值current_timestamp可以维护创建时间,设置on update current_timestamp 可以维护更新时间.在JPA中应该如何去做呢?这里还是以上篇Topic ...
- Oracle数据库不能创建表空间及表中文乱码问题
1.不能创建表空间问题 datafile为表空间的存放位置,没有将表空间存放路径指定为orcl数据库时,创建表空间出错如下 查看自己的Oracle安装位置,我的Oracle10g安装在虚拟XP系统中, ...
- JPA注解实体类,给表添加创建时间,更新时间,id的生成以及创建唯一约束
首先创建一个BaseModel,自动生成创建时间和更新时间 @SuppressWarnings("serial") @MappedSuperclass public class B ...
- ? 原创: 铲子哥 搜狗测试 今天 shell编程的时候,往往不会把所有功能都写在一个脚本中,这样不太好维护,需要多个脚本文件协同工作。那么问题来了,在一个脚本中怎么调用其他的脚本呢?有三种方式,分别是fork、source和exec。 1. fork 即通过sh 脚本名进行执行脚本的方式。下面通过一个简单的例子来讲解下它的特性。 创建father.sh,内容如下: #!/bin/bas
? 原创: 铲子哥 搜狗测试 今天 shell编程的时候,往往不会把所有功能都写在一个脚本中,这样不太好维护,需要多个脚本文件协同工作.那么问题来了,在一个脚本中怎么调用其他的脚本呢?有三种方式,分别 ...
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
centos shell编程4[分发系统] 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要 ...
- python调用脚本或shell的方式
python调用脚本或shell有下面三种方式: os.system()特点:(1)可以调用脚本.(2)可以判断是否正确执行.(3)满足不了标准输出 && 错误 commands模块特 ...
- 使用redis调用lua脚本的方式对接口进行限流
java端实现: //初始化一个redis可执行的lua DefaultRedisScript<List> defaultRedisScript = new DefaultRedisScr ...
- 详解:数据库名、实例名、ORACLE_SID、数据库域名、全局数据库名、服务名及手工脚本创建oracle数据库
数据库名.实例名.数据库域名.全局数据库名.服务名 , 这是几个令很多初学者容易混淆的概念.相信很多初学者都与我一样被标题上这些个概念搞得一头雾水.我们现在就来把它们弄个明白. 一.数据库名 什么是数 ...
随机推荐
- UEFI和Legacy及UEFI+Legacy启动的区别
uefi和legacy是两种不同的引导方式,uefi是新式的BIOS,legacy是传统BIOS.你在UEFI模式下安装的系统,只能用UEFI模式引导:同理,如果你是在Legacy模式下安装的系统,也 ...
- 原生Ajax XMLHttpRequest对象
一.Ajax请求 - 现在常见的前后端分离项目中,一般都是服务器返回静态页面后浏览器加载完页面,运行script中的js代码,通过ajax向后端api发送异步请求获取数据,然后调用回调函数,将数据添加 ...
- openstack搭建之-基础服务配置(7)
基础环境准备,所需服务器及说明 172.16.2.51 base.test.com 基础服务节点 172.16.2.52 ctrl.test.com 控制节点 172.16.2.53 ...
- python的设计原则及设计模式
python的设计原则及设计模式 七大设计原则 单一职责原则 [SINGLE RESPONSIBILITY PRINCIPLE] 一个类负责一项职责. 里氏替换原则 [LISKOV SUBSTITUT ...
- Messenger更改系统语言以后无法登陆,提示“初始设置被修改”
在安装messenger机器上使用SQL management studio打开数据库,链接YCD的数据库,找到dbo.Dic_Defaults的表,编辑打开以后找到“CultureInfo”两项,删 ...
- 一、rollup
参考:reduxreach-routerrollup-starter-librollup-starter-approller-clicreate-react-library 一.安装 npm inst ...
- Oracle SQLULDR2 以及 SQLLDR 进行导入导出的功能说明
Study From http://blog.itpub.net/28291944/viewspace-2142187/ 自己尝试了下 可以实现. 下载完sqluldr2,文件夹内容如下:sqluld ...
- HDU 3518 Boring counting
题目:Boring counting 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3518 题意:给一个字符串,问有多少子串出现过两次以上,重叠不能算两次 ...
- 【XSY3154】入门多项式 高斯消元
题目大意 给你一个 \(n\times n\)的矩阵 \(A\),求次数最小且最高次项为 \(1\) 的多项式 \(F(x)\),满足 \(F(A)=0\). 所有操作都对 \(p\) 取模. \(n ...
- mysql 设置允许重试,批量更新
jdbc:mysql://ip:port/base?allowMultiQueries=true&autoReconnect=true 在mybatis中批量更新 需要在mysql的url上设 ...