|
|
1.
create table test1
(
col1 number
)
;
2.insert into test1(col1) values(4,1,5,6);
commit;
3.
declare
cursor get_express is
select e.col1 || f.col1 || e.col2 || f.col2 || e.col3||f.col3 || e.col4 express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
union
select '(' || e.col1 || f.col1 || e.col2 || ')' || f.col2 || e.col3||f.col3 || e.col4 express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
union
select '(' || e.col1 || f.col1 || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
union
select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
union
select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3 ||f.col3 || e.col4 || ')'express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
union
select e.col1 || f.col1 || e.col2 || f.col2 || '('|| e.col3 ||f.col3 || e.col4 || ')'express
from (
select *
from (select a.col1 col1,
b.col1 col2,
c.col1 col3,
d.col1 col4
from (select col1 col1,rownum row1 from test1) a,
(select col1 col1,rownum row1 from test1) b,
(select col1 col1,rownum row1 from test1) c,
(select col1 col1,rownum row1 from test1) d
where a.row1 <> b.row1
and a.row1 <> c.row1
and a.row1 <> d.row1
and b.row1 <> c.row1
and b.row1 <> d.row1
and c.row1 <> d.row1
) )e,
(
select distinct
c1.col1 col1,
c2.col1 col2,
c3.col1 col3
from test2 c1,
test2 c2,
test2 c3,
test2 c4
) f
;
vsql varchar2(200);
vexpress varchar2(200);
vresult number := 1;
begin
open get_express;
fetch get_express into vexpress;
while get_express%found loop
Begin
EXECUTE IMMEDIATE 'select ' || vexpress || ' from dual' into vresult;
exception
when others then
dbms_output.put_line('wrong express:' || vexpress);
end ;
if vresult = 24 then
dbms_output.put_line(vexpress);
close get_express;
return;
end if;
fetch get_express into vexpress;
end loop;
close get_express;
end;
适用于一个括号 |
|