我正在为学生和部门在plsql中使用FOR Loop,并将部门名称存储在用逗号分隔的日志表中,但是我在最后一个部门名称后面得到了多余的','怎么删除它?
For i IN
(select (DEPT_NAME) DeptName FROM TBL_DEPT WHERE PREV_DEPT_NAME =
lPrevDeptName)
LOOP
lNewDept := lNewDept || i.DeptName || ',';
...
.....
....
END LOOP;
最后我要用新的部门名称更新日志表,但是我在日志表中得到了“ IT,HR,Accounts”之类的结果,想在“ Accounts”之后删除多余的“'”
答案 0 :(得分:1)
RTRIM
:
lNewDept := rtrim(lNewDept, ',');
例如:
SQL> with test (lNewDept) as (select 'IT,HR,Accounts,' from dual)
2 select rtrim(lNewDept, ',') result
3 from test;
RESULT
--------------
IT,HR,Accounts
SQL>
答案 1 :(得分:0)
或者这样:
For i IN
(select (DEPT_NAME) DeptName FROM TBL_DEPT WHERE PREV_DEPT_NAME =
lPrevDeptName)
LOOP
if lNewDept is null then
lNewDept := i.DeptName
else
lNewDept := lNewDept || ',' ||i.DeptName;
end if;
...
.....
....
END LOOP;