Row length of table in Oracle [message #637469] |
Mon, 18 May 2015 11:49 |
irfankundi786@yahoo.com
Messages: 269 Registered: February 2009 Location: pakistan
|
Senior Member |
|
|
is there any way to calculate the length of row...for example the emp table has the col empno,ename,sal i want to return length of empno + lenght of ename and the sal....how ?
|
|
|
|
|
Re: Row length of table in Oracle [message #637472 is a reply to message #637470] |
Mon, 18 May 2015 11:54 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
1* select avg_row_len from user_tables where table_name = 'EMP'
SQL> /
AVG_ROW_LEN
-----------
38
SQL> desc emp
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
[Updated on: Mon, 18 May 2015 11:55] Report message to a moderator
|
|
|
|
Re: Row length of table in Oracle [message #637474 is a reply to message #637473] |
Mon, 18 May 2015 12:08 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
how many bytes does NUMBER(4), VARCHAR2(10), VARCHAR2(9), NUMBER(4), DATE, NUMBER(7,2), NUMBER(7,2), & NUMBER(2) each consume?
then just add up the individual lengths
|
|
|
Re: Row length of table in Oracle [message #637475 is a reply to message #637474] |
Mon, 18 May 2015 12:17 |
irfankundi786@yahoo.com
Messages: 269 Registered: February 2009 Location: pakistan
|
Senior Member |
|
|
is there anyother way to calcute like lenght function or using cursor .....one anthoer thing i want to know that this is cursor
declare
--rec emp%rowtype;
cursor c1 is
select * from emp;
rec c1%rowtype;
begin
open c1;
loop
fetch c1 into rec;
dbms_output.put_line(rec.ename);
exit when c1%notfound;
end loop;
end;
in this curosr is there any method that rec.ename is mention but only rec is used to first display the empno,ename ,sal and so on.explicitely col name is not mentioned.
|
|
|
|
|
|
Re: Row length of table in Oracle [message #637479 is a reply to message #637478] |
Mon, 18 May 2015 13:12 |
irfankundi786@yahoo.com
Messages: 269 Registered: February 2009 Location: pakistan
|
Senior Member |
|
|
Micel..Plz look a this ,,is this posiblle.
is there anyother way to calcute like lenght function or using cursor .....one anthoer thing i want to know that this is cursor
declare
--rec emp%rowtype;
cursor c1 is
select * from emp;
rec c1%rowtype;
begin
open c1;
loop
fetch c1 into rec;
dbms_output.put_line(rec.ename);
exit when c1%notfound;
end loop;
end;
in this curosr is there any method that rec.ename is mention but only rec is used to first display the empno,ename ,sal and so on.explicitely col name is not mentioned.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Row length of table in Oracle [message #637563 is a reply to message #637521] |
Wed, 20 May 2015 05:15 |
|
jgjeetu
Messages: 373 Registered: July 2013 Location: www.Orafaq.com/Forum
|
Senior Member |
|
|
thanks buddy but listen what others say and seniors the most.
now coming to your question.
Length returns the number of characters in a string and Vsize returns number of bytes used to store the string. for ex:-
SQL> select vsize(sysdate) from dual
2 /
VSIZE(SYSDATE)
--------------
7
SQL> select length(sysdate) from dual
2 /
LENGTH(SYSDATE)
---------------
9
SQL> select sysdate from dual
2 /
SYSDATE
---------
20-MAY-15
SQL> select vsize(22.7) from dual
2 /
VSIZE(22.7)
-----------
3
SQL> select length(22.7) from dual
2 /
LENGTH(22.7)
------------
4
SQL> select vsize('ORAFAQ') from dual
2 /
VSIZE('ORAFAQ')
---------------
6
SQL> select length('ORAFAQ') from dual
2 /
LENGTH('ORAFAQ')
----------------
6
[Updated on: Wed, 20 May 2015 05:17] Report message to a moderator
|
|
|
Re: Row length of table in Oracle [message #637564 is a reply to message #637563] |
Wed, 20 May 2015 05:21 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
And these ones:
SQL> select length(systimestamp), vsize(systimestamp) from dual;
LENGTH(SYSTIMESTAMP) VSIZE(SYSTIMESTAMP)
-------------------- -------------------
33 13
SQL> select length(N'ORAFAQ'), vsize(N'ORAFAQ') from dual;
LENGTH(N'ORAFAQ') VSIZE(N'ORAFAQ')
----------------- ----------------
6 12
|
|
|