Teradata TPT删除单引号的尾随句点或转义字符

时间:2018-05-31 13:51:23

标签: teradata

我有简单的TPT导出命令,因为你可以看到我试图从列中删除尾随句号

TRIM(尾随'。'来自PRTY_ID)

自" VARCHAR SelectStmt"从单引号开始我不能在" TRIM(尾随'来自PRTY_ID)和#34;

中使用单引号

有没有办法从select语句中删除singe-quote或以任何其他方式删除尾随句点。感谢。

DEFINE JOB EXPORT_DELIMITED_FILE
DESCRIPTION 'Export rows from a Teradata table to a delimited file'
(
    DEFINE SCHEMA FILE_SCHEMA
    (
        COL1 VARCHAR
    );

    DEFINE OPERATOR SQL_SELECTOR
    TYPE SELECTOR
    SCHEMA FILE_SCHEMA
    ATTRIBUTES
    (
        VARCHAR PrivateLogName = 'selector_log',
        VARCHAR TdpId = 'prod',
        VARCHAR LogonMech = 'LDAP',
        VARCHAR UserName = 'user1',
        VARCHAR UserPassword = 'XXXX',
        VARCHAR SelectStmt =  '  
            select TOP 100 
                trim ( 
                    cast ( 
                            ( 
                                trim(cast(cast(TRIM(trailing '.' from EMP_ID) AS CHAR(100))) 
                            ) 
                        as  CHAR(10000)) 
                )
             from DP_TRM.V_ANSWER_FACT ; ',
        VARCHAR ReportModeOn = 'Y'
    );

    DEFINE OPERATOR FILE_WRITER
    TYPE DATACONNECTOR CONSUMER
    SCHEMA *
    ATTRIBUTES
    (
        VARCHAR PrivateLogName = 'dataconnector_log',
        VARCHAR DirectoryPath = 'T:\Manjesh\Athena\Output\V_SURVEY_ANSWER_FACT\',
        VARCHAR FileName = 'V_SURVEY_ANSWER_FACT*.csv',
        VARCHAR Format = 'Delimited',
        VARCHAR IndicatorMode = 'N', 
        VARCHAR OpenMode = 'Write',
        VARCHAR TextDelimiter = '|'
    );

    APPLY TO OPERATOR (FILE_WRITER)
    SELECT * FROM OPERATOR (SQL_SELECTOR);
);

1 个答案:

答案 0 :(得分:0)

你可以通过将它加倍来将它像SQL中的字符串文字中的单引号一样转义:

VARCHAR SelectStmt =  '  
    select TOP 100 
        trim ( 
            cast ( 
                    ( 
                        trim(cast(cast(TRIM(trailing ''.'' from EMP_ID) AS CHAR(100))) 
                    ) 
                as  CHAR(10000)) 
        )
     from DP_TRM.V_ANSWER_FACT ; ',

但是为什么你要对CHAR进行多次CAST然后TRIM而不是直接CAST到VarChar?

并且EMP_ID可能被定义为十进制,并且由于默认格式Z(x)9.而添加了尾随句点,您可以将其转换为INTEGER,然后不需要TRIM。