- 浏览: 21989 次
- 性别:
- 来自: 济南
最新评论
创建自增序列
CREATE SEQUENCE SEQname
INCREMENT BY 1
START WITH 1
MAXVALUE 99999999
CREATE or replace TRIGGER TRGname
BEFORE INSERT ON userinfo
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.customerid
FROM DUAL;
End;
CREATE or replace TRIGGER tr_trade
BEFORE INSERT ON tradeinfo
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.tid
FROM DUAL;
End;
CREATE or replace TRIGGER tr_type
BEFORE INSERT ON tradetype
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.transid
FROM DUAL;
End;
创建银行卡号
CREATE or replace TRIGGER card_id
BEFORE INSERT ON cardinfo
FOR EACH ROW
Begin
SELECT '1010 3576 '||lpad(to_char(trunc(dbms_random.value(0,9999))),4,'0')||' '||lpad(to_char(trunc(dbms_random.value(0,9999))),4,'0')
INTO :NEW.cardid
FROM DUAL;
End;
测试语句
insert into userinfo(customername,pid,telephone) values('王法英','370126199003092128','15253503967')
select * from userinfo
insert into cardinfo(savingid,openmoney,balance,password,customerid) values('定期',1,1,123456,2)
select * from cardinfo
select * from tradetype
insert into tradetype(transname) values('转账');
insert into tradetype(transname) values('存款');
insert into tradetype(transname) values('取款');
insert into tradetype(transname) values('手机缴费');
insert into cardinfo(savingid,openmoney,balance,customerid) values('定期',1,1,13);
insert into cardinfo(savingid,openmoney,balance,customerid) values('定期',1,1,14);
修改客户密码
update cardinfo set password='123456' where customerid=13
办理银行卡挂失
update cardinfo set isreportloss='是' where customerid=13
查询本周开户的卡号,显示该卡相关信息
select * from cardinfo where opendate>=sysdate-7 and opendate<=sysdate
查询本月交易金额最高的卡号
select cardid from tradeinfo where transmoney =
(select max(transmoney) from tradeinfo
where transdate>=to_date(to_char(sysdate,'yyyymm'),'yyyymm') and transdate<=sysdate)
查询挂失账号的客户信息
select * from userinfo where customerid in(
select customerid from cardinfo where isreportloss='是'
)
客户基本信息:v_userInfo
create or replace view v_userinfo as
select customerid 用户编号,customername 用户名,pid 身份证号,telephone 电话,address 地址
from userinfo;
select * from v_userinfo
银行卡信息:v_cardInfo
create or replace view v_cardinfo as
select cardid 银行卡号,curid 货币类型,savingid 存款类型,opendate 开户时间,openmoney 开户金额,
balance 余额,password 密码,isreportloss 是否挂失,customerid 客户编号
from cardinfo;
select * from v_cardinfo
银行卡交易信息:v_tradeInfo
create or replace view v_tradeinfo as
select tid 交易号,transdate 交易时间,tradetype.transname 交易类型,
transmoney 交易金额,transcardid 交易对象,remark 备注
from tradeinfo,tradetype where tradeinfo.transid=tradetype.transid;
select * from v_tradeinfo
查询、统计指定时间段内没有发生交易的账户信息
create or replace procedure user_no_trade(
overDate in date,
startDate in date
)
is
cursor cursor_test is select * from cardinfo where transdate>=startDate and transdate<=overDate
and cardid not in(
select distinct cardid from tradeinfo
);
row_test tradeinfo%rowtype;
begin
for row_test in cursor_test loop
dbms_output.put_line(row_test.cardid||'||'||row_test.curid||'||'||row_test.opendate||'||'||row_test.openmoney
||'||'||row_test.balance||'||'||row_test.isreportloss||'||'||row_test.custeomerid);
end loop;
end;
CREATE SEQUENCE SEQname
INCREMENT BY 1
START WITH 1
MAXVALUE 99999999
CREATE or replace TRIGGER TRGname
BEFORE INSERT ON userinfo
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.customerid
FROM DUAL;
End;
CREATE or replace TRIGGER tr_trade
BEFORE INSERT ON tradeinfo
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.tid
FROM DUAL;
End;
CREATE or replace TRIGGER tr_type
BEFORE INSERT ON tradetype
FOR EACH ROW
Begin
SELECT SEQname.NEXTVAL
INTO :NEW.transid
FROM DUAL;
End;
创建银行卡号
CREATE or replace TRIGGER card_id
BEFORE INSERT ON cardinfo
FOR EACH ROW
Begin
SELECT '1010 3576 '||lpad(to_char(trunc(dbms_random.value(0,9999))),4,'0')||' '||lpad(to_char(trunc(dbms_random.value(0,9999))),4,'0')
INTO :NEW.cardid
FROM DUAL;
End;
测试语句
insert into userinfo(customername,pid,telephone) values('王法英','370126199003092128','15253503967')
select * from userinfo
insert into cardinfo(savingid,openmoney,balance,password,customerid) values('定期',1,1,123456,2)
select * from cardinfo
select * from tradetype
insert into tradetype(transname) values('转账');
insert into tradetype(transname) values('存款');
insert into tradetype(transname) values('取款');
insert into tradetype(transname) values('手机缴费');
insert into cardinfo(savingid,openmoney,balance,customerid) values('定期',1,1,13);
insert into cardinfo(savingid,openmoney,balance,customerid) values('定期',1,1,14);
修改客户密码
update cardinfo set password='123456' where customerid=13
办理银行卡挂失
update cardinfo set isreportloss='是' where customerid=13
查询本周开户的卡号,显示该卡相关信息
select * from cardinfo where opendate>=sysdate-7 and opendate<=sysdate
查询本月交易金额最高的卡号
select cardid from tradeinfo where transmoney =
(select max(transmoney) from tradeinfo
where transdate>=to_date(to_char(sysdate,'yyyymm'),'yyyymm') and transdate<=sysdate)
查询挂失账号的客户信息
select * from userinfo where customerid in(
select customerid from cardinfo where isreportloss='是'
)
客户基本信息:v_userInfo
create or replace view v_userinfo as
select customerid 用户编号,customername 用户名,pid 身份证号,telephone 电话,address 地址
from userinfo;
select * from v_userinfo
银行卡信息:v_cardInfo
create or replace view v_cardinfo as
select cardid 银行卡号,curid 货币类型,savingid 存款类型,opendate 开户时间,openmoney 开户金额,
balance 余额,password 密码,isreportloss 是否挂失,customerid 客户编号
from cardinfo;
select * from v_cardinfo
银行卡交易信息:v_tradeInfo
create or replace view v_tradeinfo as
select tid 交易号,transdate 交易时间,tradetype.transname 交易类型,
transmoney 交易金额,transcardid 交易对象,remark 备注
from tradeinfo,tradetype where tradeinfo.transid=tradetype.transid;
select * from v_tradeinfo
查询、统计指定时间段内没有发生交易的账户信息
create or replace procedure user_no_trade(
overDate in date,
startDate in date
)
is
cursor cursor_test is select * from cardinfo where transdate>=startDate and transdate<=overDate
and cardid not in(
select distinct cardid from tradeinfo
);
row_test tradeinfo%rowtype;
begin
for row_test in cursor_test loop
dbms_output.put_line(row_test.cardid||'||'||row_test.curid||'||'||row_test.opendate||'||'||row_test.openmoney
||'||'||row_test.balance||'||'||row_test.isreportloss||'||'||row_test.custeomerid);
end loop;
end;
发表评论
-
关于Map常用的方法
2014-02-25 09:25 7471 将Map转换成List // key list List ... -
Effictive Java 读书笔记
2013-10-11 13:51 739Effictive Java 1 考虑用静 ... -
eclipseSSH整合
2013-02-25 16:16 6361 Exception loading sessions fr ... -
简单java ibatis
2012-12-24 13:50 0ibatis小巧,易上手,适合于小型项目开发。 其中对于引用的 ... -
自己做的Ajax小练习
2012-11-13 08:42 6351 关于Ajax三个方法的固定写法 <scri ... -
自己做的web练习
2012-11-12 19:54 579参见附件:service 与client -
struts2小知识点
2012-11-01 10:19 6511 默认的命名空间“ namespace="&qu ... -
2012-10-11 Hibernate杂碎
2012-10-11 18:35 5611 从Hibernate的参考手册中,我们基本可以总结出这样几 ... -
Hibernate BaseDao
2012-10-09 17:16 0package net.comtops.dao.impl; ... -
Hibernate 实现增删改
2012-10-09 16:53 675Configuration conf = null; S ... -
Hibernate 主键生成策略
2012-10-09 16:14 574此处我们只针对常用的数据库类型进行说明,其他的略过: 1 Or ... -
JSP一个正确的验证码
2012-09-27 15:13 659image.jsp页面 <%@ page conte ... -
SQL SERVER分页
2012-09-27 09:51 652分页方案一:(利用Not In和SELECT TOP分页) ... -
JDBC数据库连接
2012-09-10 16:11 502MySQL: String Driver="com ... -
oracle分页以及rownum、rowid的使用
2012-09-09 14:13 697分页存储过程: 1.根据ROWID来分,执行时间0.03秒 c ... -
ObjectOutputStream
2012-08-02 11:05 901要根据用户选择,向一个文件写一个类(Student)的实例,使 ... -
java
2012-07-30 14:45 354- 第一种情况: Comparator cmp = Col ... -
初始化块和构造器
2012-07-24 08:31 5811,构造器的语法格式 修饰符:public private,p ... -
黑马程序员:学习笔记第一天
2012-03-26 21:28 513android培训、java培训、期待与您交流! ------ ...
相关推荐
一键生成Oracle自增序列和触发器,方便Oracle sql的编写加快代码编写速度。
给大家分享MyBatis Oracle 自增序列的实现方法及mybatis配置oracle的主键自增长的方法,非常不错具有一定的参考借鉴价值,感兴趣的朋友一起看看吧
oracle 序列自增oracle
如何实现Oracle主键自增,通过写sequence和触发器,很全面,绝对帮你解决问题
Oracle使用序列创建自增字段,自增长列。
今天从oracle迁移数据到mysql碰到个需求:原先的主键字段需要改成mysql中的自增字段,而且原先数据的值不能变,以后新插入的值从原先数据最大的值开始自增。 解决办法: 构建环境: mysql> CREATE TABLE test -> ( ...
oracle 数据库主键自增脚本 --第一步,创建表 --第二步,创建自增序列 --第三步,创建触发器
oracle sqlldr导入带有自动增加的数据实例
插入数据时获取自增ID,使用序列,需要在插入数据时,自增字段插入序列下一个值
代码如下:create or replace Function GetInvitationNO(prev varchar2, num1 varchar2, num2 varchar2, sessionSetting varchar2) Return Varchar2 Authid Current_User Is PRAGMA AUTONOMOUS_TRANSACTION;...
本方法为使用SEQUENCE... 1、建立自增序列TEMP_TEST_IDADD,命名任意,从1开始,每次加1 CREATE SEQUENCE TEMP_TEST_IDADD INCREMENT BY 1 START WITH 1; 2、在表temp_test上建立触发器如下 CREATE OR REPL
用于Oracle的主键进行自增的办法,有触发器 和序列机制
在网上找的资料,oracle建表以后如何建自增序列和触发器。觉得比较实用,分享出来
ORACLE数据库中实现属性的自增,是通过序列和触发器来实现的,当给表中插入数据时触发触发器,触发器从序列中得到相应的数值放入相应的位置,这样实现属性的自增。
我用的是12c版本的,它有一个新特性,可以这样设置自增序列,在创建表是,把id设置为自增序列 create table t ( id number generated by default as identity (start with 1 increment by 1), name varchar2...
oracle设置主外键即主键序列自动增长
S2SH简单整合CRUD适合新手练手。jdk1.7,tomcat7.0。数据库Oracle。打包了简单的sql语句,包含了Oracle自增序列的建立。
Oracle中没有sqlserver中那么方便的自增序列,如果想要达到sqlserver中那种效果,也不是很麻烦,需要创建一个自增序列SEQUENCE,然后建一个触发器即可。 CREATE SEQUENCE emp_sequence INCREMENT BY 1 — ...
当向表中插入数据时,主键值自动加一. 实现方法1: 建立一个最小为1,最大为nomaxvalue的一个序列号会自动循环的序列 create sequence 序列名 increment by 1 start with 1 nomaxvalue nocycle; .......