Solution for Cut & Divide Text by ',' without Declare or Create Procedure

来源:互联网 发布:linux vi显示行数 编辑:程序博客网 时间:2024/05/30 02:24

with Core as  

(select co.course_number, 

(case  

when termid=((substr('&param1',1,4))-'1990') *100 

then substr('&param1',1,9) 

when termid=((substr('&param1',1,4))-'1990')*100+1 

then 'S1' 

when termid=((substr('&param1',1,4))-'1990')*100+2 

then 'S2' 

when termid=((substr('&param1',1,4))-'1990')*100+3 

then 'Q1' 

when termid=((substr('&param1',1,4))-'1990')*100+4 

then 'Q2' 

when termid=((substr('&param1',1,4))-'1990')*100+5 

then 'Q3' 

when termid=((substr('&param1',1,4))-'1990')*100+6 

then 'Q4' 

end)  

as Term, 

co.course_name,cc.section_number,cc.teacherid,cc.studentid from 

cc  join courses co 

on co.course_number=cc.course_number 

and termid>=UPPER( 

(select ((substr('&param1',1,4))-'1990')*100 from dual)) 

group by co.course_number, co.course_name,cc.section_number,cc.teacherid,cc.studentid, 

(case  

when termid=((substr('&param1',1,4))-'1990') *100 

then substr('&param1',1,9) 

when termid=((substr(&param1',1,4))-'1990')*100+1 

then 'S1' 

when termid=((substr('&param1',1,4))-'1990')*100+2 

then 'S2' 

when termid=((substr('&param1',1,4))-'1990')*100+3 

then 'Q1' 

when termid=((substr('&param1',1,4))-'1990')*100+4 

then 'Q2' 

when termid=((substr('&param1',1,4))-'1990')*100+5 

then 'Q3' 

when termid=((substr('&param1',1,4))-'1990')*100+6 

then 'Q4' 

end) 

order by course_number,section_number) 

SELECT COURSE_NUMBER,TERM,COURSE_NAME,SECTION_NUMBER,TEACHERNAME,STUDENT_NUMBER,StudentName,HOME_ROOM,FATHERPHONE,FATHEREMAIL,MOTHERPHONE,MOTHEREMAIL FROM 

( 

select course_number,Term,course_name,section_number,t.lastfirst as TeacherName,student_number,s.lastfirst as StudentName,s.home_room,MF.CUST_FATHERMOBILEPHONE AS FATHERPHONE,MF.CUST_FATHEREMAIL AS FATHEREMAIL,MF.CUST_MOTHERMOBILEPHONE AS MOTHERPHONE,MF.CUST_MOTHEREMAIL AS MOTHEREMAIL 

from students s 

join core c 

on s.id=c.studentid 

and s.enroll_status='0' 

join teachers t 

on t.id=c.teacherid 

join U_STUDENTSUSERFIELDS MF 

on MF.studentsdcid=s.dcid 

) 

WHERE  

course_NUMBER=UPPER('&param2') 

and 

( 

(case  

when   

'&param3' is null  

and 1=1 

then 1 end )=1 

or  

(case  

when  '&param3' is not null  

and 

( 

section_number in ( 

  select substr(regexp_substr(UPPER('&param3'), 

                            '[^,]+', 

                            1, 

                            level), 

              1 

              ,40) 

  from dual 

  connect by level <= regexp_count(UPPER('&param3'), 

                                   ',') + 1) 

) 

then 1 end)=1 

) 

order by course_number,section_number,studentname,student_number 

; 

0 0
原创粉丝点击