gpt4 book ai didi

sql - 一起使用 SQL 和 Perl - 哪些应该用于通用功能?

转载 作者:行者123 更新时间:2023-12-04 21:07:28 24 4
gpt4 key购买 nike

我没有发现这个问题的任何欺骗,但如果有一个或多个,我很抱歉 - 请用链接发表评论。

这个问题很基本,答案可能也是如此。如果我使用 Perl 来执行和操作数据库,当涉及共享函数时,我应该将负担放在哪个途径(Perl 与 SQL)上?

功能如 - 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 中复制这些逻辑。

(我不得不说,虽然严格来说不是你问题的一部分,但大部分案例逻辑看起来你可以在模式中建立一个很好的模型,并用正常连接替换案例到一些关联表)

关于sql - 一起使用 SQL 和 Perl - 哪些应该用于通用功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4493177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com