简体   繁体   English

Oracle SQL,在select语句中获取长度更大的varchar2列

[英]Oracle SQL, get varchar2 column with greater length in select statement

I have a varchar2(8) column in a table, and I want to convert it to varchar2(100) in the select statement (ie I don't want to to call an "alter table" afterwards).* Is it possible?我在表中有一个 varchar2(8) 列,我想在 select 语句中将它转换为 varchar2(100)(即我不想在之后调用“alter table”)。* 这可能吗? Is there some function like "to_varchar2(x, 100)"?有没有像“to_varchar2(x, 100)”这样的函数?

(*) the reason is that I need to use the column in a "model" statement, where there will be additional identifiers that are longer. (*) 原因是我需要在“模型”语句中使用该列,其中会有更长的附加标识符。 I don't want to create an intermediate table and use "alter table" to change the varchar2 length.我不想创建一个中间表并使用“alter table”来更改 varchar2 长度。 Example:例子:

  select date, mystringvariable r, somenumber v from MyTable
  model
  unique single reference
  return updated rows   
  partition by(date) dimension by(r) measures(v)
  rules upsert automatic order ( 
  v['too_long_identifier']  = v['X1']
  );

     Error at line 5:

     ORA-12899: value too large for column ??? (actual: 19, maximum: 8)
          partition by(date) dimension by(r) measures(v)
                                          ^

不确定您需要在查询中的哪个位置执行此操作(我没有要测试的数据),但是如果str是数据类型为varchar2(8)任何表达式并且您需要将其重新转换为varchar2(100) ,则可以使用cast功能:

 .... cast(str as varchar2(100)) ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM