Home » SQL & PL/SQL » SQL & PL/SQL » Return defined column size of varchar and varchar2 data types
Return defined column size of varchar and varchar2 data types [message #679329] Fri, 21 February 2020 15:31 Go to next message
jdbeyler
Messages: 1
Registered: February 2020
Junior Member
I want to write a query that returns the defined size of a varchar and/or varchr2 data type. Example: I defined a varchar2 column as column_name1 varchar2(40)
I insert 'abcde' into that column, I want to write a query that returns the defined length of 40. I then want to evaluate that returned result against a defined integer variable that is set to a value of 40.

What is the best way to write this query. Note: I am most familiar with SQL Server and not sure how to accomplish this in PL/SQL in an Oracle environment.
Re: Return defined column size of varchar and varchar2 data types [message #679330 is a reply to message #679329] Fri, 21 February 2020 19:17 Go to previous messageGo to next message
BlackSwan
Messages: 26701
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum

Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read

PL/SQL is a programming language. You should be able to meet your requirements with only plain SQL.

DESC USER_TAB_COLUMNS
Re: Return defined column size of varchar and varchar2 data types [message #679333 is a reply to message #679329] Sat, 22 February 2020 08:27 Go to previous messageGo to next message
EdStevens
Messages: 1206
Registered: September 2013
Senior Member
This has all the earmarks of a mis-guided attempt to solve some other problem. Step back a moment from ANY proposed technical solution and describe the business problem you are trying to solve. Explain WHY you want to know the defined size of a column and what you will do with that information when you have it.
Re: Return defined column size of varchar and varchar2 data types [message #679341 is a reply to message #679333] Mon, 24 February 2020 05:55 Go to previous message
Bill B
Messages: 1950
Registered: December 2004
Senior Member
See the view ALL_TAB_COLUMNS. All the information is in there.
select *
from all_tab_columns
where owner = 'SCHEMA_NAME'
and table_name = 'MY_TABLE'
order by column_id;
Previous Topic: Tab Delimited
Next Topic: Single update to get one column value using another column value
Goto Forum:
  


Current Time: Wed May 27 01:31:13 CDT 2020