Query to convert number to char
Hai All
I have a salary column in my table as declare as number now i need to spell this in words
For example
500 as five hundred how to use Jsp
Regards
Srikkanth.M
create or replace
FUNCTION SPELL_INDIAN_MONEY (
p_currency IN VARCHAR2 DEFAULT 'Rs.',
p_number IN NUMBER DEFAULT 0
RETURN VARCHAR2
AS
TYPE myarray IS TABLE OF VARCHAR2 (255);
l_str myarray
:= myarray (' Thousand ',
' Lakh ' ,
' Crore ' ,
' Hundred ' , --' Arab ',
' Thousand ', --' Kharab ',
' Shankh '
l_num VARCHAR2 (50) DEFAULT TRUNC (p_number);
l_return VARCHAR2 (4000);
BEGIN
IF (SUBSTR (l_num, LENGTH (l_num) - 2, 3) <> 0) THEN
l_return := TO_CHAR (TO_DATE (SUBSTR (l_num, LENGTH (l_num) - 2, 3), 'J'), 'Jsp');
END IF;
l_num := SUBSTR (l_num, 1, LENGTH (l_num) - 3);
FOR i IN 1 .. l_str.COUNT LOOP
EXIT WHEN l_num IS NULL;
IF (SUBSTR (l_num, LENGTH (l_num) - 1, 2) <> 0) THEN
l_return := TO_CHAR (TO_DATE (SUBSTR (l_num, LENGTH (l_num) - 1, 2), 'J'), 'Jsp')
|| l_str (i)
|| l_return;
END IF;
l_num := SUBSTR (l_num, 1, LENGTH (l_num) - 2);
END LOOP;
IF p_number BETWEEN 999999999 AND 9999999999999 AND UPPER (l_return) NOT LIKE '%CRORE%' THEN
l_return := l_return || 'Crore';
END IF;
IF TO_CHAR (p_number) LIKE '%.%' THEN
l_num := SUBSTR (to_char(ROUND (p_number, 2),'D00'), INSTR (p_number, '.') + 1);
SELECT REPLACE(TO_CHAR(SUBSTR (ROUND (p_number, 2),INSTR (p_number, '.')),'D90'),'.','')l_num
INTO l_num
FROM DUAL;
-- l_num := REPLACE(TO_CHAR(SUBSTR (ROUND (p_number, 2),INSTR (p_number, '.')),'D90'),'.','');
-- l_num := SUBSTR (ROUND (p_number, 2), INSTR (p_number, '.') + 1);
IF l_num > 0 THEN
l_return := l_return
|| ' And '
|| TO_CHAR (TO_DATE (l_num, 'J'), 'Jsp')
|| ' Paise';
END IF;
END IF;
RETURN p_currency || ' ' || l_return;
END spell_indian_money;*009*
Similar Messages
-
Hi,
I need to format numbers when converting it to char.
I need to show the number with a precision of 3, and when between -1 and 1 to show the 0.
ex:
0.234
-0.234
1.220
not .234
thanks in advanceI need to show the number with a precision of 3, and when between -1 and 1 to show the 0.This ?
SQL> with t as (
select 0.234 n from dual union all
select -0.234 from dual union all
select 13.22 from dual union all
select 1.220 from dual
select n, to_char(n, '990.000') n2 from t
N N2
,234 0.234
-0,234 -0.234
13,22 13.220
1,22 1.220
4 rows selected. -
How can I convert a number to char in javascript
How can I convert a number i.e ascii number to char in javascript.
ex: 55 to AHow can I convert a number i.e ascii number to char in javascript.
Quite simple: By asking in a forum that deals with javascript and not with java.
Have no clue...
Maybe on http://www.irt.org -
I want to convert number to hours in oracle 10 like this.
Dear All
Some can help me
I want to convert below MS-SQL query in oracle 10g. please help me.
for eg:
Select numasdate,
Cast(numasdate / 60 as Varchar) + ' hours ' +
Cast(numasdate % 60 as Varchar) + ' minutes'
as [TotalHoursAndMinutes]
From
#SampleTable
Output:
9436 157 hours 16 minutes
537 8 hours 57 minutes
9323 155 hours 23 minutes
12525 208 hours 45 minutes
Edited by: Parwez on Jan 1, 2013 5:33 AMI want to convert number to hours in oracle 10g like this.
537 8 hours 57 minutes
9436 157 hours 16 minutes
12525 208 hours 45 minutesTry this...
Ranit>> with xx as(
2 SELECT 537 num from dual UNION ALL
3 SELECT 9436 num from dual UNION ALL
4 SELECT 12525 num from dual
5 )
6 select
7 num,
8 FLOOR(num/60)||' hrs' as "hrs",
9 MOD(num,60)||' minutes' as "minutes",
10 FLOOR(num/60)||' hrs '||MOD(num,60)||' minutes' as "Hours.Mins"
11 from xx;
NUM hrs minutes Hours.Mins
537 8 hrs 57 minutes 8 hrs 57 minutes
9436 157 hrs 16 minutes 157 hrs 16 minutes
12525 208 hrs 45 minutes 208 hrs 45 minutes Edited by: ranit B on Jan 1, 2013 6:51 PM
--- Hey John... I just did it and saw your hint now !!! -
Query to convert Row to column - Re-posting
Hi all,
i am re-posting the same requirement, please do the needful.
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarMost repeated question in the forum..
SQL> select id,max(ltrim(sys_connect_by_path(val,','),',')) res
2 from (select id,val,
3 row_number() over(partition by id order by val) rn
4 from tb_row_2_col)
5 start with rn = 1
6 connect by prior rn = rn -1
7 and prior id = id
8 group by id;
ID RES
1 col1,col2,col3
2 col4,col5<br>
Message was edited by:
jeneesh
Check here for variations.. -
Query to convert Row to column
Hi all,
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarOr look for aggregation techniques against the forum helping by the search feature (top-right of the current page).
Nicolas. -
Inconsistent datatypes: expected NUMBER got CHAR error
Hi,
I have the following table
create GLOBAL TEMPORARY TABLE br_total_rtn_data_tmp
code varchar(50) NOT NULL,
name varchar(255),
cum_ytd_rtn_amt varchar(255),
cum_one_mon_rtn_amt varchar(255) ,
cum_thr_mon_rtn_amt varchar(255) ,
cum_six_mon_rtn_amt varchar(255),
cum_nine_mon_rtn_amt varchar(255),
cum_one_yr_rtn_amt varchar(255),
cum_thr_yr_rtn_amt varchar(255),
cum_five_yr_rtn_amt varchar(255),
cum_ten_yr_rtn_amt varchar(255),
cum_lof_rtn_amt varchar(255),
avg_anl_one_yr_rtn_amt varchar(255),
avg_anl_thr_yr_rtn_amt varchar(255),
avg_anl_five_yr_rtn_amt varchar(255),
avg_anl_ten_yr_rtn_amt varchar(255),
avg_anl_lof_rtn_amt varchar(255),
cum_prev_1m_month_end varchar(255),
cum_prev_2m_month_end varchar(255)
)ON COMMIT PRESERVE ROWS;
I have a case statement
CASE
WHEN code = 'MDN' THEN
max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.mdn /100 else null end)
WHEN code = 'QRT' THEN
max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.quartile else null end)
WHEN code = 'PCT' THEN
max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.pct_beaten / 100 else null end)
WHEN code = 'RNK' THEN
case when (p.m_date = v_prev2_yr_mon and p.period_type = '1M' and p.rank is null and p.cnt is null)
THEN
P.RANK
else
p.rank||'/'||p.cnt
end
ELSE NULL
END CASE The output for code = RNK should be somewhat like 3/5 which is rank/count
but i get the error "Inconsistent datatypes: expected NUMBER got CHAR error" when i put p.rank||'/'||p.cnt
How can that be solved.
ORacle version is 10g.Taken from the documentation of the CASE expression:
"For a simple CASE expression, the expr and all comparison_expr values must either have the same datatype (CHAR, VARCHAR2, NCHAR, or NVARCHAR2, NUMBER, BINARY_FLOAT, or BINARY_DOUBLE) or must all have a numeric datatype. If all expressions have a numeric datatype, then Oracle determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype.
For both simple and searched CASE expressions, all of the return_exprs must either have the same datatype (CHAR, VARCHAR2, NCHAR, or NVARCHAR2, NUMBER, BINARY_FLOAT, or BINARY_DOUBLE) or must all have a numeric datatype. If all return expressions have a numeric datatype, then Oracle determines the argument with the highest numeric precedence, implicitly converts the remaining arguments to that datatype, and returns that datatype."
You need to use the same data type for all your expressions. If you want to return a string, then you need to convert the remaining numbers explicitly to strings. E.g. you could try something like this:
CASE
WHEN code = 'MDN' THEN
to_char(max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.mdn /100 else null end), 'TM')
WHEN code = 'QRT' THEN
to_char(max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.quartile else null end), 'TM')
WHEN code = 'PCT' THEN
to_char(max(case when p.m_date = v_prev2_yr_mon and p.period_type = '1M' then p.pct_beaten / 100 else null end), 'TM')
WHEN code = 'RNK' THEN
case when (p.m_date = v_prev2_yr_mon and p.period_type = '1M' and p.rank is null and p.cnt is null)
THEN
to_char(P.RANK, 'TM')
else
p.rank||'/'||p.cnt
end
ELSE NULL
END CASE I see another potential issue, you're mixing aggregate functions with non-aggregate expressions, this can only work if these non-aggregate expressions are part of the group by clause, but you haven't posted the complete statement so I can only guess.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
hi
i need help in converting number to alphabet
for example 4 to D, 2 to B, etc
thank you for helping
best regards
andorsprivate String Number2String(int number, bool isCaps)
Char c
= (Char)((isCaps ? 64 : 96) + number);
return c.ToString();
No point in doing - 1.
If you want 0 to be A then start at 65 for caps, 97 for lower.
Edit:
After some messing around, I've come up with the perfect method:
public static string numberToAlpha(long number, bool isLower = false)
string returnVal = "";
char c = isLower ? 'a' : 'A';
while (number >= 0)
returnVal = (char)(c + number % 26) + returnVal;
number /= 26;
number--;
return returnVal; -
Convert number to letter of alphabet?
Hi,
Is there a LabWindows function for converting a number to an alphabet equivalent?
I was trying something like this...
char getLetterOfAlphabetByNum(int number){
//test if alpha
if(isalpha (number)==0)
DebugPrintf ("Error converting number to letter. Non-alphabetic.");
else{
//take decimal and convert to ascii
statusReturned=Fmt (&letter, "%s<%d", number);
if(statusReturned<0)
DebugPrintf ("Error converting number to letter!\n");
DebugPrintf ("tempString = %s\n", letter);
DebugPrintf ("%d --> %s\n",number,letter);
return letter;
Thanks!
Solved!
Go to Solution.It seems to me that you could simplify your code this way:
//number of alphabet to letter
char getLetterOfAlphabetByNum (int number)
number += 64;
//test if alpha
if (!isalpha (number)) {
DebugPrintf ("Non-alphabetic.\n");
return 0;
return (char)number;
I excluded the test for printable characters as is it overcome by test for alphabetic.
Also, be warned that passing numbers from 33 to 58 returns lowercase letters.
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
Hi,
I want to convert number in words and get the output through a query.
For example :if the value in row is 1311 then I want the query to return it like one thousand three hundreds and eleven.
Any help is highly appreciated.
CheersIt could be better indeed, scope is larger, but problem with 0 still exists.
SQL> select to_char(to_date(0,'J'), 'JSP') as converted_form from dual;
select to_char(to_date(0,'J'), 'JSP') as converted_form from dual
ERROR at line 1:
ORA-01854: julian date must be between 1 and 5373484
SQL> Better to build function as showed by Tom Kyte in the link given earlier.
Nicolas. -
How to convert quantity to char without using FM's like C14W_CHAR_NUMBER_CONVERSION,
C14W_NUMBER_CHAR_CONVERSION,
CHAR_INT_CONVERSION as these FM's do not exist in my server?Hi...
this is my program...try this code....
Parameters:
p_Number(9) type c. " Input string.
data:
w_number(9) type c, " Input number
w_strlen(9) type c, " Strlen
w_numc(9) type n, " Digit string
w_2bit(2) type c. " first 2 positions
w_number = p_number.
w_numc = p_number.
write: 'The given number in words: '.
do 5 times.
case sy-index.
when 1.
w_2bit = w_numc+0(2).
when 2.
w_2bit = w_numc+2(2).
when 3.
w_2bit = w_numc+4(2).
when 4.
w_2bit+0(1) = 0.
w_2bit1(1) = w_numc6(1).
when 5.
w_2bit = w_numc+7(2).
endcase. " CASE SY-INDEX.
if w_2bit+0(2) ne 0.
if w_2bit le 19.
case w_2bit.
when '01'.
write 'ONE'.
when '02'.
write 'TWO'.
when '03'.
write 'THREE'.
when '04'.
write 'FOUR'.
when '05'.
write 'FIVE'.
when '06'.
write 'SIX'.
when '07'.
write 'SEVEN'.
when '08'.
write 'EIGHT'.
when '09'.
write 'NINE'.
when '10'.
write 'TEN'.
when '11'.
write 'LEVEN'.
when '12'.
write 'TWELVE'.
when '13'.
write 'THIRTEEN'.
when '14'.
write 'FOURTEEN'.
when '15'.
write 'FIFTEEN'.
when '16'.
write 'SIXTEEN'.
when '17'.
write 'SEVENTEEN'.
when '18'.
write 'EIGHTEEN'.
when '19'.
write 'NINETEEN'.
endcase. " CASE 2BITS POSITIONS 1,2.
else.
case w_2bit+0(1).
when '2'.
write 'TWENTY'.
when '3'.
write 'THIRTY'.
when '4'.
write 'FOURTY'.
when '5'.
write 'FIFTY'.
when '6'.
write 'SIXTY'.
when '7'.
write 'SEVENTY'.
when '8'.
write 'EIGHTY'.
when '9'.
write 'NINETY'.
endcase. " CASE W_2BIT+0(1)
if w_2bit+1(1) ne 0.
case w_2bit+1(1).
when '1'.
write 'ONE'.
when '2'.
write 'TWO'.
when '3'.
write 'THREE'.
when '4'.
write 'FOUR'.
when '5'.
write 'FIVE'.
when '6'.
write 'SIX'.
when '7'.
write 'SEVEN'.
when '8'.
write 'EIGHT'.
when '9'.
write 'NINE'.
when others.
write ' '.
endcase. " CASE W_2BIT+1(1)
endif. " IF W_2BIT+1(1)
endif. " IF 2BIT LE 19
case sy-index.
when 1.
write 'CRORES'.
when 2.
write 'LAKHS'.
when 3.
write 'THOUSANDS'.
when 4.
write 'HUNDREDS'.
endcase. " CASE SY-INDEX
endif. " IF 2BIT NE 0 -
URG: Converting encoded greek char from HTML page to greek char
String geekvalues = "&# 966;&# 948;&# 945;&# 963;&# 966;&# 945;&# 963;&# 948;&# 966;";
( i have inserted space b/w &# ddd; because while framing the query they get converted to
greek char)
I parse the following string and insert the integer values in the following
o/p stream with UTF8 ecoding.
I can see proper greek char in the file, but when i read the contents of the file
and try inserting these values to the DB, they appear as ���������(not what i see on my m/c) some junk char.
bufferWriter = new BufferedWriter
(new OutputStreamWriter(new FileOutputStream("d:\\tempAA.txt",false),"UTF8"));
bufferWriter.write(x);
bufferReader = new BufferedReader
(new InputStreamReader(new FileInputStream("d:\\tempAA.txt"),"UTF8"));
retGreekValue =bufferReader.readLine();
String sqlStr = "INSERT INTO test_table VALUES('"+retGreekValue+"')";
Could anybody suggest how do i insert proper greek characters in Database from the encoded string from browser.
Thanks in advance,You could try the Internationalization forum. Although the question "I need to get data in script X from my database through the Internet to a browser and back, and it doesn't work" is asked frequently there, and never seems to get an answer.
-
How to convert number datatype to raw datatype for use in data warehouse?
I am picking up the work of another grad student who assembled the initial data for a data warehouse, mapped out a dimensional dw and then created then initial fact and dimension tables. I am using oracle enterprise 11gR2. The student was new to oracle and used datatypes of NUMBER (without a length - defaulting to number(38) for dimension keys. The dw has 1 fact table and about 20 dimension tables at this point.
Before refining the dw further, I have to translate all these dimension tables and convert all columns of Number and Number(n) (where n=1-38) to raw datatype with a length. The goal is to compact the size of the dw database significantly. With only a few exceptions every number column is a dimension key or attribute.
The entire dw db is now sitting in a datapump dmp file. this has to be imported to the db instance and then somehow converted so all occurrences of a number datatype into raw datatypes. BTW, there are other datatypes present such as varchar2 and date.
I discovered that datapump cannot convert number to raw in an import or export, so the instance tables once loaded using impdp will be the starting point.
I found there is a utl_raw package delivered with oracle to facilitate using the raw datatype. This has a numbertoraw function. Never used it and am unsure how to incorporate this in the table conversions. I also hope to use OWB capabilities at some point but I have never used it and only know that it has a lot of analytical capabilities. As a preliminary step I have done partial imports and determined the max length of every number column so I can alter the present schema number columns tp be an apporpriate max length for each column in each table.
Right now I am not sure what the next step is. Any suggestions for the data conversion steps would be appreciated.Hi there,
The post about "Convert Numbers" might help in your case. You might also interested in "Anydata cast" or transformations.
Thanks, -
Problem in converting number to character
Hi All,
In my report there is number field called <?LINE_TOT_AMOUNT?>. In the next line i want to display that amount in words. I tried using
<?xdofx:to_char(LINE_TOT_AMOUNT)?>
but the output is same as the <?LINE_TOT_AMOUNT?>. Can any one help in solving this?look at TO_CHAR (number)
if LINE_TOT_AMOUNT is number then to_char(LINE_TOT_AMOUNT) in string
it's not display that amount in words
it's only format row
if you wnat to convert number to words
plz see Re: Conversion of number to word -
Column size and number of chars
I have fixed Jtables column header size.
when I put a large text in this colums ,half of text is hidden. I know this problem is solved with setAutoResizeMode, bat I don't wont to use it.
I wont to know how many chars can I put in this column(with fixed size),
How can I return number Of chars or length or text which can be possible tu put fixed columean size?Well, you can do something like (untested)
TableColumnModel tcm = table.getColumnModel();
TableColumn col = tcm.getColumn( n );
int cw = col.getMaxWidth();
String st = col.getHeaderValue().toString();
JTableHeader header = table.getTableHeader();
FontMetrics fm = header.getFontMetrics( header.getFont() );
for( int sw = fm.stringWidth( st ); sw > cw; ) {
st = st.substring( 0, st.length()-1 );
sw = fm.stringWidth( st );
col.setHeaderValue( st );That should at least give you some ideas.
Maybe you are looking for
-
Shut down problem on new macbook pro 13"
Hey, Just a new convert to mac after ditching my glitchy windows desktop replacement. Been really enjoying the mac (i've had it for 3 days now). I've experienced a shut down problem where everything would close, like the dock and the bar up the top.
-
New FaunOS Live Arch-Based DVD/USB Distro Now Available
Hello fellow archers, We have just released the latest version of FaunOS. Since this version of FaunOS is the answer to the most important question in the universe, we have named it "fortytwo." FaunOS-fortytwo contains many improvements over previous
-
Video playback issue in safari.
I hope some knows the answer to this. I converted many videos on my website so they could play on the iPhone iPad and iPod a few months ago. I used winff. Everything worked great. Now I have the latest iPhone and none of my videos will work. Safari s
-
Custom ADF Application with Process Instance Details Task Flow
Hi, I want to use Process Instance Details Task Flow which is referred to in the doc below. http://download.oracle.com/docs/cd/E21764_01/user.1111/e15175/bpmug_ws_taskflows.htm#BACDBDJA But I could not find the task flow in the JAR files nor in the l
-
Control sort order of UDO Child
Hey All, Can anyone tell me how I can control the display order of a document UDO lines matrix? We have document lines created that have a date in the data and the client would like the data to display with the newest entries on top. Anyone know how