Jump to content

stored procedure


jeny

Recommended Posts

hi,

i am trying to implement stored procedure. and here is the procedure

 

CREATE PROCEDURE getData(

  IN in_user VARCHAR(25),

  OUT out_fname VARCHAR(25)

)

 

BEGIN

  SELECT fname

  FROM organization.customers

  WHERE username = in_user

  INTO out_fname

END;

 

i am trying to run this is as SQL statement. it is not running. can you people help me out?

Link to comment
https://forums.phpfreaks.com/topic/135132-stored-procedure/
Share on other sites

i am trying to run this is as SQL statement. it is not running. can you people help me out?

If you want to return the data via a standard SQL statement (e.g. a SELECT), then you might be better creating a function rathe rthan a procedure

 

CREATE FUNCTION getData(
   in_user IN VARCHAR2(25)
)
   RETURN VARCHAR2(25)
IS
   out_fname VARCHAR2(25);
BEGIN
   SELECT fname
     INTO out_fname
     FROM organization.customers
    WHERE username = in_user;

   RETURN out_fname;
END;

 

If you're using Oracle (as I assume you are), you can then call this using:

SELECT getData('Hello World')
  FROM DUAL;

 

Of course, you also need some form of error trapping in case a username of "Hello World" doesn't exist in your customers table.

 

 

Link to comment
https://forums.phpfreaks.com/topic/135132-stored-procedure/#findComment-703846
Share on other sites

i tried to run this statement

 

CREATE FUNCTION getData(

  in_user IN VARCHAR(25)

)

  RETURN VARCHAR(25)

IS

  out_fname VARCHAR(25);

BEGIN

  SELECT fname

    INTO out_fname

    FROM organization.customers

    WHERE username = in_user;

 

  RETURN out_fname;

END;

 

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN VARCHAR(25)

)

  RETURN VARCHAR(25)

IS

  out_fname VARCHAR(25)' at line 2

 

i remove the varchar also and check it is not running.

Link to comment
https://forums.phpfreaks.com/topic/135132-stored-procedure/#findComment-704553
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.