调用脚本的方式自动的创建或者是更新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数据库
数据库名.实例名.数据库域名.全局数据库名.服务名 , 这是几个令很多初学者容易混淆的概念.相信很多初学者都与我一样被标题上这些个概念搞得一头雾水.我们现在就来把它们弄个明白. 一.数据库名 什么是数 ...
随机推荐
- 【Beta阶段】展示博客
Beta阶段展示博客 blog software buaa 1.团队成员简介 Email:qianlxc@126.com Free time:8:00 7:00 a.m ~ 11:00 12:00p. ...
- Merge Sort(Java)
public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextI ...
- ConcurrentHashMap 与 Hashtable
粘贴复制于:https://blog.csdn.net/lzwglory/article/details/79978788 集合是编程中最常用的数据结构.而谈到并发,几乎总是离不开集合这类高级数据结构 ...
- Kubernetes的本质
在前面的四篇文章中,我以 Docker 项目为例,一步步剖析了 Linux 容器的具体实现方式.通过这 些讲解你应该能够明白:一个“容器”,实际上是一个由 Linux Namespace.Linux ...
- 在一台计算机上运行两个或多个tomcat
有的时候我们需要在一台计算计算机上安装多个Tomcat,那我们该怎样配置呢? ## 1.配置思路: 在操作之前我们先启动一个Tomcat,看一下启动数据: 这里面有我们在环境变量中配置的CATALI ...
- Windows Server 2016激活方法+密钥+遇到的问题及解决办法(摘抄)
Windows Server 2016激活方法+密钥+遇到的问题及解决办法 2018年08月30日 13:47:34 Brozer 阅读数:28667 这两天公司准备部署Revit Server ...
- Django url (路由)
1.路由的基本使用 #url 是个函数,有四个参数,第一个参数要传正则表达式,第二个参数传函数内存地址,第三个传默认参数,第四个传路由别名 url(r'^yaopipqideneirong/art ...
- Python【第三篇】文件操作、字符编码
一.文件操作 文件操作分为三个步骤:文件打开.操作文件.关闭文件,但是,我们可以用with来管理文件操作,这样就不需要手动来关闭文件. 实现原理: import contextlib @context ...
- macOS Mojave待机耗电大
这很有可能是待机时依然链接网络导致的.如果不需要待机时链接网络可以执行 sudo pmset -a tcpkeepalive 0 恢复则执行 sudo pmset -a tcpkeepalive 1
- (五)qt资源文件
// 规则: :+添加的前缀/+文件名 ui->actionSave_as->setIcon(QIcon(":/new/Image/face.png"));