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

# Indian money to character conversion

## A script that converts numbers in the form of Indian money (rupees, paises, etc) into characters.

This solution is designed to convert numbers into words: for example, 100 to One Hundred. Since I am from India, this example uses rupees (for dollars), paises (for cents), lacs (10 lac=one milion), and so on, so you'll need to modify it to fit your needs. Here is the code for Oracle:

```*/

create or replace package num_to_word is
function to_num(num number) return char;
end;
/
create or replace package body num_to_word is

function num_to_char1 (num number) return char is
a number;
var_return  varchar(100);
begin
if num=1 then
return 'One';
elsif num=2 then
return 'Two';
elsif num=3 then
return 'Three';
elsif num=4 then
return 'Four';
elsif num=5 then
return 'Five';
elsif num=6 then
return 'Six';
elsif num=7 then
return 'Seven';
elsif num=8 then
return 'Eight';
elsif num=9 then
return 'Nine';
elsif num =0 then
return null;
end if;
end;

function num_to_char2 (num number) return char is
a number;
var_return  varchar(100);
begin
if  num=20 then
return ' Twenty';
elsif num=30 then
return ' Thirty';
elsif num=40 then
return ' Fourty';
elsif num=50 then
return ' Fifty';
elsif num=60 then
return ' Sixty';
elsif num=70 then
return ' Seventy';
elsif num=80 then
return ' Eighty';
elsif num=90 then
return ' Ninety';
else
return null;
end if;
end;

function num_to_char3 (num number) return char is
a number;
var_return  varchar(100);
begin
if  num=11 then
return 'Eleven';
elsif num=12 then
return 'Twelve';
elsif num=13 then
return 'Thirteen';
elsif num=14 then
return 'Fourteen';
elsif num=15 then
return 'Fifteen';
elsif num=16 then
return 'Sixteen';
elsif num=17 then
return 'Seventeen';
elsif num=18 then
return 'Eighteen';
elsif num =19 then
return 'Nineteen';
else return null;
end if;
end;

function to_num(num number) return char is
a number;
var_return   varchar(500);
num1   number:=num;
var_remain1   number;
begin

a:=length(num1);
if a=6 or a=7 then
var_remain1:=(trunc(num1/100000));
a:=length(var_remain1);
if a=2 then
if var_remain1=10 then
var_return:=var_return||' Ten ';
elsif var_remain1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(var_remain1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(var_remain1,-1));
var_remain1:=mod(var_remain1,10);
end loop;
end if;
end if;
a:=length(var_remain1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(var_remain1);
end if;
var_return:=var_return||' Lac ';
num1:=mod(num1,100000);
end if;

a:=length(num1);
if a =5 or a=4 then
var_remain1:=(trunc(num1/1000));
a:=length(var_remain1);
if a=2 then
if var_remain1=10 then
var_return:=var_return||' Ten ';
elsif var_remain1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(var_remain1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(var_remain1,-1));
var_remain1:=mod(var_remain1,10);
end loop;
end if;
end if;

a:=length(var_remain1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(var_remain1);
end if;
var_return:=var_return||' Thousand ';
num1:=mod(num1,1000);
end if;

a:=length(num1);
if a =3 then
for i in 1..9 loop
if trunc(num1/100)=i then
var_return:=var_return|| num_to_char1(i)||' Hundered';
num1:=mod(num1,100);
end if;
end loop;
end if;

a:=length(num1);
if a=2 then
if num1=10 then
var_return:=var_return||' Ten';
elsif num1 between 11 and 19 then
var_return:=var_return||' '|| num_to_char3(num1);
else
for i in 2..9 loop
var_return:=var_return|| num_to_char2(trunc(num1,-1));
num1:=mod(num1,10);
end loop;
end if;
end if;

a:=length(num1);
if a=1 then
var_return:=var_return||' '|| num_to_char1(num1);
end if;
return var_return;
end;

end ;
/
```

#### For More Information

• What do you think about this tip? E-mail the Edtior at tdichiara@techtarget.com with your feedback.
• The Best Oracle Web Links: tips, tutorials, scripts, and more.
• Have an Oracle tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
• Ask your technical Oracle questions--or help out your peers by answering them--in our live discussion forums.
• Check out our Ask the Experts feature: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.

This was last published in November 2001

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### Big data management practices gain attention amid risks

Many data professionals have yet to solidify traditional data management practices, but they have a new set of challenges to ...

• ### Aerospike database garners Spark, Kafka connectors

Apache Kafka and Apache Spark connectors ease use of the Aerospike NoSQL data store in high-speed applications such as analytics ...

• ### Data catalog software takes on data lakes, privacy laws

Data catalog systems form a hub for managing a company's data. New products are focusing on machine learning and AI add-ons that ...

## SearchBusinessAnalytics

• ### NYPD's Patternizr crime analysis tool raises AI bias concerns

The NYPD has rolled out Patternizr, a machine learning algorithm that helps analysts identify crime patterns but highlights the ...

• ### Users find data preparation tools vital to BI strategies

Data preparation isn't the sexiest topic, but it's critically important to IT and business users, according to a study by Dresner...

• ### Augmented analytics tools, NLP search, graph are trending

Augmented analytics, NLP and graph analytics technologies are changing the data and analytics market, according to Gartner -- ...

## SearchSAP

• ### SAP CEO talks Qualtrics acquisition, says experience data is critical

At the Qualtrics X4 Summit, SAP CEO Bill McDermott argues that experience data is now central to business success. He promised to...

• ### SAP blockchain service helps fight counterfeit drugs

SAP's new blockchain service may help drug wholesalers verify the authenticity of returned drugs, but it faces business process ...

• ### Release of ABAP in SAP Cloud Platform to extend S/4HANA

ABAP's future is bright with the support of SAP technology like S/4HANA, but having ABAP in the cloud will take some adjustment, ...

## SearchSQLServer

• ### SQL Server auditing best practices: 3 key questions for DBAs

Acing a SQL Server database audit starts with careful monitoring of how sensitive data is accessed and used so you can answer the...

• ### Talend Stitch tools load data to Azure SQL Data Warehouse

Cloud data warehouses see serious data transformation work moving to the cloud. Talend's first integration with Stitch, which it ...

• ### 5 trends for SQL Server environments as SQL Server 2019 looms

SQL Server is undergoing new changes, as Microsoft prepares to release the 2019 version of the database software. Other changes ...

## TheServerSide.com

• ### Fix this runC vulnerability to prevent unwanted root access

Examine a recent vulnerability to the runC container code and what you need to do to prevent unwanted root access and container ...

• ### Get these benefits when you simplify a WebSphere Portal URL

If your Portal URL displays the tired /wps/portal preamble in the browser's location bar, it's time to perform Portal URL ...

• ### Manage Jenkins vulnerabilities via Security Advisory page

The Jenkins Security Advisory maintains a list of vulnerable plugins and ways to fix issues that may otherwise hamper your ...

## SearchDataCenter

• ### 4 PowerShell modules every IT pro should know

Find out how to use four of the most popular PowerShell community modules in the PowerShell Gallery to help better manage your ...

• ### IBM quantum computing may arrive sooner than expected

If IBM continues doubling the performance of its quantum computers, as recent benchmarks indicate, it could deliver the first ...

• ### Nvidia acquires Mellanox against growing AI, data competition

Nvidia acquires Mellanox for \$6.9 billion, as competition increases for platforms that can handle AI and other data-intensive ...

## SearchContentManagement

• ### 4 Office 365 collaboration tools that mirror SharePoint

In order to convince users to move away from SharePoint, Microsoft has built Office 365 collaboration tools that improve upon the...

• ### 9 killer use cases for CMS blockchain

Uses for blockchain technology in content management and social media exist largely in the realm of the theoretical. But there's ...

• ### Content services and archiving records: It's complicated

Content services complicate archiving. Microservices render records dynamically for many devices, while an archive should be a ...

## SearchHRSoftware

• ### Users at Qualtrics X4 Summit share a common philosophy on role of HR

Two Qualtrics customers talk about how they've successfully measured employee experience, and how doing so has effectively ...

• ### 10 steps for developing a recruiting strategy

To ensure your organization is attracting and hiring the right candidates, evaluate existing policies and strategies and update ...

• ### At Qualtrics X4 Summit, Obama stresses need for facts

Former President Barack Obama discusses his approach to problem analysis and forming a team at the Qualtrics X4 Summit.

Close