9.15 Parse while splitting a string

 

Parse a string as a numerical value of appropriate type during splitting it.
Find courses that no students select according to Course table and SelectCourse table. In the SelectCourse table, one student may select multiple courses, which are separated by comma. Below are parts of the two tables:
Course:

ID NAME TEACHERID
1 Environmental protection and … 5
2 Mental health of College Students 1
3 Computer language Matlab 8
4 Electromechanical basic practice 7
5 Introduction to modern life science 3
6 Modern wireless communication system 14

SelectCourse:

ID STUDENTID COURSE
1 59 2,7
2 43 1,8
3 52 2,7,10
4 44 1,10
5 37 5,6
6 57 3

s.split() function works with @p option to parse members of the result sequence after string splitting as appropriate types.

SPL script:

A
1 =connect(“db”)
2 =A1.query(“select * from Course”)
3 =A1.query@x(“select * from SelectCourse”)
4 =A3.union(COURSE.split@cp())
5 =A2.(ID)
6 =A2(A5.pos([A5,A4].diff()))

A1 Connect to the database.
A2 Import Course table.
A3 Import SelectCourse table.
A4 split()function adds @p and @c options to split COURSE value in SelectCourse table with comma and parse it as an integer. union() function calculates union of sequences of courses.
A5 Get IDs of all courses.
A6 Use diff() function to calculate the difference of the sequence of course IDs in Course table and that in SelectCourse table, which are courses that no students select, and then locate corresponding records in A5 and get it in A2.

Execution result:

ID NAME TEACHERID
1 Fundamentals of economic management 21