亚洲城ca88唯一官方网


mac连接远程桌面,远程桌面连接无法验证您希望连接的计算机的身份

俄军接收首批铠甲防空系统,俄军舰载版铠甲弹炮结合防空系统2016年交付

存储过程之四,sqlserver带游标存储过程及调用函数

创建表:

1.囤积进度

储存进度之四—游标,存款和储蓄进度游标

 游标在蕴藏进度和函数中接纳。语法就如在寄放的SQL中。游标是只读的及不滚动的,只好在三个样子上进展遍历,不能够在记录之间自由进退,无法跳过好几记录,所以每一遍读完以往就应该移动到下一个笔录。游标必需在评释管理程序从前被声称,何况变量和规范必需在表明光标或管理程序以前被声称。

一、游标

  1、定义

   DECLARE 游标名称 CU昂CoraSOEvoque FOKuga 查询语句

   这一个讲话声Bellamy(Bellamy)个光标。也能够在子程序中定义四个光标,不过三个块中的每叁个光标必得有独一的名字。

   2、OPEN语句

    OPEN 游标名称

    那一个讲话展开先前声称的游标。

  3、FETCH语句

    FETCH 游标名称 INTO 变量[,  变量2] …

    这几个语句用钦定的开荒游标读取下一行(要是有下一行的话),何况发展游标指针。

   4、CLOSE语句

    CLOSE 游标名称

    那一个语句关闭先前开垦的游标。固然未被显眼地关闭,游标在它被声称的复合语句的终极被关闭。

二、实例

  表结构如下:

-- ----------------------------
-- Table structure for person
-- ----------------------------
DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of person
-- ----------------------------
INSERT INTO `person` VALUES ('1', '张三', '21', null);
INSERT INTO `person` VALUES ('2', '李四', '23', null);
INSERT INTO `person` VALUES ('3', '王五', '22', null);
INSERT INTO `person` VALUES ('4', 'zhangsan', '22', 'fdsafds');
INSERT INTO `person` VALUES ('8', 'zhangsan', '22', 'fdsafds');
INSERT INTO `person` VALUES ('9', 'zhangsan', '22', 'fdsafds');
INSERT INTO `person` VALUES ('10', 'wangwu', '23', 'password123');

  1、游标使用REPEAT 

DROP PROCEDURE IF EXISTS proc_test_cursor;
-- 所有人的年龄和
CREATE PROCEDURE proc_test_cursor(
    OUT total INT(11)
)
BEGIN
    DECLARE t INT DEFAULT 0;
    DECLARE done INT DEFAULT 0;
    DECLARE pcursor CURSOR FOR SELECT age FROM person;
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; -- 在 FETCH 语句中引用的游标位置处于结果表最后一行之后。
    SET total = 0;
    OPEN pcursor;
    REPEAT
        FETCH pcursor INTO t; 
        IF NOT done THEN -- 还有记录
            SET total = total + t;
        END IF;
    UNTIL done END REPEAT;
    CLOSE pcursor; 
END;

CALL proc_test_cursor(@total);
SELECT @total; 
SELECT SUM(age) FROM person; 

 

   一回询问的结果一律,则游标实施例行。

  2、游标使用while

DROP PROCEDURE IF EXISTS proc_test_cursor_while;
-- id小于某个值的年龄和
CREATE PROCEDURE proc_test_cursor_while(
    IN uid INT(11),
    OUT total INT(11)
)
BEGIN
    DECLARE t INT DEFAULT 0;
    DECLARE done INT DEFAULT 0;
    DECLARE pcursor CURSOR FOR SELECT age FROM person WHERE id < uid;
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; -- 在 FETCH 语句中引用的游标位置处于结果表最后一行之后。
    SET total = 0;
    OPEN pcursor; 
    WHILE(NOT done) DO
        FETCH pcursor INTO t;
        IF(NOT done) THEN
            SET total = total + t;    
        END IF;
  end WHILE;
    CLOSE pcursor; 
END;

CALL proc_test_cursor_while(3,@total);
SELECT @total;
SELECT SUM(age) FROM person where id < 3;

    两回询问的结果一致,则游标实践日常。

  3、游标中应用update语句

DROP PROCEDURE IF EXISTS proc_test_cursor_update;
-- 年龄大于多少的年龄加某个数
CREATE PROCEDURE proc_test_cursor_update( 
    IN avgage INT(11)
)
BEGIN
    DECLARE num INT DEFAULT 0;
    DECLARE t INT DEFAULT 0;
    DECLARE done INT DEFAULT 0;
    DECLARE pcursor CURSOR FOR SELECT id, age FROM person;
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; -- 在 FETCH 语句中引用的游标位置处于结果表最后一行之后。
    OPEN pcursor; 
    REPEAT
            FETCH pcursor INTO num, t; 
            IF NOT done THEN -- 还有记录    
                IF t > avgage THEN -- 年龄大于传入的年龄值
                    UPDATE person SET age = age + 5 where id = num;
                END IF;
            END IF;
    UNTIL done END REPEAT;
    CLOSE pcursor; 
END;

SET @uage = 20;
SELECT id, username, age FROM person where age > @uage;
CALL proc_test_cursor_update(@uage); 
SELECT id, username, age FROM person where age > @uage;

    五回询问的结果相同,则游标推行常规。

复制代码 代码如下:
CREATE OR REPLACE PROCEDURE PROCSENDEMAIL(P_TXT VARCHAR2,
P_SUB VARCHAR2,
P_SENDOR VARCHAR2,
P_RECEIVER VARCHAR2,
P_SERVER VARCHAR2,
P_ca661亚洲城,PORT NUMBER DEFAULT 25,
P_NEED_SMTP INT DEFAULT 0,
P_USER VARCHAR2 DEFAULT NULL,
P_PASS VARCHAR2 DEFAULT NULL,
P_FILENAME VARCHAR2 DEFAULT NULL,
P_ENCODE VARCHAR2 DEFAULT ‘bit 7’)
AUTHID CURRENT_USER IS

ca661亚洲城 1ca661亚洲城 2

CREATE PROCEDURE [dbo].[pro_init_dzz_dy_exception] AS
DECLARE @v_uuid VARCHAR (40) ;
DECLARE @v_operatetime datetime ;
DECLARE @v_userid VARCHAR (40) ;
DECLARE @v_zjhm VARCHAR (30) ;
DECLARE @v_csrq Date ;
DECLARE @v_rdsj Date ;
DECLARE @v_zzsj Date ;
DECLARE @v_idcardmult VARCHAR (1);
DECLARE @v_idcardvalidity VARCHAR (1) ;
DECLARE @v_subzjhmstr VARCHAR (50) ;
DECLARE @v_csrqstr VARCHAR (50) ;
DECLARE @dbname VARCHAR (100) ;
DECLARE @insertSqlStrStart VARCHAR (5000) ;
DECLARE @insertSqlStrMiddle VARCHAR (5000) ;
DECLARE @insertSqlStrEnd VARCHAR (5000) ;
DECLARE @insertSqlStr VARCHAR (5000) ;
DECLARE @querysql VARCHAR (5000) ;
DECLARE @deletesql VARCHAR (5000) ;
DECLARE @yearInterval INT ;
DECLARE @mm INT ; --DECLARE v_all_dy sys_refcursor;
--DECLARE @v_dy_info TABLE T_DZZ_DY_EXCEPTION_INFO_TEMP;
DECLARE allSche CURSOR FOR SELECT
    schemaname
FROM
    s_qkdzzinfo ;
BEGIN

--清空异常信息表
SET @deletesql = 'delete from t_dzz_dy_exception_info';
BEGIN
    TRAN ; EXEC (@deletesql) ; COMMIT TRAN ;

SET @insertSqlStrStart = 'insert into t_dzz_dy_exception_info 
                         (uuid,dzz_dy_id,datatype,errorlevel,errortype,operatetime) 
                         values(' ;
SET @insertSqlStrEnd = ')' ; OPEN allSche FETCH NEXT
FROM
    allSche INTO @dbname ;
WHILE (@@FETCH_STATUS = 0)
BEGIN

--SET @querysql = 'select * from ' + dbname + '.t_dy_info where delflag =1' ;
--FAST_FORWARD 
exec('DECLARE v_all_dy CURSOR FOR select userid, zjhm, csrq, rdsj, zzsj, idcardmult, idcardvalidity from '+@dbname+'.t_dy_info where delflag = 1 and dylb in (1,2) and dyzt = 1');
--DECLARE v_all_dy CURSOR FOR select REPLACE(userid, ' ', ''), REPLACE(zjhm, ' ', ''), csrq, rdsj, zzsj, idcardmult, idcardvalidity from @dbname.t_dy_info where delflag = 1;
OPEN v_all_dy ; FETCH NEXT
FROM
    v_all_dy INTO @v_userid, @v_zjhm, @v_csrq, @v_rdsj, @v_zzsj, @v_idcardmult, @v_idcardvalidity;
WHILE (@@FETCH_STATUS = 0)
BEGIN

SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @v_operatetime =  CONVERT(datetime, GETDATE(), 20);
SET @v_userid = REPLACE(@v_userid, ' ', '');
SET @v_zjhm = REPLACE(@v_zjhm, ' ', '')
SET @v_csrq = CONVERT (DATE,@v_csrq,23);
SET @v_rdsj = CONVERT (DATE,@v_rdsj,23);
SET @v_zzsj = CONVERT (DATE,@v_zzsj,23);
--SET @v_rdsj = @v_dy_info.rdsj ;
--SET @v_zzsj = @v_dy_info.zzsj ;
--SET @v_idcardmult = @v_dy_info.idcardmult ;
--SET @v_idcardvalidity = @v_dy_info.idcardvalidity ;
IF @v_zjhm IS NOT NULL
AND @v_csrq IS NOT NULL
BEGIN
SET @v_subzjhmstr = SUBSTRING (@v_zjhm, 7, 4) + SUBSTRING (@v_zjhm, 11, 2) + SUBSTRING (@v_zjhm, 13, 2) ;
SET @v_csrqstr = CONVERT (
    VARCHAR (100),
    CONVERT (
        DATE,
        CONVERT (VARCHAR(100), @v_csrq, 23),
        20
    ),
    112
)
IF @v_subzjhmstr != @v_csrqstr
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,1,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
IF @v_rdsj IS NOT NULL
AND @v_zzsj IS NOT NULL
BEGIN
SET @yearInterval = dbo.FUNC_getYearsToDates (@v_rdsj ,@v_zzsj) ;
SET @mm = dbo.FUNC_getMonthsToDates (@v_rdsj ,@v_zzsj) ;
IF (
    DateDiff(DAY, '1921-07-01' ,@v_rdsj) >= 0
    AND DateDiff(DAY, '1923-06-09' ,@v_rdsj) <= 0
)
OR (
    DateDiff(DAY, '1928-06-18' ,@v_rdsj) >= 0
    AND DateDiff(DAY, '1945-04-22' ,@v_rdsj) <= 0
)
OR (
    DateDiff(DAY, '1969-04-01' ,@v_rdsj) >= 0
    AND DateDiff(DAY, '1977-08-11' ,@v_rdsj) <= 0
)
BEGIN
IF DateDiff(DAY ,@v_zzsj ,@v_rdsj) != 0
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
ELSE

IF DateDiff(DAY, '1923-06-10' ,@v_rdsj) >= 0
AND DateDiff(DAY, '1927-04-26' ,@v_rdsj) <= 0
BEGIN
IF @yearInterval > 0
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
ELSE
BEGIN
IF @mm != 6
AND @mm != 3
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
END
ELSE

IF DateDiff(DAY, '1927-04-27' ,@v_rdsj) >= 0
AND DateDiff(DAY, '1928-06-17' ,@v_rdsj) <= 0
BEGIN
IF DateDiff(DAY ,@v_zzsj ,@v_rdsj) != 0
BEGIN
IF @mm != 3
AND @yearInterval != 0
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
END
ELSE

IF DateDiff(DAY, '1945-04-23' ,@v_rdsj) >= 0
AND DateDiff(DAY, '1956-09-14' ,@v_rdsj) <= 0
BEGIN
IF @mm != 6
AND @yearInterval != 0
AND @mm != - 1
AND @mm != 12 
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
ELSE
IF @yearInterval != 1
AND @yearInterval != 2
AND (@mm != 6 AND @yearInterval != 0)
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
ELSE
BEGIN
IF @yearInterval != 1
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,2,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END
END
IF @v_idcardvalidity IS NOT NULL
BEGIN
IF @v_idcardvalidity = 1
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,3,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END

IF @v_idcardmult IS NOT NULL
BEGIN
IF @v_idcardmult = 1 
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,4,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
END

IF @v_rdsj IS NOT NULL
AND @v_csrq IS NOT NULL
BEGIN
SET @yearInterval = dbo.FUNC_getYearsDifference (@v_csrq ,@v_rdsj) ;
IF @yearInterval < 19
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,1,5,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END
IF DateDiff(DAY ,@v_csrq ,@v_rdsj) < 0
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,2,6,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ;
END

END
IF @v_rdsj IS NOT NULL 
BEGIN
IF DateDiff(DAY, '1921-07-01' ,@v_rdsj) < 0
BEGIN
SET @v_uuid = REPLACE(NEWID(), '-', '') ;
SET @insertSqlStrMiddle = ',2,2,7,' ;
SET @insertSqlStr = @insertSqlStrStart + '''' +@v_uuid + '''' + ',' + '''' +@v_userid + '''' +@insertSqlStrMiddle +''''+cast(@v_operatetime as varchar)+''''+@insertSqlStrEnd ;
BEGIN
    TRAN ; EXEC (@insertSqlStr) ; COMMIT TRAN ; 
END
END
FETCH NEXT
FROM
    v_all_dy INTO @v_userid, @v_zjhm, @v_csrq, @v_rdsj, @v_zzsj, @v_idcardmult, @v_idcardvalidity;
END ; CLOSE v_all_dy ; DEALLOCATE v_all_dy ; FETCH NEXT
FROM
    allSche INTO @dbname ;
END ; CLOSE allSche ; DEALLOCATE allSche ;
END ;

积攒进度中游标是怎使用的

ALTER proc [dbo].[积攒进程名]
as
begin
declare 游标名字 cursor for select 列名 from 表名 where
条件–先证明游标指向查询出的结果,一列,恐怕多列都足以,条件自定
declare 变量名 varchar(400)–存款和储蓄取到的值
open 游标名 –开启游标
while @@FETCH_STATUS=0–取值
存储过程之四,sqlserver带游标存储过程及调用函数。begin
fetch next FROM 游标名 into

复制代码 代码如下:
/*
效果与利益:用oracle发送邮件
重要作用:1、扶持多收件人。
2、扶持汉语
3、扶助抄送给别人
4、协助胜出32K的附属类小部件
5、匡助多行正文
6、扶植多附属类小部件
7、扶助文件附属类小部件和二进制附属类小部件
8、支持HTML格式
8、支持
作者:suk
参数表达:
p_txt :邮件正文
p_sub: 邮件标题
p_SendorAddress : 发赠给外人邮件地址
p_ReceiverAddress :
接收地址,能够同时发送到多少个地方上,地址之间用”,”恐怕”;”隔断
p_EmailServer : 邮件服务器地址,能够是域名照旧IP
p_Port :邮件服务器端口
p_need_smtp:是或不是需求smtp认证,0意味无需,1表示须要
p_user:smtp验证须求的客商名
p_pass:smtp验证需求的密码
p_filename:附属类小部件名称,必得带有完整的门路,如”d:tempa.txt”。
能够有多少个附属类小部件,附属类小部件名称只看见用逗号或然分集团分隔
p_encode:附属类小部件编码转换格式,在那之中 p_encode=’bit 7′ 代表文本类型附件
p_encode=’base64′ 表示二进制类型附属类小部件
注意:
1、对于文本类型的附属类小部件,无法用base64的办法发送,不然出错
2、对于多少个附属类小部件只可以用一样种格式发送

1 1 create table tb1(
2 2 
3 3 id int ,
4 4 
5 5 name nvarchar(20)
6 6 
7 7 )

2.定义函数

变量名–那样就将游标指向下一行,获得的第一行值就传给变量了

–须求实施的操作,举例修改某表中的字段
update 表名
set 列名=值

*/
L_CRLF VARCHAR2(2) := UTL_TCP.CRLF;
L_SENDORADDRESS VARCHAR2(4000);
L_SPLITE VARCHAR2(10) := ‘++’;
BOUNDARY CONSTANT VARCHAR2(256) := ‘—–BYSUK’;
FIRST_BOUNDARY CONSTANT VARCHAR2(256) := ‘–‘ || BOUNDARY || L_CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256) := ‘–‘ || BOUNDARY || ‘–‘ ||
L_CRLF;
MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := ‘multipart/mixed;
boundary=”‘ ||
BOUNDARY || ‘”‘;
/* 以下部分是发送大二进制附属类小部件时用到的变量 */
L_FIL BFILE;
L_FILE_LEN NUMBER;
L_MODULO NUMBER;
L_PIECES NUMBER;
L_FILE_HANDLE UTL_FILE.FILE_TYPE;
L_AMT BINARY_INTEGER := 672 * 3; /* ensures proper format; 2016
*/
L_FILEPOS PLS_INTEGER := 1; /* pointer for the file */
L_CHUNKS NUMBER;
L_BUF RAW(2100);
L_DATA RAW(2100);
L_MAX_LINE_WIDTH NUMBER := 54;
L_DIRECTORY_BASE_NAME VARCHAR2(100) := ‘DIR_FOR_SEND_MAIL’;
L_LINE VARCHAR2(1000);
L_MESG VARCHAR2(32767);
/* 以上部分是出殡和埋葬大二进制附属类小部件时用到的变量 */
TYPE ADDRESS_LIST IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
MY_ADDRESS_LIST ADDRESS_LIST;
TYPE ACCT_LIST IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
MY_ACCT_LIST ACCT_LIST;

View Code

一.
CREATE FUNCTION [dbo].[FUNC_getMonthsToDates] (@v_rdsj DATE, @v_zzsj DATE) RETURNS INT AS
BEGIN

DECLARE @beginYear INT ;
DECLARE @endYear INT ;
DECLARE @beginMonth INT ;
DECLARE @endMonth INT ;
DECLARE @beginDay INT ;
DECLARE @endDay INT ;
DECLARE @beginBool INT ;
DECLARE @endBool INT ;
DECLARE @yearInterval INT ;
DECLARE @monthInterval INT ;
DECLARE @mm INT ;
SET @beginYear = DatePart(YEAR ,@v_rdsj) ;
SET @endYear = DatePart(YEAR ,@v_zzsj) ;
SET @beginMonth = DatePart(MONTH ,@v_rdsj) ;
SET @endMonth = DatePart(MONTH ,@v_zzsj) ;
SET @beginDay = DatePart(DAY ,@v_rdsj) ;
SET @endDay = DatePart(DAY ,@v_zzsj) ;
SET @yearInterval = @endYear - @beginYear ; --为1说明是当月最后一天喂0说明不是
SET @beginBool = datediff(
    MONTH ,@v_rdsj,
    dateadd(DAY, 1 ,@v_rdsj)
) ;
SET @endBool = datediff(
    MONTH ,@v_zzsj,
    dateadd(DAY, 1 ,@v_zzsj)
) ;
IF DateDiff(DAY ,@v_rdsj ,@v_zzsj) >= 0
BEGIN

IF (
    @yearInterval = 0
    OR @yearInterval = 1
)
BEGIN

IF (
    @endMonth < @beginMonth
    OR @endMonth = @beginMonth
    AND (
        (@endDay < @beginDay)
        AND (@beginBool = 0 AND @endBool = 0)
    )
)
BEGIN

SET @yearInterval = @yearInterval - 1;
END
SET @monthInterval = (@endMonth + 12) - @beginMonth ;
IF (
    @endDay < @beginDay
    AND (@beginBool = 0 AND @endBool = 0)
)
BEGIN

SET @monthInterval = @monthInterval - 1 ;
END
SET @monthInterval = @monthInterval % 12 ;
SET @mm = @yearInterval * 12 + @monthInterval ;
IF (@beginBool = 1 AND @endBool = 1)
BEGIN

SET @mm = @mm ;
END
ELSE

IF (
    @beginBool = 0
    AND @endBool = 1
    AND @endDay <= @beginDay
)
BEGIN

SET @mm = @mm ;
END
ELSE

IF (
    @beginBool = 0
    AND @endBool = 0
    AND @endDay = @beginDay
)
BEGIN

SET @mm = @mm ;
END
ELSE

BEGIN

SET @mm = -1 ;
END
END
ELSE

BEGIN

SET @mm = -1 ;
END
END
ELSE

BEGIN

SET @mm = -1 ;
END RETURN @mm ;
END

 

where (修改表中的列)=变量名

end
close 游标名–关闭游标

deallocate 游标名–释放游标
end
 

————————————-再次回到附属类小部件源文件所在目录或许名称————————————–
复制代码 代码如下:
FUNCTION GET_FILE(P_FILE VARCHAR2, P_GET INT) RETURN VARCHAR2 IS
–p_get=1 表示回去目录
–p_get=2 代表回去文件名
L_FILE VARCHAR2(1000);
BEGIN
IF INSTR(P_FILE, ”) > 0 THEN
–windows
IF P_GET = 1 THEN
L_FILE := SUBSTR(P_FILE, 1, INSTR(P_FILE, ”, -1) – 1);
ELSIF P_GET = 2 THEN
L_FILE := SUBSTR(P_FILE, – (LENGTH(P_FILE) – INSTR(P_FILE, ”,
-1)));
END IF;
ELSIF INSTR(P_FILE, ‘/’) > 0 THEN
–linux/unix
IF P_GET = 1 THEN
L_FILE := SUBSTR(P_FILE, 1, INSTR(P_FILE, ‘/’, -1) – 1);
ELSIF P_GET = 2 THEN
L_FILE := SUBSTR(P_FILE,

相关文章

No Comments, Be The First!
近期评论
    功能
    网站地图xml地图