Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Converting number to HEX value, part 1

Is there a piece of PL/SQL or function or group of functions where I can take a number between 1 and 1234567 and convert it into a HEX value?
I do not know of any built-ins in Oracle. However, a long time ago I stumbled into a package in the public domain that you can use. I have provided the source code below. I have used this package and I am publishing it here for your benefit without infringing on any copyright.
```create or replace package Lang_Integer as
/* The package is named loosely after a similar Java class,
java.lang.Integer; in addition, all public package functions
(except toRadixString() which has no Java equivalent) are named
after equivalent Java methods in the java.lang.Integer class.
*/

/* Convert a number to string in given radix.
Radix must be in the range [2, 16].
*/
pragma restrict_references (toRadixString, WNDS, WNPS, RNDS, RNPS);

/* Convert a number to binary string. */
function toBinaryString(num in number) return varchar2;
pragma restrict_references (toBinaryString, WNDS, WNPS, RNDS, RNPS);

/* Convert a number to hexadecimal string. */
function toHexString(num in number) return varchar2;
pragma restrict_references (toHexString, WNDS, WNPS, RNDS, RNPS);

/* Convert a number to octal string. */
function toOctalString(num in number) return varchar2;
pragma restrict_references (toOctalString, WNDS, WNPS, RNDS, RNPS);

/* Convert a string, expressed in decimal, to number. */
function parseInt(s in varchar2) return number;
pragma restrict_references (parseInt, WNDS, WNPS, RNDS, RNPS);

/* Convert a string, expressed in given radix, to number.
Radix must be in the range [2, 16].
*/
function parseInt(s in varchar2, radix in number) return number;
pragma restrict_references (parseInt, WNDS, RNDS);
end Lang_Integer;
/

create or replace package body Lang_Integer as
/* Takes a number between 0 and 15, and converts it to a string (character)
The toRadixString() function calls this function.

The caller of this function is responsible for making sure no invalid
number is passed as the argument.  Valid numbers include non-negative
integer in the radix used by the calling function.  For example,
toOctalString() must pass nothing but 0, 1, 2, 3, 4, 5, 6, and 7 as the
argument 'num' of digitToString().
*/
function digitToString(num in number) return varchar2 as
digitStr varchar2(1);
begin
if (num<10) then
digitStr := to_char(num);
else
digitStr := chr(ascii('A') + num - 10);
end if;

return digitStr;
end digitToString;

/* Takes a character (varchar2(1)) and converts it to a number.
The parseInt() function calls this function.

The caller of this function is responsible for maksing sure no invalid
string is passed as the argument.  The caller can do this by first
calling the isValidNumStr() function.
*/
function digitToDecimal(digitStr in varchar2) return number as
num number;
begin
if (digitStr >= '0') and (digitStr <= '9') then
num := ascii(digitStr) - ascii('0');
elsif (digitStr >= 'A') and (digitStr <= 'F') then
num := ascii(digitStr) - ascii('A') + 10;
end if;

return num;
end digitToDecimal;

/* Checks if the given string represents a valid number in given radix.
Returns true if valid; ORA-6502 if invalid.
*/
function isValidNumStr(str in out varchar2,radix in number) return boolean
as
validChars varchar2(16) := '0123456789ABCDEF';
valid number;
len number;
i number;
retval boolean;
begin
end if;
```

## SearchDataManagement

• ### Oracle brings GoldenGate data integration service to cloud

Oracle is making its GoldenGate real time data technology available on its second-generation Oracle Cloud Infrastructure platform...

• ### Era Software raises \$15.25M for enterprise data management

The startup that began as the EraDB time series database is advancing its efforts with new funding and a cloud service for its ...

• ### Dgraph GraphQL database users detail graph use cases

Graph DB vendor Dgraph Labs is expanding its AWS cloud footprint with new regions and adding change data capture capabilities in ...

• ### TigerGraph unveils support for GCP, adds new connectors

Graph database vendor TigerGraph unveiled support for Google Cloud and new connectors to Snowflake and Tableau on April 21 during...

• ### Startup Veezoo emerges from stealth with NLQ-based platform

Aiming to be 'Siri for enterprises,' an analytics startup emerged from stealth with a platform that enables users to interact ...

• ### 15 data science tools to consider using in 2021

Numerous tools are available for data science applications. Read about 15, including their features, capabilities and uses, to ...

## SearchSAP

• ### S/4HANA Cloud SaaS ERP: Buying team overview

SAP's multi-tenant SaaS ERP, S/4HANA Cloud, is a viable choice for companies that need ease in their infrastructure management. ...

• ### SAP forms financial services partnership with Dediq

SAP and financial industry investment firm Dediq are forming a new business unit to develop applications that help banks and ...

• ### Unpatched applications threaten SAP security

Cyberattacks are a significant threat to unpatched, unprotected SAP applications, according to a new threat intelligence report ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Incorporate diversity and inclusion in technology design

DEI in technology is about more than creating a diverse workplace. We talked to a few DEI professionals about how teams build ...

• ### Microsoft previews OpenJDK distro to the delight of devs

In a move meant to attract more Java developers to its Azure cloud and further support the Java community, Microsoft launched a ...

• ### Supreme Court ruling on Java APIs eases developer worries

Now that the Supreme Court has ruled for Google over Oracle in their high-stakes copyright battle over Java APIs, developers can ...

## SearchDataCenter

• ### Nvidia SDK simulates quantum computing circuits on GPU systems

Nvidia edged its way into the quantum computing market with an SDK that simulates quantum circuits by adding horsepower to ...

• ### Programmable processor technology for next-gen data centers

The right processing technology can benefit your data center. Learn about advancements in CPU technologies, recent vendor ...

• ### Data processing units accelerate infrastructure performance

DPUs often run on networking packets to move information in the data center, instead of supporting processing workflows. Get an ...

## SearchContentManagement

• ### Hyland gets digital asset management tech with Nuxeo buy

By acquiring a smaller competitor's digital asset management platform, Hyland looks to build on its 2020 purchase of Alfresco, ...

• ### OpenText releases Cloud Editions content services updates

OpenText CE 21.2 includes federated document compliance that extends to Microsoft Office 365, along with a revamped content ...

As the pandemic disrupts paper workflows, Adobe courts small business users with simple webforms, digital signatures and payments...

## SearchHRSoftware

• ### Shift to HR shared services could save Connecticut millions

By consolidating 17 separate HR operations into one shared service, Connecticut expects to save significantly on costs, most of ...

• ### 10 steps to support your HCM system post go-live

To ensure a new system's success, HR leaders need to develop a plan for how they will support their new HCM system post go-live. ...

• ### Face mask detection a newcomer to employee surveillance

Face mask detection has emerged as another form of employee surveillance technology, and its adoption may be helped indirectly by...

Close