create  or  replace  function f_op (p_n1  number , p_op  varchar2 , p_n2  number )  return  number

as

begin

return  case  when p_op =  '+'  then p_n1 + p_n2

when p_op =  '-'  then p_n1 - p_n2

when p_op =  '*'  then p_n1 * p_n2

when p_op =  '/'  and p_n2<> 0  then p_n1 / p_n2

else  null

end ;

end f_op;

/

create  or  replace  procedure pro_241(p1  number , p2  number , p3  number , p4  number )  as

r_result  number  default  0 ;

begin

for r  in (

with t_num  as

( select  1  id ,p1  as n  from dual

union

select  2  id ,p2  as n  from dual

union

select  3  id ,p3  as n  from dual

union

select  4  id ,p4  as n  from dual),

t_op  as

( select  '+'  as o  from dual

union

select  '-'  as o  from dual

union

select  '*'  as o  from dual

union

select  '/'  as o  from dual)

select  distinct

a.n   as a,

o1.o  as o1,

b.n   as b,

o2.o  as o2,

c.n   as c,

o3.o  as o3,

d.n   as d

from t_num a, t_num b, t_num c, t_num d,

t_op  o1, t_op  o2, t_op  o3

where a.id  not  in (b.id, c.id, d.id)

and b.id  not  in (c.id, d.id)

and c.id <> d.id)  loop

r_result := f_op(f_op(f_op(r.a,r.o1,r.b),r.o2,r.c),r.o3,r.d);

if r_result=12  then

dbms_output.put_line( '((' ||r.a||r.o1||r.b|| ')' ||r.o2||r.c|| ')' ||r.o3||r.d);

end  if ;  --((a b) c) d

r_result := f_op(f_op(r.a,r.o1,r.b),r.o2,f_op(r.c,r.o3,r.d));

if r_result=12  then

dbms_output.put_line( '(' ||r.a||r.o1||r.b|| ')' ||r.o2|| '(' ||r.c||r.o3||r.d|| ')' );

end  if ;  --(a b) (c d)

end  loop ;

end ;

/

set serveroutput on;

exec pro_241( 32 , 13 , 3 , 17 );

24SQL的更多相关文章

  1. 30种oracle常见的等待事件说明

    1Buffer busy waits从本质上讲,这个等待事件的产生仅说明了一个会话在等待一个Buffer(数据块),但是导致这个现象的原因却有很多种.常见的两种是: 当一个会话视图修改一个数据块,但这 ...

  2. Oracle常见等待事件

    1Buffer busy waits从本质上讲,这个等待事件的产生仅说明了一个会话在等待一个Buffer(数据块),但是导致这个现象的原因却有很多种.常见的两种是: ·         当一个会话视图 ...

随机推荐

  1. iOS 面试题(四):block 什么时候需要构造循环引用 --转自唐巧

    问题 有没有这样一个需求场景,block 会产生循环引用,但是业务又需要你不能使用 weak self? 如果有,请举一个例子并且解释这种情况下如何解决循环引用问题. 答案 需要不使用 weak se ...

  2. Python开发【第十章】:I/O多路复用、异步I/O(综合篇)

    近期心得:国庆节放假再加上近期工作太忙,已经有半个月没更新博客了,程序更别说了,也没怎么去写,自己给自己着实放了个大假.谈谈感受的话,没有python的日子,每天看书.看电影.各种玩,还有爸妈伺候着, ...

  3. PHP服务器配置环境变量

    我们写的PHP应用程序,通常会分别在本地.开发.测试.RC.生产环境中运行,不同环境中全局变量各不相同.通常简单的部署做法是,每次部署到一个环境,都需要先修改对应的全局变量,然后再部署代码.如果部署频 ...

  4. ElasticSearch作为Windows服务启动

           由于公司服务器用的Windows服务器,所以你懂得…… 直接下载elasticsearch中文发行版.下载地址是:https://github.com/medcl/elasticsear ...

  5. C#利用微软库完成设备网络定位(经纬度-地址)

    public delegate void OnPositionChangedEventHandle(object sender, PositionChangedEventArgs e); public ...

  6. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  7. LinQ 简单使用

    LinQ: 1.LinQ to Sql类(NET Language Integrated Query (LINQ) ) LINQ定义了大约40个查询操作符,如select.from.in.where以 ...

  8. HTML5Canvas标签(https://developer.mozilla.org)

  9. C++之路进阶——P2022

    P2022 有趣的数 让我们来考虑1到N的正整数集合.让我们把集合中的元素按照字典序排列,例如当N=11时,其顺序应该为:1,10,11,2,3,4,5,6,7,8,9. 定义K在N个数中的位置为Q( ...

  10. Qt4.8.5在ARM9上的移植

    Qt4.8.5在ARM9开发板上的移植 以前移植过qtopia-embedded-2.2.0,俗称Qt/E,在早期的Qt框架中是使用X11桌面服务器系统,无法应用于嵌入式平台,为此产生了qtopia, ...