我没有发现此问题有任何重复,但是如果有一个或多个,很抱歉-请使用链接发表评论。
问题是基本的,答案可能是基本的。如果我使用Perl执行数据库并对数据库执行操作,那么当涉及共享功能时,我应该负担哪种途径(Perl与SQL)?
功能,如- ,,和许多以及运算功能,例如是共同的系统。 LEN``IF/ELSE``CONCAT
LEN``IF/ELSE``CONCAT
该SQL语句加载有case块和其他可以用Perl复制的操作。因此,如果可以在Perl中实现相同的逻辑,是否值得重写?哪些条件会影响承担一个系统的负担并将其置于另一个系统上的决定?
SELECT DISTINCT s.id stu_id, stu_id.fullname stu_name, p.major1 major, p.minor1 minor, s.reg_hrs, NVL(st.cum_earn_hrs,0) ttl_hrs, p.adv_id curr_adv_id, adv_id.fullname curr_adv_name, CASE WHEN (p.adv_id <> 35808 AND p.major1 = 'NS') THEN (1165) WHEN (p.adv_id = 35808 AND p.major1 = 'NS') THEN (35808) WHEN (p.adv_id = 9179 AND p.major1 = 'DART') THEN (9179) WHEN (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24) THEN (70897) WHEN (p.major1 IN ('CDSC','CDSD')) THEN (52125) WHEN (p.major1 IN ('CA','CB')) THEN (24702) WHEN (p.minor1 = 'NURS') THEN (51569) WHEN (p.major1 = 'LEG') THEN (13324) WHEN (p.major1 = 'CC') THEN (73837) WHEN (p.major1 = 'CCRE') THEN (1133) WHEN ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I')) OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24)) OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG')) OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0)) OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0))) THEN (9238) ELSE (p.adv_id) END new_adv_id, CASE WHEN (p.adv_id <> 35808 AND p.major1 = 'NS') THEN ('Deborah') WHEN (p.adv_id = 35808 AND p.major1 = 'NS') THEN ('Veronica') WHEN (p.adv_id = 9179 AND p.major1 = 'DART') THEN ('Stella') WHEN (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24) THEN ('Lisa') WHEN (p.major1 IN ('CDSC','CDSD')) THEN ('Joanne') WHEN (p.major1 IN ('CA','CB')) THEN ('Barbara') WHEN (p.minor1 = 'NURS') THEN ('Karen') WHEN (p.major1 = 'LEG') THEN ('Nancy') WHEN (p.major1 = 'CC') THEN ('Alberta') WHEN (p.major1 = 'CCRE') THEN ('Naomi') WHEN ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I')) OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24)) OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG')) OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0)) OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0))) THEN ('Staff') ELSE (adv_id.fullname) END new_adv_name, CASE WHEN (p.adv_id <> 35808 AND p.major1 = 'NS') THEN ('NS majors not assigned to Veronica go to Debbie') WHEN (p.adv_id = 35808 AND p.major1 = 'NS') THEN ('NS majors stay with Veronica') WHEN (p.adv_id = 9179 AND p.major1 = 'DART') THEN ('DART majors stay with Stella') WHEN (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24) THEN ('RT-RESP minors go to Lisa') WHEN (p.major1 IN ('CDSC','CDSD')) THEN ('CDSC-CDSD majors go to Joanne') WHEN (p.major1 IN ('CA','CB')) THEN ('CA-CB majors go to Barbara') WHEN (p.minor1 = 'NURS') THEN ('NURS minors go to Karen') WHEN (p.major1 = 'LEG') THEN ('LEG majors go to Nancy') WHEN (p.major1 = 'CC') THEN ('CC majors go to Alberta') WHEN (p.major1 = 'CCRE') THEN ('CCRE majors go to Naomi') WHEN (p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I')) THEN ('Current advisor is inactive') WHEN (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24)) THEN ('Total credits for this student did not meet the advisor reqs for this major') WHEN (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG')) THEN ('This student did not attend '||si.prev_sess||si.prev_yr) WHEN ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE (stat <> 'A' OR max_stu <= 0))) THEN ('Current advisor is not advising students with this major') WHEN ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0)) THEN ('Current advisor is not advising students with this major') ELSE ('Student will stay with current advisor') END change_comm FROM stu_acad_rec s, prog_enr_rec p, OUTER stu_stat_rec st, id_rec stu_id, id_rec adv_id, sess_info si WHERE s.id = p.id AND s.id = st.id AND s.id = stu_id.id AND p.adv_id = adv_id.id AND s.yr = si.curr_yr AND s.sess = si.curr_sess AND s.reg_hrs > 0 AND s.reg_stat IN ('C','R') AND s.prog = 'UNDG' AND p.prog = 'UNDG' AND st.prog = 'UNDG' AND s.id NOT IN (3,287,9238,59999) {System test use IDs} INTO TEMP stu_list WITH NO LOG;
我将从性能和重用的角度来看待这个问题。
如果双方都尝试,您可能会发现其中一个比另一个要快得多-这将是一个首选的很好的指标。
如果要在多个地方重用某些查询,那么您可能希望将许多业务逻辑合并到查询中,因此您无需在GUI中进行复制。
(而且我不得不说,尽管不是严格地属于您的问题的一部分,但大多数情况下的逻辑看起来都可以在模式中建立一个好的模型,并用对某些关联表的普通联接来代替该情况)