我想在我的SQL語句中使用%TYPE屬性強制轉換一個值。 %TYPE屬性允許您在自己的聲明中使用字段,記錄,嵌套表,數據庫列或變量的數據類型,而不是對類型名稱進行硬編碼。Oracle Cast使用%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。所以強制轉換(v爲t1.v%TYPE)而不是substr(v,1,1)
'+ 1',恭喜達到'10k' :) –
@PeterLang - thanks * 8-)猜猜我最好去看看版主工具然後... –
@Alex這正是我所知道的試圖實現。當t2.v很大時,我想截斷它。我試圖避免使用具有硬編碼字段長度的substr。所以投(v作爲t1.v%TYPE)而不是substr(v,1,1) –