Home » SQL & PL/SQL » SQL & PL/SQL » n00b question (linux , oracle 11gR2)
n00b question [message #607939] Thu, 13 February 2014 12:05 Go to next message
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 Go to previous messageGo to next message
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

Re: n00b question [message #607943 is a reply to message #607939] Thu, 13 February 2014 13:29 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

PL/SQL User's Guide and Reference
Application Developer's Guide - Fundamentals
Database SQL Reference

[Updated on: Thu, 13 February 2014 13:30]

Report message to a moderator

Previous Topic: Oracle SQL Developer questions
Next Topic: Error when calling a function that returns a pipeline from another function
Goto Forum:
  


Current Time: Fri Apr 19 20:44:05 CDT 2024