n00b question [message #607939] |
Thu, 13 February 2014 12:05 |
|
cozsmin
Messages: 1 Registered: February 2014
|
Junior Member |
|
|
Hello
althow i am not new to programming , sql functions give me some hard time
os : linux 64 , db oracle 11gR2 (no rac )
i was eventually trying to create a function tat will give me a random MAC generator - easy steazy in java/python/bash ...
so i started with tutorials ovr the net on how to create a "hello world" mimimal function
and here i am , trying to replicate what i see on the net , but the results are not the ones expected
this is my code (sqlplus) :
SQL> create function fff
2 begin
3 select * from table1_backup;
4 end;
5 // < i had to press ctrl+c here or else it would not stop the function
SQL>
SQL> select fff();
select fff()
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
I come from mysql small background, is "select fname()" correct ?
please dont tell me that you need a table in order to call the function
Best Regards
[Updated on: Thu, 13 February 2014 12:08] Report message to a moderator
|
|
|
Re: n00b question [message #607940 is a reply to message #607939] |
Thu, 13 February 2014 12:14 |
|
BlackSwan
Messages: 26766 Registered: January 2009 Location: SoCal
|
Senior Member |
|
|
So few lines of code & sooooooo many errors!
1) SQLPLUS reports after the function is successfully created.
2) SELECT inside of PL/SQL code requires INTO clause
3) function requires RETURN statement.
4) function only returns single scalar value
5) function can be tested by doing like below
SELECT SYSDATE FROM DUAL;
1 create or replace function age (dateOfBirth date)
2 return number
3 is
4 mAge number(5,2);
5 begin
6 mAge:=(sysdate-dateOfBirth)/365.25;
7 return mAge;
8* end;
9 /
Function created.
[Updated on: Thu, 13 February 2014 12:36] Report message to a moderator
|
|
|
|