1

我有一个海外同事的 sql 语句,但是当我尝试运行它时弹出一个框,上面写着“输入替换变量”。我在里面放什么?我的同事说他们没有得到同一个盒子。是什么导致此消息?我在下面提供声明。任何帮助是极大的赞赏。

此外,第三行给出了一条消息,指出缺少右括号。

select SUBSTR(created_ts, 1, 7) as created_month, 
count(t1.id) as mops_created,
count(completed_ts <> '') as num_complete,
round(AVG(DATEDIFF(planning_complete_ts, created_ts)), 1) as average_created_to_planning_complete,
round(AVG(DATEDIFF(review_complete_ts, planning_complete_ts)), 1) as average_planning_complete_to_review_complete,
round(AVG(DATEDIFF(scheduling_complete_ts, planning_complete_ts)), 1) as average_planning_complete_to_scheduling_complete,
round(AVG(DATEDIFF(scheduled_ts, scheduling_complete_ts)), 1) as average_scheduled_for_x_days_out,
round(AVG(DATEDIFF(completed_ts, planning_complete_ts)), 1) as average_planning_complete_to_mop_complete,
round(AVG(planning_complete_num), 1) as average_num_times_planning_complete,
max(planning_complete_num) as max_planning_complete,
round(AVG(scheduling_complete_num), 1) as average_num_time_scheduled,
max(scheduling_complete_num) as max_scheduled_num
FROM
(select a.id, a.created_ts, a.scheduled_ts, work_start_ts, completed_ts
from TRAFFIC_ENG.DSIS_CC_MASTER as a 
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)) as t1
LEFT JOIN
(select a.id, max(c.orig_date) as review_complete_ts 
from 
                TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
                TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
                ON c.cc_master_id = a.id
                AND (c.cc_log_note_type_id = 8 OR c.note = 'Passed Review & submitted to Scheduling')
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id) as review_complete
ON review_complete.id = t1.id
LEFT JOIN
(
select a.id, min(c.orig_date) as planning_complete_ts 
from 
                TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
                TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
                ON c.cc_master_id = a.id
                AND (c.cc_log_note_type_id = 5 OR c.note = 'Submitted for Review')
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id

) as planning_complete
ON planning_complete.id = t1.id
LEFT JOIN
(
select a.id, (c.orig_date) as scheduling_complete_ts 
from 
                TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
                TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
                ON c.cc_master_id = a.id
                AND (c.cc_log_note_type_id = 7 OR c.note='Scheduled')
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as scheduling_complete
ON scheduling_complete.id = t1.id
LEFT JOIN
(
select a.id, count(c.orig_date) as planning_complete_num 
from 
                TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
                TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
                ON c.cc_master_id = a.id
                AND (c.cc_log_note_type_id = 5 OR c.note = 'Submitted for Review')
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id

) as planning_complete_num
ON planning_complete_num.id = t1.id
LEFT JOIN
(
select a.id, count(c.orig_date) as scheduling_complete_num
from 
                TRAFFIC_ENG.DSIS_CC_MASTER as a
INNER JOIN
                TRAFFIC_ENG.DSIS_CC_LOG_NOTE as c
                ON c.cc_master_id = a.id
                AND (c.cc_log_note_type_id = 7 OR c.note='Scheduled')
WHERE 
                a.created_ts >= '2013-01-01 00:00:00'
AND 
                a.status_cc_options_id NOT IN (810, 820)
GROUP BY a.id
) as scheduling_complete_num
ON scheduling_complete_num.id = t1.id

GROUP BY created_month
4

3 回答 3

2

你可以试试“SET DEFINE OFF”吗?

SQL> SET SERVEROUTPUT ON
SQL> SET DEFINE OFF
SQL> BEGIN
  2  DBMS_OUTPUT.PUT_LINE('A&B');
  3  END;
  4  /
A&B

PL/SQL procedure successfully completed.
于 2013-11-08T15:11:36.827 回答
2

正如@the_slk 所说,您可以使用set define off. 这将停止客户端将&字符串中的解释'Passed Review & submitted to Scheduling'为用户输入。听起来您可能正在使用 SQL Developer,但大部分 SQL*Plus 文档仍然是相关的。如果您使用的是不同的客户端,它可能更愿意将其关闭。

问题的第二部分,关于“缺少右括号”,看起来可能是因为您的代码中有空行。我认为您的客户将代码的每个部分(以空行分隔)视为单独的语句 - 我按照您的格式化方式进行了四种处理,但我不确定这是否与错误完全一致。默认情况下,SQL*Plus 会这样做。无论如何,实际上只有最后一个块正在执行,但如果它真的只是在运行'GROUP BY created_month',你会得到一个不同的错误,所以不管你的客户端是什么,它的行为似乎有点不同,或者你在这之后有更多的代码没有显示。

为了使 SQL*Plus 忽略空行,并将由空行分隔的代码视为一个块,set sqlblanklines on. SQL Developer 不使用该设置,并且无论如何都允许您使用空行,因此您的客户端可能是其他东西,并且将使用相同的命令或有自己的偏好。如果您与同事使用相同的客户端,请询问他们如何设置偏好。如果您的客户没有明显的方法来改变行为,那么从脚本中删除空行可能会解决这个问题。

于 2013-11-08T15:55:33.347 回答
1

它是“通过审核并提交给调度”中的 & 符号的存在,这通常向 sql 工具表明您想要替换该位置的变量。

如果您使用的是像 Toad 这样的图形工具,您可以在查看/选项/提示替换变量中将其关闭。

于 2013-11-08T15:18:31.643 回答