sql存储过程算法
MSSQL执行 : exec proc_NAME
ORACLE :
begin
proc_NAME;
commit;
end;
1.求素数
MSSQL;
CREATE proc [dbo].[EXEC003] as
declare @num int;
begin
set @num = ;
while (@num > )
BEGIN
IF(@num % = )
BEGIN
PRINT(@NUM);
END
SET @num -= ;
END
end
ORACLE:
create or replace procedure EXEC003 as
List int := ;
begin while( List > ) loop
if mod(List,) = then
Dbms_Output.put_line(List);
end if;
List := List - ;
end loop;
end; --测试
begin exec003 ;
commit;
end;
2.费布拉切数列
MSSQL
alter proc Exec004
as
declare @num int;
declare @Sum int;
declare @min int;
declare @max int;
declare @curr int;
set @num = ;
set @min = ;
set @max = ;
set @curr = ;
set @Sum = ;
--、、、、、、、
begin
if( @num = )
begin
set @max = ;
end
else if (@num = )
begin
set @max = ;
end
else
begin
while ( @curr <= @num )
begin
set @Sum = @max + @min;
set @min = @max;
set @max = @Sum;
set @curr += ;
end
end
print( @max);
end
ORACLE
create or replace procedure Exec004
as
curr int := ;
max1 int := ;
min1 int := ;
sum1 int := ;
num int := ;
begin
if(num = ) then
begin
sum1 := ;
end;
elsif ( num = ) then
begin
sum1 := ;
end;
else
while( curr <= num ) loop
sum1 := max1 + min1;
min1 := max1;
max1 := sum1;
curr := curr + ;
end loop;
end if;
DBMS_OUTPUT.PUT_LINE(sum1);
end;
3.判断表是否10列,有10列则打出制定列数
MYYSQL
alter proc forEachData(@num int) as
declare @curr int;
declare @temId varchar();
begin
set @curr = ;
if( (select COUNT(*) from jcms_module_article ) > )
begin
print('this number gt 10');
while(@curr <@num)
begin
select @temId = m.Title from ( select ROW_NUMBER() OVER (ORDER BY Id) rn,Title from jcms_module_article t) m where m.rn = @curr;
print( Convert( varchar(), @curr) + ':' + @temId);
set @curr += ;
end
end
else
print('this number lt 10');
end
ORACLE
create or replace procedure forEachData(num in out int) as
curr int := ;
temValue varchar();
countNum int; begin
select count( *) into countNum from cod_biz_codes;
if( curr <= ) then
begin
Dbms_Output.put_line('is number gt 10'); while( curr <= num ) loop
select t.doc_spec into temValue from ( select row_number() over( order by doc_type) rn , DOC_SPEC from cod_biz_codes ) t where t.rn = curr ;
Dbms_Output.put_line( curr || ','|| temValue);
curr := curr + ;
end loop;
end;
else
DBMS_OUTPUT.put_line('is number lt 10');
end if;
end; /*
测试:
declare num int := 10;
begin
forEachData(num);
end; */
sql存储过程算法的更多相关文章
- 分页sql存储过程算法
/****** Object: StoredProcedure [dbo].[PRO_Pub_FenYe] Script Date: 08/04/2014 11:14:22 ******/ SET A ...
- PL/SQL存储过程编程
PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...
- SQL存储过程分页(通用的拼接SQL语句思路实现)
多表通用的SQL存储过程分页 案例一: USE [Community] GO /****** Object: StoredProcedure [dbo].[Common_PageList] Scrip ...
- SQL存储过程的调用及写法
调用函数: public class SqlProcess { ; public DataSet ReturnSet = null; public SqlDataAdapter adapter = n ...
- sql存储过程几个简单例子
导读:sql存储是数据库操作过程中比较重要的一个环节,对于一些初学者来说也是比较抽象难理解的,本文我将通过几个实例来解析数据库中的sql存储过程,这样就将抽象的事物形象化,比较容易理解. 例1: cr ...
- SQL存储过程生成顺序编码
一.第一种方式 USE [WJKC]GO/****** Object: StoredProcedure [dbo].[Address_GetCode1] Script Date: 2016/3 ...
- SQL 存储过程入门(事务)(四)
SQL 存储过程入门(事务)(四) 本篇我们来讲一下事务处理技术. 为什么要使用事务呢,事务有什么用呢,举个例子. 假设我们现在有个业务,当做成功某件事情的时候要向2张表中插入数据,A表,B表,我 ...
- 在SQL存储过程中给条件变量加上单引号
在SQL存储过程中给条件变量加上单引号,不加语句就会出问题,以下就是在存储过程中将条件where设置成了动态变化的,给where赋完值再和前面的语句拼接,再execute(SQL) ), )), )+ ...
- SQL存储过程概念剖析
一.SQL存储过程的概念,优点及语法 定义:将常用的或很复杂的工作,预先用SQL语句写好并用一个指定的名称存储起来, 那么以后要叫数据库提供与已定义好的存储过程的功能相同的服务时,只需调用execut ...
随机推荐
- react 写一个贪吃蛇
示例: 全部代码如下: snake.jsx import React, { Component } from 'react'; import PropTypes from 'prop-types'; ...
- WinRAR 5.40 & 4.20 & 3.93 的注册码 - rarreg.key
把下面的数据复制到“记事本”中,用文件名“rarreg.key”命名该文件,保存到WinRAR安装文件夹即完成注册. 以下4个Key随便选一个复制都可以. WinRAR 5.40 版Key,复制箭头中 ...
- python string method
嗯,学习其它语言没这样全练过,嘻嘻 //test.py 1 # -*- coding: UTF-8 -*- 2 3 str = "i am worker" 4 print str. ...
- 实验源码,DES,AES,RSA,椭圆曲线
https://pan.baidu.com/s/1CPA-bnLmcJR_AFsNImhUjQ
- node.js初识09
1.node_module文件夹 如果你的require中没有写./,那么Node.js将该文件视为node_modules目录下的一个文件. 2.package.json文件 如果使用文件夹来统筹管 ...
- Nginx性能调优
[调优]Nginx性能调优 一.Nginx优化配置 1.主配置文件优化:# vi /usr/local/nginx/conf/nginx.conf------------------------- ...
- Unity shader学习之屏幕后期处理效果之高斯模糊
高斯模糊,见 百度百科. 也使用卷积来实现,每个卷积元素的公式为: 其中б是标准方差,一般取值为1. x和y分别对应当前位置到卷积中心的整数距离. 由于需要对高斯核中的权重进行归一化,即使所有权重相加 ...
- RabbitMQ的使用场景
RabbitMQ的使用场景 1 大数据日志收集消息中间件应用场景 2 消息中间件在搜索系统DIH(伪实时)中的应用 伪实时的搜索系统: 后台系统:(作为生产者发送消息) ...
- scrapy 参考教程及安装
scrapy 参考教程及安装环境: win7/10 64bit, python 3.6.x教程: http://python.jobbole.com/86405/安装过程0. 预先安装 VC14 64 ...
- Spark核心RDD:combineByKey函数详解
https://blog.csdn.net/jiangpeng59/article/details/52538254 为什么单独讲解combineByKey? 因为combineByKey是Spark ...