比如一个三位数192,192*2=384,192*3=576,这三个三位数正好取了1到9这9个数字,求出所以符合这个条件的数字。
其实这个题目是不可以用编程方法求出的,这样做只是为了提高编程技巧,不过我的程序效率不高,我希望看到高手写的程序以提高我的水平。
我用pl/sql求出另外3个数分别是219,273,327
希望大家贴出自己的求解方法,谢谢!
declare
type shuzi_type is table of number index by binary_integer;
shuzi shuzi_type;
ijk int;
begin
for i in 1..3 loop
shuzi(1):=i;
for j in 1..9 loop
if j=i then continue;end if;
if i>=3 and j>3 then exit;end if;
shuzi(2):=j;
for k in 1..9 loop
if k=i or k=j then continue;end if;
shuzi(3):=k;
ijk:=shuzi(1)*100+shuzi(2)*10+shuzi(3);
shuzi(4):=floor(ijk/50);
if shuzi(4)=shuzi(1) or shuzi(4)=shuzi(2) or shuzi(4)=shuzi(3) then continue;end if;
shuzi(5):=floor((ijk*2-shuzi(4)*100)/10);
if shuzi(5)=shuzi(1) or shuzi(5)=shuzi(2) or shuzi(5)=shuzi(3) or shuzi(5)=shuzi(4) then continue;end if;
shuzi(6):=mod(ijk*2,10);
if shuzi(6)=shuzi(1) or shuzi(6)=shuzi(2) or shuzi(6)=shuzi(3) or shuzi(6)=shuzi(4) or shuzi(6)=shuzi(5) then continue;end if;
shuzi(7):=floor(ijk*3/100);
if shuzi(7)=shuzi(1) or shuzi(7)=shuzi(2) or shuzi(7)=shuzi(3) or shuzi(7)=shuzi(4) or shuzi(7)=shuzi(5) or shuzi(7)=shuzi(6) then continue;end if;
shuzi(8):=mod(floor(ijk*3/10),10);
if shuzi(8)=shuzi(1) or shuzi(8)=shuzi(2) or shuzi(8)=shuzi(3) or shuzi(8)=shuzi(4) or shuzi(8)=shuzi(5) or shuzi(8)=shuzi(6) or shuzi(8)=shuzi(7) then continue;end if;
shuzi(9):=mod(ijk*3,10);
if shuzi(9)=shuzi(1) or shuzi(9)=shuzi(3) or shuzi(9)=shuzi(2) or shuzi(9)=shuzi(4) or shuzi(9)=shuzi(5) or shuzi(9)=shuzi(6) or shuzi(9)=shuzi(7) or shuzi(9)=shuzi(8) then continue;end if;
dbms_output.put_line(ijk);
end loop;end loop;end loop;
end;
其实这个题目是不可以用编程方法求出的,这样做只是为了提高编程技巧,不过我的程序效率不高,我希望看到高手写的程序以提高我的水平。
我用pl/sql求出另外3个数分别是219,273,327
希望大家贴出自己的求解方法,谢谢!
declare
type shuzi_type is table of number index by binary_integer;
shuzi shuzi_type;
ijk int;
begin
for i in 1..3 loop
shuzi(1):=i;
for j in 1..9 loop
if j=i then continue;end if;
if i>=3 and j>3 then exit;end if;
shuzi(2):=j;
for k in 1..9 loop
if k=i or k=j then continue;end if;
shuzi(3):=k;
ijk:=shuzi(1)*100+shuzi(2)*10+shuzi(3);
shuzi(4):=floor(ijk/50);
if shuzi(4)=shuzi(1) or shuzi(4)=shuzi(2) or shuzi(4)=shuzi(3) then continue;end if;
shuzi(5):=floor((ijk*2-shuzi(4)*100)/10);
if shuzi(5)=shuzi(1) or shuzi(5)=shuzi(2) or shuzi(5)=shuzi(3) or shuzi(5)=shuzi(4) then continue;end if;
shuzi(6):=mod(ijk*2,10);
if shuzi(6)=shuzi(1) or shuzi(6)=shuzi(2) or shuzi(6)=shuzi(3) or shuzi(6)=shuzi(4) or shuzi(6)=shuzi(5) then continue;end if;
shuzi(7):=floor(ijk*3/100);
if shuzi(7)=shuzi(1) or shuzi(7)=shuzi(2) or shuzi(7)=shuzi(3) or shuzi(7)=shuzi(4) or shuzi(7)=shuzi(5) or shuzi(7)=shuzi(6) then continue;end if;
shuzi(8):=mod(floor(ijk*3/10),10);
if shuzi(8)=shuzi(1) or shuzi(8)=shuzi(2) or shuzi(8)=shuzi(3) or shuzi(8)=shuzi(4) or shuzi(8)=shuzi(5) or shuzi(8)=shuzi(6) or shuzi(8)=shuzi(7) then continue;end if;
shuzi(9):=mod(ijk*3,10);
if shuzi(9)=shuzi(1) or shuzi(9)=shuzi(3) or shuzi(9)=shuzi(2) or shuzi(9)=shuzi(4) or shuzi(9)=shuzi(5) or shuzi(9)=shuzi(6) or shuzi(9)=shuzi(7) or shuzi(9)=shuzi(8) then continue;end if;
dbms_output.put_line(ijk);
end loop;end loop;end loop;
end;
解决方案 »
- Oracle触发器错误
- SQL查询not in,或是同一字段多个!=效率超低,怎样优化??
- why don't download resrouce on this site.
- 触发器中关于:old :new 得动态SQL问题! 一直没有解决 拜托大家帮忙看看哪里出了问题
- Oracle高手进来看看吧!
- oracle问题 ora-01461:只能向long列插入赋了值的长型数据
- trigger只能针对一个表吗?
- oracle中有像server一样的@@rowcount记录所选的记录数呢?rownum好像不行呀
- Oracle查询语句报错
- Oracle更新数据后,查询一次,数据就自动还原了
- 看看下面两个sql语句
- 菜鸟提问,关于insert问题
2 FROM (SELECT num, num || num * 2 || num * 3 numstr
3 FROM (SELECT LEVEL + 100 - 1 num FROM dual CONNECT BY LEVEL <= 900))
4 WHERE length(numstr) = 9 AND
5 instr(numstr,'1')>0 AND
6 instr(numstr,'2')>0 AND
7 instr(numstr,'3')>0 AND
8 instr(numstr,'4')>0 AND
9 instr(numstr,'5')>0 AND
10 instr(numstr,'6')>0 AND
11 instr(numstr,'7')>0 AND
12 instr(numstr,'8')>0 AND
13 instr(numstr,'9')>0; NUM NUMSTR
---------- --------------------------------------
192 192384576
219 219438657
273 273546819
327 327654981已用时间: 00: 00: 00.01
SQL>
[SYS@orcl] SQL>with t1 as(
2 select level c1 ,
3 level||level*2||level*3 c2
4 from dual
5 connect by level <= 999
6 ),t2 as(
7 select c1,c2
8 from t1
9 where c1 > 99
10 ),t3 as(
11 select c1,c2,count(distinct column_value)
12 from t2,
13 table(cast(multiset(
14 select substr(c2,level,1)
15 from dual
16 connect by level <= length(c2)) AS sys.odcivarchar2list))
17 where length(c2) = 9
18 group by c1,c2
19 having count(distinct column_value) = 9
20 )select c1
21 from t3
22 where instr(c2,0,1,1) = 0; C1
----------
192
219
273
327