project_id 和任务编号的每个组合都存在一行数据,但会抛出“找不到数据”错误。 SELECT into 会引发错误,但只有带有 where 子句的 select 才获取一行数据。 流程如下
`
PROCEDURE GET_TASK_ID(P_TASK_NUMBER_IN IN VARCHAR2,
P_PROJ_ID_IN NUMBER,
P_TASK_ID_OUT OUT NUMBER) IS
L_TASK_ID_OUT NUMBER;
BEGIN
G_PROC_NAME := 'GET_TASK_ID';
G_ERR_LOCATION := '10';
BEGIN
SELECT TASK_ID INTO L_TASK_ID_OUT
FROM PA_TASKS
WHERE PROJECT_ID =P_PROJ_ID_IN
AND TASK_NUMBER =P_TASK_NUMBER_IN
AND CHARGEABLE_FLAG = 'Y';
P_TASK_ID_OUT := L_TASK_ID_OUT;
我认为任务编号有换行符。
替换和翻译功能不适用于我的场景。请问这里有任何线索吗?
在程序之外,运行:
SELECT TASK_ID,
TASK_NUMBER,
DUMP(TASK_NUMBER)
FROM PA_TASKS
WHERE PROJECT_ID = :your_expected_project_id
AND TASK_NUMBER LIKE :your_expected_task_number || '%'
AND CHARGEABLE_FLAG = 'Y';
并且
DUMP
将显示任务编号中的字节值,让您查看值末尾是否有空格、回车符或换行符(分别为 ASCII 32、13、10)。
例如,如果您有尾随回车符,则可以使用以下方法将其删除:
UPDATE PA_TASKS
SET task_number = RTRIM(task_number, CHR(13)) -- Use CHR and the ASCII value
WHERE PROJECT_ID = :your_expected_project_id
AND TASK_NUMBER LIKE :your_expected_task_number || '%'
AND CHARGEABLE_FLAG = 'Y';
顺便说一句,您的过程可以使用列数据类型编写,无需中间变量或嵌套 PL/SQL 块:
PROCEDURE GET_TASK_ID(
P_TASK_NUMBER_IN IN PA_TASKS.TASK_NUMBER%TYPE,
P_PROJ_ID_IN IN PA_TASKS.PROJECT_ID%TYPE,
P_TASK_ID_OUT OUT PA_TASKS.TASK_ID%TYPE
)
IS
BEGIN
SELECT TASK_ID
INTO P_TASK_ID_OUT
FROM PA_TASKS
WHERE PROJECT_ID = P_PROJ_ID_IN
AND TASK_NUMBER = P_TASK_NUMBER_IN
AND CHARGEABLE_FLAG = 'Y';
END;