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. ruby -检查数据类型

    HashObj={","language"=>"zh","make"=>"Apple"," ...

  2. Linux环境安装MySQL数据库

    1.  下载mysql安装包 下载地址1:  http://www.mysql.com/   (mysql官网) 下载地址2:  http://mirrors.sohu.com/mysql/   (其 ...

  3. javascript中的对象,原型,原型链和面向对象

    一.javascript中的属性.方法 1.首先,关于javascript中的函数/“方法”,说明两点: 1)如果访问的对象属性是一个函数,有些开发者容易认为该函数属于这个对象,因此把“属性访问”叫做 ...

  4. 如何启动redis

    直接运行redis-server既可以启动redis

  5. ReadMe.md MarkDown file

    MarkDown 文件写法类似写Confluence page. http://blog.csdn.net/kaitiren/article/details/38513715

  6. Programming paradigms

    https://en.wikipedia.org/wiki/Aspect-oriented_programming Action Agent-oriented Array-oriented Autom ...

  7. leetcode Super Pow

    题目描述: superPow(int a, int[] b),b是一个int数组,每个元素都是正的个位数,组合起来表示一个正整数,例如b=[1,2,3]表示123,求解a^b mod 1337. 思路 ...

  8. aix磁盘分区挂载问题

    aix在进行磁盘分区挂载时,可能会报错

  9. Leetcode: Concatenated Words

    Given a list of words, please write a program that returns all concatenated words in the given list ...

  10. android案例一 电话拨号器

    效果图:   电话拨号器的核心原理:  意图   MainActivity代码:     private EditTest et_number; //加载一个布局 setContentView(R.l ...