12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using Pseudocolumns, Sequences, and <strong>SQL</strong> FunctionsSELECT TO_CHAR(SYSDATE, 'fmMonth DD YYYY') "Today" FROM DUAL;-- the following displays 21-SEP-2005 ADSELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY AD') "Today" FROM DUAL;6.5.4 Using Arithmetic OperatorsYou can use arithmetic operators to create expressions for calculations on data intables. The arithmetic operators include:■■■+ for addition- for subtraction* for multiplication■ / for divideIn an arithmetic expression, multiplication and division are evaluated first, thenaddition and subtraction. When operators have equal precedence, the expression isevaluated left to right. It is best to include parentheses to explicitly determine the orderof operators and provide clarity in the expression.Example 6–16 shows the use of arithmetic operators in expressions with the data in theemployees table. Note the use of a column alias to provide a more useful heading forthe displayed output.Example 6–16 Using Arithmetic Operators-- in the following query the commission is displayed as a percentate instead-- of the decimal that is stored in the databaseSELECT employee_id, (commission_pct * 100) "Commission %" FROM employees;-- in the following query, the proposed new annual salary is calculated-- for employees who report to the manager with Id 145SELECT employee_id, ((salary + 100) * 12) "Proposed new annual salary"FROM employees WHERE manager_id = 145;6.5.5 Using Numeric Functions<strong>Oracle</strong> Database provides a set of numeric functions that you can use in your <strong>SQL</strong>statements to manipulate the numeric values. With numeric functions, you canperform operations that upper case, lower case, trim blanks from, and concatenatecharacter data.Example 6–17 shows how to use numeric functions on numeric data in theemployees table.Example 6–17Using Numeric Functions-- you can use the ROUND function to round off numeric data, in this case to-- two decimal placesSELECT employee_id, ROUND(salary/30, 2) "Salary per day" FROM employees;-- you can use the TRUNC function to truncate numeric data, in this case to-- 0 decimal places; 0 is the default so TRUNC(salary/30) would be sameSELECT employee_id, TRUNC(salary/30, 0) "Salary per day" FROM employees;6-12 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!