1

是否可以进行选择以带来字符数受限的字符串列?例如,我有一列有 10 和 15 个字符的记录,我只想要 10 个字符。

4

2 回答 2

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
这是一个这是对 substr fn 的测试
这是一个这是对 substr fn 的另一个测试
于 2013-02-18T18:18:31.297 回答
2

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

Select * from tableName where length(yourField) = 10

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

于 2013-02-18T18:17:20.897 回答