Marco
Marco

Reputation: 33

selecting records with field varchar size restricted

it is possible to do a select that brings a string column with a restricted number of characters? For example, I have a column that has records with 10 and 15 characters, I want only has 10 characters.

Upvotes: 1

Views: 98

Answers (2)

mechanical_meat
mechanical_meat

Reputation: 169324

Use substr. Tested example here: http://sqlfiddle.com/#!4/9b800/1

create table t (v varchar(50));

insert into t values ('this is a test of the substr fn');
insert into t values ('this is another test of the substr fn');

select 
  substr(v,1,10) restricted_output, 
  v unrestricted_output
from t

Resultset:

RESTRICTED_OUTPUT    UNRESTRICTED_OUTPUT
this is a            this is a test of the substr fn
this is an           this is another test of the substr fn

Upvotes: 3

xQbert
xQbert

Reputation: 35323

Your question is a big vague. Are you saying a field in a table allows X characters (15,30, whatever) and you only want those records with a Length of 10? if so... the following would work substituting table name and yourField for the values in your system.

Select * from tableName where length(yourField) = 10

If however you're after all table columns having a length of 10. Look at All_tab_cols view for a list of table/columns and field sizes.

Upvotes: 2

Related Questions