As we know there is limitations in oracle datatype VARCHAR2 as it can only hold data upto 4000 characters.
If you are trying to build some string which is going just beyond 4000 character limit and you are not willing to use BLOB or LONG, then you can split them and put
it into two different fields with datatype varchar2(4000)
For Example :
Employee Table (emp) :
Now Lets understand the query below :
SELECT deptno, Substr(Sys_connect_by_path(path, '<>'), 3) hie
FROM (SELECT deptno,
ename,
path,
COUNT(1) over(PARTITION BY deptno) cnt,
Row_number() over(PARTITION BY deptno ORDER BY ename) r_num
FROM (SELECT deptno,
ename,
path,
SUM((Length(path) + 2) - 2) over(PARTITION BY deptno, ORDER BY ename) len
FROM (SELECT deptno,
ename,
Substr(Sys_connect_by_path(ename, '\\'), 3) path
FROM emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr))
WHERE len < 20)
WHERE r_num = cnt
START WITH r_num = 1
CONNECT BY PRIOR r_num + 1 = r_num
AND PRIOR deptno = deptno
If you are trying to build some string which is going just beyond 4000 character limit and you are not willing to use BLOB or LONG, then you can split them and put
it into two different fields with datatype varchar2(4000)
For Example :
Employee Table (emp) :
|
Now Lets understand the query below :
SELECT deptno, Substr(Sys_connect_by_path(path, '<>'), 3) hie
FROM (SELECT deptno,
ename,
path,
COUNT(1) over(PARTITION BY deptno) cnt,
Row_number() over(PARTITION BY deptno ORDER BY ename) r_num
FROM (SELECT deptno,
ename,
path,
SUM((Length(path) + 2) - 2) over(PARTITION BY deptno, ORDER BY ename) len
FROM (SELECT deptno,
ename,
Substr(Sys_connect_by_path(ename, '\\'), 3) path
FROM emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr))
WHERE len < 20)
WHERE r_num = cnt
START WITH r_num = 1
CONNECT BY PRIOR r_num + 1 = r_num
AND PRIOR deptno = deptno
No comments:
Post a Comment