Learn Teradata Indexing Techniques in this 2-Hour Video Course

tune2

Introduction

Teradata SQL lacks a built-in function to determine the ASCII code of a character. But fear not, for there exists a query workaround to this dilemma. This blog post will guide you through the process of using a straightforward SQL query in Teradata to find the ASCII code of a character.

The solution is as follows:

We use the Teradata SQL function CHAR2HEXINT to obtain a hexadecimal value for a character. Our objective is to convert this hexadecimal value to its decimal counterpart, which signifies the character’s ASCII code.

This SQL query accomplishes the task.

SELECT
CASE SUBSTRING(CHAR2HEXINT('B') FROM 3 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END * 16 +
CASE SUBSTRING(CHAR2HEXINT('B') FROM 4 FOR 1)
WHEN '0' THEN 0
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
WHEN '5' THEN 5
WHEN '6' THEN 6
WHEN '7' THEN 7
WHEN '8' THEN 8
WHEN '9' THEN 9
WHEN 'A' THEN 10
WHEN 'B' THEN 11
WHEN 'C' THEN 12
WHEN 'D' THEN 13
WHEN 'E' THEN 14
WHEN 'F' THEN 15
END

Using a CASE statement, the query extracts two hexadecimal digits with the SUBSTRING function and converts them to decimal values. It then calculates the character’s ASCII code by multiplying the first digit’s decimal value by 16 and adding the second digit’s decimal value.

Conclusion

Teradata SQL lacks a dedicated feature for determining the ASCII code of a given character. However, this blog post offers a straightforward and efficient workaround for this issue. By utilizing the CHAR2HEXINT function and performing basic arithmetic operations, you can effectively determine the ASCII code of any character within your Teradata SQL queries.

Why Teradata DBAs Should Prioritize Housekeeping the DBC AccessRights Table

admin3

As any experienced Teradata DBA will tell you, some tables in the Teradata dictionary (DBC) need housekeeping. But some customer sites that I have worked with ignore table DBC.AccessRights. If you have ever analyzed this table on a Teradata system, you will almost certainly spot two things quickly. Since this is a system table, altering …

Read more

Is Teradata Compression Worth Your Time and Effort?

tune3

Teradata DBMS offers various compression options to save disk space and improve performance. But, the cost of implementing the compression takes man-time. This article discusses the cost vs. benefit of compression and suggests carefully considering the compression setting when designing new or modifying existing tables.

Benefits of Organizing Stored Procedures into Chapters and Steps

sql3

I made organizing Stored Procedures into Chapters and Steps a principle. These separation points are marked by comments and variables used in performance and result logging. A step refers to a technical or conceptual task that cannot be further divided without losing the abstraction of Stored Procedures or the main task. Examples of a step …

Read more

How to Analyze Teradata Tables for Multivalue Compression: A Less Costly Method Using SHOW STATISTICS VALUES COLUMN ON

tune3

Learn how to analyze Teradata tables for Multivalue compression without costly operations by using the SHOW STATISTICS VALUES COLUMN statement. This method delivers excellent compression suggestions with less resource and time consumption than traditional approaches. However, it only works for columns with correct statistics, and the information used in the statement is challenging to extract.

Mastering Teradata Performance Optimization: Introduction to Partial Redistribution and Duplication

tune3

Introduction to Teradata Partial Redistribution and Partial Duplication Managing data skew is a critical aspect of optimizing Teradata performance. While table-level skew can typically be prevented by selecting an appropriate Primary Index, spool skew occurs during query execution – a common and often significant problem. Spool skew is a common issue when joining tables in …

Read more

DWHPro

Expert network for enterprise data platforms. Senior consultants, project teams built for your challenge — across Teradata, Snowflake, Databricks, and more.

📍Vienna, Austria & Jacksonville, Florida

Quick Links
Services Team Teradata Book Blog Contact Us
Connect
LinkedIn → [email protected]
Newsletter

Join 4,000+ data professionals.
Weekly insights on Teradata, Snowflake & data architecture.