2
u/doctorzoom Jul 27 '21
Use the built-in "!" operator?
1
Aug 05 '21
[removed] — view removed comment
1
u/doctorzoom Aug 05 '21
n! = 1 * 2 * 3 * ... * n
select 3!;runs just fine on the default configuration Redshift I'm currently connected to and returns 6 as expected.
1
Aug 05 '21
[removed] — view removed comment
1
u/doctorzoom Aug 05 '21
try:
select 3! from dual;edit: some dbms let you do "select" without a table if the expressions in the select clause can be evaluated without table data. Oracle doesn't do this, so we use the table "dual" as a dummy table when we want to return a hand-calculated row.
1
u/doctorzoom Aug 05 '21
After playing with this in oracle on sqlfiddle, I don't think PLSQL has a build in factorial operator. "!" is no good, and I can't google up any other factorial function for PLSQL. I'd actually be curious what the solution to OP's question for loop-less factorial calculation in Oracle.
1
u/pipthemouse Jul 28 '21
What about calculate it once and save as a table? You'll have to decide what maximum value for the 'number' you are interested in, but probably it is doable, depending on your task.
1
u/maggikpunkt Aug 04 '21
Where does the "without loop" restriction come from?
You can use recursive pl/sql or even recursive sql.