我想在我的 SQL 语句中使用 %TYPE 属性转换一个值。%TYPE 属性允许您在自己的声明中使用字段、记录、嵌套表、数据库列或变量的数据类型,而不是硬编码类型名称。
这有效:
insert into t1 select cast(v as varchar2(1)) from t2;
但我想
insert into t1 select cast(v as t1.v%TYPE) from t2;
Error starting at line 16 in command:
insert into t1 select cast(v as t1.v%TYPE) from t2
Error at Command Line:16 Column:37
Error report:
SQL Error: ORA-00911: Ongeldig teken.
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
可以这样做(或类似的事情)吗?
编辑:我想要实现的是:当 t2.v 太大时,我想截断它。我试图避免使用带有硬编码字段长度的 substr 。所以 cast(v as t1.v%TYPE) 而不是 substr(v,1,1)