Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing functions from SQLPlus

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
Could anyone tell me the steps in running Functions in SQL*Plus?

I am entering:

declare returnval (press enter..takes me to the next line)
begin (press enter..takes me to the next line)
returnval := FUNC_NEW_USERS; (press enter..takes me to the
next line)
end; (press enter..takes me to the next line)


Now, how will I execute???

Thanks
 
dvknn,

Rather than rework the code you posted, following is a hyper-simplified function, followed by its invocation, and sample output:

Section 1: Function definition:
Code:
create or replace function income_tax (salary_amt in number) return number is
begin
        -- certainly many other lines of code could go here.
	return salary_amt * .06;
end;
/

Section 2: Function invocation and results:
Code:
col a heading "Worker" format a12
col b heading "Salary" format 999,999.99
col c heading "Income|Taxes" format 999,999.99
select last_name a, salary b, [b]income_tax(salary)[/b] c
from s_emp
order by salary desc;

                              Income
Worker            Salary       Taxes
------------ ----------- -----------
Garcia         11,550.00      693.00
Ropeburn        1,550.00       93.00
Nguyen          1,525.00       91.50
Sedeghi         1,515.00       90.90
Giljum          1,490.00       89.40
Ngao            1,450.00       87.00
Dumas           1,450.00       87.00
Quick-To-See    1,450.00       87.00
Nagayama        1,400.00       84.00
Magee           1,400.00       84.00
Maduro          1,400.00       84.00
Havel           1,307.00       78.42
Catchpole       1,300.00       78.00
Menchu          1,250.00       75.00
Urguhart        1,200.00       72.00
Nozaki          1,200.00       72.00
Biri            1,100.00       66.00
Schwartz        1,100.00       66.00
Smith             940.00       56.40
Dancs             860.00       51.60
Markarian         850.00       51.00
Chang             800.00       48.00
Patel             795.00       47.70
Patel             795.00       47.70
Newman            750.00       45.00

Let us know if this resolves your question.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 05:40 (25Apr04) UTC (aka "GMT" and "Zulu"), 22:40 (24Apr04) Mountain Time)
 
Your answer resolves my question. But, I already got my answers. But, Thank You for taking time to stop and see my question..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top