如何获取在 teradata 的 table 模式中定义的列长度

How to get a column length defined in the table schema in teradata

我需要找出列值的长度与创建时定义的列长度之间的差异 table。

例如:我有一个 table 架构如下。

CREATE TABLE `employee` (
  `id` int(10) NOT NULL,
  `name` varchar(10) DEFAULT NULL,
  `subject` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) 

具有价值

id  name    subject 
1   Alex    maths   
2   Bob     maths   
3   Clark   science 
4   Dave    maths   

现在我需要输出为

id  name    subject len(name) remain_space 
1   Alex    maths    4           6
2   Bob     maths    3           7
3   Clark   science  5           5
4   Dave    maths    4           6

此处剩余 space 是使用公式 (10 - len(name)) 计算的,其中 10 是列 max.length =26=] 在创建 table 时定义。我如何在 Teradata 中实现这一点?

获取字符串长度的标准 SQL 函数名为 Char_Length:

10 - Char_Length(name)

如果您不想硬编码定义的 VarChar 长度:

RegExp_Substr(TYPE(name), '[0-9]+') - Char_Length(name)