Convert Number into Words in Oracle BI Publisher - oracle

I have a requirement that I need to show the Total Amount of Invoice into words in rtf , I tried
but it doesn't show any thing !! Is there any RTF Tag to do such a requirement on layout ?
For Example :
I have value 74,448.50 and i need to show the value in this way : SEVENTY-FOUR THOUSAND FOUR HUNDRED FORTY-EIGHT AND Halla FIVE HUNDRED

Here's a function you can create to take care of it
SQL> create or replace
2 function spell_number( p_number in number )
3 return varchar2
4 as
5 type myArray is table of varchar2(255);
6 l_str myArray := myArray( '',
7 ' thousand ', ' million ',
8 ' billion ', ' trillion ',
9 ' quadrillion ', ' quintillion ',
10 ' sextillion ', ' septillion ',
11 ' octillion ', ' nonillion ',
12 ' decillion ', ' undecillion ',
13 ' duodecillion ' );
14
15 l_num varchar2(50) default trunc( p_number );
16 l_return varchar2(4000);
17 begin
18 for i in 1 .. l_str.count
19 loop
20 exit when l_num is null;
21
22 if ( substr(l_num, length(l_num)-2, 3) <> 0 )
23 then
24 l_return := to_char(
25 to_date(
26 substr(l_num, length(l_num)-2, 3),
27 'J' ),
28 'Jsp' ) || l_str(i) || l_return;
29 end if;
30 l_num := substr( l_num, 1, length(l_num)-3 );
31 end loop;
32
33 return l_return;
34 end;
35 /
Function created.
SQL> select
2 spell_number( 12345678901234567890123456789012345678 )
3 from dual;
SPELL_NUMBER(1234567890123456789012345678901234567
--------------------------------------------------
Twelve undecillion Three Hundred Forty-Five decill
ion Six Hundred Seventy-Eight nonillion Nine Hundr
ed One octillion Two Hundred Thirty-Four septillio
n Five Hundred Sixty-Seven sextillion Eight Hundre
d Ninety quintillion One Hundred Twenty-Three quad
rillion Four Hundred Fifty-Six trillion Seven Hund
red Eighty-Nine billion Twelve million Three Hundr
ed Forty-Five thousand Six Hundred Seventy-Eight

Related

PL/SQL program to separate the code into its two parts

How to write a PL/SQL program to separate the code into its two parts as shown in the following example: if the input is ABC031, the output should be:
Product Name is: ABC
Serial Number is: 031
Hints: Use the following functions if needed:
instr( string1, string2 [, start_position [, nth_appearance ] ] )
substr( string, start_position, [ length ] )
length( string )
DBMS_OUTPUT.PUT_LINE( )
Here are two examples, see if any of these helps.
SQL> set serveroutput on
SQL>
SQL> create or replace procedure p_test (par_input in varchar2)
2 is
3 l_product_name varchar2(10);
4 l_serial_number varchar2(10);
5 begin
6 -- first example
7 l_product_name := substr(par_input, 1, 3);
8 l_serial_number := substr(par_input, 4);
9
10 dbms_output.put_line('First example : ' || l_product_name ||', '|| l_serial_number);
11
12 -- second example, possibly better as it splits letters from digits
13 l_product_name := regexp_substr(par_input, '^[[:alpha:]]+');
14 l_serial_number := regexp_substr(par_input, '[[:digit:]]+$');
15
16 dbms_output.put_line('Second example: ' || l_product_name ||', '|| l_serial_number);
17 end;
18 /
Procedure created.
SQL> begin
2 p_test('ABC031');
3 end;
4 /
First example : ABC, 031
Second example: ABC, 031
PL/SQL procedure successfully completed.
SQL>

Getting rid of comma at the end of PL/SQL Function [Oracle PL/SQL]

Am working on a stored PL/SQL function that find the names of dependents of an employee by the given employee's number. So far I am able to get the desired output but seem to have an issue with the commas during the output. Any help is appreciated in regards to how I can remove the last bracket during the output.
[Current Code]
SQL> create or replace function FINDDEPENDENTS(empid in Employee.E#%TYPE)
2 RETURN VARCHAR IS
3 EID Employee.E#%TYPE;
4 Ename Employee.Name%TYPE;
5
6 DEPNAME Dependent.DName%TYPE;
7 finalRow VARCHAR(2000);
8 CURSOR q IS
9 --
10 select DName from Dependent WHERE E#=empid;
11 begin
12 select E#, Name INTO EID, Ename FROM Employee WHERE E#= empid;
13 finalRow:= EID || ' ' || Ename || ': ';
14 open q;
15 loop
16 fetch q into depname;
17 if q%notfound then exit;
18 end if;
19 finalRow:= finalRow || DEPNAME || ', ';
20 end loop;
21 close q;
22 return(finalRow);
23 end FINDDEPENDENTS;
24 /
Function created.
SQL> show errors
No errors.
SQL> SELECT FINDDEPENDENTS(E#) FROM Employee;
FINDDEPENDENTS(E#)
----------------------------------------------------------------------------------------------------
00100 Albert: Bolt, Edee, Judy,
00101 Peter:
00103 Ami:
00105 Robert:
00107 Wendy:
00109 Michael:
00110 Alvin:
00120 Alice: Blues, Edee, Kadi,
00125 Angela:
00136 Aban:
00150 Bob:
00187 Eadger:
00200 Carl: Eva,
00250 Douglass:
14 rows selected.
How can I get rid of the last comma so that I can get an output like:
00100 Albert: Bolt, Edee, Judy
00110 Alvin:
00120 Alice: Blures, Edee, Kadi
TRIM it:
return(rtrim(finalRow, ','));
You can use RTRIM as mentioned in one of the answers, But you can also use the following logic which will prevent the creation of such data.
Use
finalRow:= finalRow || CASE WHEN SUBSTR(finalRow ,-2) <> ': ' THEN ', ' END || DEPNAME;
Instead of
finalRow:= finalRow || DEPNAME || ', ';
Use TRIM function:
create or replace function foo (s varchar2) return varchar2 is
begin
return trim (trailing ',' from s);
end;
/
var ret varchar2
exec :ret := foo ('foo,')
RET
---
foo

plsql procedure doesn't do what i programmed it to do

my procedure is supposed to change 2 values but when i call it it shows the same values entered
code
CREATE OR REPLACE PROCEDURE commande_remise(pourcentage_rem IN Decimal,
c_client IN commande.code_client%type,
c_reg IN commande.reglement%type,
c_montantht IN OUT commande.montant_ht%type,
c_montantttc IN OUT commande.montant_ttc%type)
IS
c_ref commande.ref_commande%type;
BEGIN
SELECT COUNT(ref_commande) INTO c_ref FROM commande;
c_ref := c_ref + 1;
c_montantht := c_montantht-c_montantht*pourcentage_rem;
c_montantttc := c_montantttc-c_montantttc*pourcentage_rem;
INSERT INTO commande(ref_commande, code_client, reglement, montant_ht, montant_ttc)
VALUES(c_ref, c_client, c_reg, c_montantht, c_montantttc);
COMMIT;
END commande_remise;
/
procedure call
DECLARE
c_remise DECIMAL :=0.2;
c_code commande.code_client%type :=2;
c_reglement commande.reglement%type :='oui';
c_montantht commande.montant_ht%type :=3080.12;
c_montantttc commande.montant_ttc%type :=3530.56;
c_com commande%rowtype;
CURSOR c_cur IS SELECT ref_commande, code_client, reglement, montant_ht, montant_ttc FROM commande;
BEGIN
commande_remise(c_remise, c_code, c_reglement, c_montantht, c_montantttc);
OPEN c_cur;
LOOP
FETCH c_cur INTO c_com;
exit when c_cur%notfound;
dbms_output.put_line(c_com.ref_commande || ' ' || c_com.code_client || ' ' || c_com.reglement || ' ' || c_com.montant_ht || ' ' || c_com.montant_ttc);
END LOOP;
CLOSE c_cur;
END;
/
the values are c_montantht and c_montantttc
the result is the third:, please help.
Works for me (I'll tell you a secret later).
Table first:
SQL> create table commande
2 (ref_commande number,
3 code_client number,
4 reglement varchar2(10),
5 montant_ht number,
6 montant_ttc number);
Table created.
SQL>
Procedure:
SQL> CREATE OR REPLACE PROCEDURE commande_remise
2 (pourcentage_rem IN NUMBER,
3 c_client IN commande.code_client%type,
4 c_reg IN commande.reglement%type,
5 c_montantht IN OUT commande.montant_ht%type,
6 c_montantttc IN OUT commande.montant_ttc%type)
7 IS
8 c_ref commande.ref_commande%type;
9 BEGIN
10 SELECT COUNT(ref_commande) INTO c_ref FROM commande;
11 c_ref := c_ref + 1;
12 dbms_output.put_line('pourcentage_rem = ' || pourcentage_rem);
13 c_montantht := c_montantht - c_montantht * pourcentage_rem;
14 c_montantttc := c_montantttc - c_montantttc * pourcentage_rem;
15
16 INSERT INTO commande
17 (ref_commande, code_client, reglement, montant_ht, montant_ttc)
18 VALUES
19 (c_ref, c_client, c_reg, c_montantht, c_montantttc);
20 END commande_remise;
21 /
Procedure created.
SQL>
Anonymous PL/SQL block:
SQL> set serveroutput on;
SQL> DECLARE
2 c_remise NUMBER :=0.2;
3 c_code commande.code_client%type :=2;
4 c_reglement commande.reglement%type :='oui';
5 c_montantht commande.montant_ht%type :=3080.12;
6 c_montantttc commande.montant_ttc%type :=3530.56;
7 c_com commande%rowtype;
8 CURSOR c_cur IS SELECT ref_commande, code_client, reglement, montant_ht, montant_ttc FROM commande;
9 BEGIN
10 commande_remise(c_remise, c_code, c_reglement, c_montantht, c_montantttc);
11 OPEN c_cur;
12 LOOP
13 FETCH c_cur INTO c_com;
14 exit when c_cur%notfound;
15 dbms_output.put_line(c_com.ref_commande || ' ' || c_com.code_client
16 || ' ' || c_com.reglement || ' ' || c_com.montant_ht
17 || ' ' || c_com.montant_ttc);
18 END LOOP;
19 CLOSE c_cur;
20 END;
21 /
pourcentage_rem = ,2
1 2 oui 2464,096 2824,448
PL/SQL procedure successfully completed.
SQL>
Table contents:
SQL> select * From commande;
REF_COMMANDE CODE_CLIENT REGLEMENT MONTANT_HT MONTANT_TTC
------------ ----------- ---------- ---------- -----------
1 2 oui 2464,096 2824,448
SQL>
Looks OK, right?
The secret: don't use DECIMAL in
procedure's parameter declaration: pourcentage_rem IN Decimal
anonymous PL/SQL block's variable declaration: c_remise DECIMAL :=0.2;
Use NUMBER instead. Because, if you use DECIMAL, then procedure's line #12 displays
pourcentage_rem = 0
so - when you subtract something that is multiplied by zero, you subtract zero and get the input value itself.

Search data from any column of the table from Oracle

I want to implement one search logic here. What I want is,
A user enters any text in the search box and presses enter. Then what should happen is, it should search in the table on any column and it the record exist then it should display.
Currently what I tried is, it search from one of the column from the table. Below is the code,
PROCEDURE GET_SEARCH_DATA
(
P_INPUTTEXT IN NVARCHAR2,
P_RETURN OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN P_RETURN FOR
SELECT APP_MST_ID, APPLICATIONNAME, PROJECTNO, VSS_FOLDER_LOC FROM
APPLICATION_MASTER WHERE APPLICATIONNAME LIKE '%'|| P_INPUTTEXT || '%';
END;
So what I want is, it should search from every column of the table and display the result.
This is a rather rudimentary "solution" which checks all tables and their columns (from USER_TAB_COLUMNS) and checks which ones of them contain a search string; it displays a table, a column and number of occurrences.
SQL> declare
2 l_str varchar2 (500);
3 l_cnt number := 0;
4 begin
5 for cur_r in (select u.table_name, u.column_name
6 from user_tab_columns u)
7 loop
8 l_str :=
9 'SELECT COUNT(*) FROM '
10 || cur_r.table_name
11 || ' WHERE '
12 || upper (cur_r.column_name)
13 || ' like (''%&search_string%'')';
14
15 execute immediate (l_str) into l_cnt;
16
17 if l_cnt > 0
18 then
19 dbms_output.put_line (
20 cur_r.table_name || '.' || cur_r.column_name || ': ' || l_cnt);
21 end if;
22 end loop;
23 end;
24 /
Enter value for search_string: MANAGE
EMP.JOB: 3
PL/SQL procedure successfully completed.
SQL> /
Enter value for search_string: ACCOU
DEPT.DNAME: 1
PL/SQL procedure successfully completed.
SQL>

Converting integer value from a db column to text in oracle

I have a requirement in db.
1).Table ABC, column: check_amount number number(18,4). This basically contains check amount for eg. 3000.50 to be paid to an employee.
Now a cheque is issued and that check contains this check_amount in number as well as in text form.for eg.check will have:
pay to <emplyee_name> ****$3000.50**** ****THREE THOUSAND DOLLARS AND FIFTY CENTS****
I have to generate this text using DB column value and display that on check.
Can anybody help me out, how can i achieve this in oracle 11g ?
Hint:I have heard of Julien format, but that is not working. Any suggestions is greatly appreciated.
From
Nalin
Since Julian format works only for whole numbers, you can separate the decimal parts and then apply the Julian format trick to the separated numbers. Here's a simple demo.
DECLARE
x NUMBER (8, 2) := 1253.5;
y NUMBER;
z NUMBER;
BEGIN
y := FLOOR (x);
z := 100 * (x - y);
DBMS_OUTPUT.put_line (TO_CHAR (TO_DATE (y, 'j'), 'jsp'));
IF (z > 0)
THEN
DBMS_OUTPUT.put_line (TO_CHAR (TO_DATE (z, 'j'), 'jsp'));
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('err:' || SQLERRM);
END;
There is a limitation while using Julian dates ,It ranges from 1 to 5373484. That’s why if you put the values after 5373484, it will throw you an error as shown below:
ORA-01854: julian date must be between 1 and 5373484
To cater the above problem ,create a function ,and with little trick with j->jsp ,you can fetch the desired result.
CREATE OR REPLACE FUNCTION spell_number (p_number IN NUMBER)
RETURN VARCHAR2
AS
TYPE myArray IS TABLE OF VARCHAR2 (255);
v_decimal PLS_INTEGER;
l_str myArray
:= myArray ('',
' thousand ',
' million ',
' billion ',
' trillion ',
' quadrillion ',
' quintillion ',
' sextillion ',
' septillion ',
' octillion ',
' nonillion ',
' decillion ',
' undecillion ',
' duodecillion ');
l_num VARCHAR2 (50) DEFAULT TRUNC (p_number);
l_return VARCHAR2 (4000);
BEGIN
FOR i IN 1 .. l_str.COUNT
LOOP
EXIT WHEN l_num IS NULL;
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')
|| l_str (i)
|| l_return;
END IF;
l_num := SUBSTR (l_num, 1, LENGTH (l_num) - 3);
END LOOP;
v_decimal := 100* (p_number -TRUNC(p_number)) ;
IF v_decimal>0 THEN
RETURN l_return ||' Dollars AND '||TO_CHAR (TO_DATE (v_decimal, 'j'), 'jsp')|| ' Cents';
ELSE
RETURN l_return ||' Dollars' ;
END IF;
END;
/
select spell_number(122344343444444.23) from dual;
Output:
One Hundred Twenty-Two trillion Three Hundred Forty-Four billion Three Hundred Forty-Three million Four Hundred Forty-Four thousand Four Hundred Forty-Four Dollars AND twenty-three Cents Blog Link

Resources