x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1395

# Division operator in SQL

Hello All,

Could you please help me in obtaining the result of division operator using other basic operators available in SQL with examples? And division operator is not available in SQL as it is redundant operator.

Regards,
Neeraja
0
NeerajaR
• 3
• 3
• 3
• +3
1 Solution

Commented:
Hello NeerajaR,

Which SQL dialect are you using? (Oracle? T_Sql/Sql Server/ Jet / MySql... which?)

Pete
0

Author Commented:
Hello Peter,

It is Oracle.

Regards,
Neeraja
0

Commented:
Why do think you cannot use a standard division symbol?  (/)

Pete
0

Billing EngineerCommented:
homework?

Actually, maths prove that  a/b = 2^( log2 ( a ) - log2 (b) )
in oracle, the functions are called EXP and LN (resp. LOG), the rest should be your work...

CHeers
0

Commented:
take care with division, to take care of divide-by-zero...

SQL> CREATE TABLE test_table( a number, b number );

Table created.

SQL> INSERT INTO test_table VALUES( 1, 0 );

1 row created.

SQL> INSERT INTO test_table VALUES( 1, 2 );

1 row created.

SQL> SELECT a/b FROM test_table;
SELECT a/b FROM test_table
*
ERROR at line 1:
ORA-01476: divisor is equal to zero

SQL> SELECT a/DECODE(b,0,null,b) FROM test_table;

A/DECODE(B,0,NULL,B)
--------------------

.5

0

Billing EngineerCommented:
another one (more simple):
a/b = a * b^(-1)
0

Commented:
Smells like homework to me...
0

Commented:
or maybe a bit of teen spirit :)
0

Commented:
or does that assume that EE is a true nirvana?
0

Commented:
Okay, that's enough puns for one thread!
0

Billing EngineerCommented:
I think I have given 2 clear indications of what the solution should be (without giving the full answer at it smelled homework)...
0

Commented:
Is there a way to do the right thing here: give angelIII the points AND throw this question away? :-)
0

Commented:
I agree with SV. Interesting maths, if nothing else!

s46.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 3
• 3
• 3
• +3
Tackle projects and never again get stuck behind a technical roadblock.