选择字段varchar大小受限的记录

时间:2013-02-18 18:12:29

标签: sql oracle

可以执行一个带有字符串列数限制的字符串的选择吗?例如,我有一个包含10个和15个字符的记录的列,我只想要10个字符。

2 个答案:

答案 0 :(得分:3)

使用substr。此处测试的示例: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

结果集:

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

答案 1 :(得分:2)

你的问题很模糊。你是说一个表中的字段允许X字符(15,30,无论如何),你只想要那些长度为10的记录?如果是这样......以下内容将替换表名和yourField代替系统中的值。

Select * from tableName where length(yourField) = 10

但是,如果您在所有表格列的长度为10之后,请查看All_tab_cols视图以获取表格/列和字段大小的列表。