By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,116 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,116 IT Pros & Developers. It's quick & easy.

How to add a select statement to a function of which will display the results?

P: 2
Hello,

Is it possible to create a function that uses a select statement and displays the results.

Any and all help would be greatly appreciated.

My table:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE COLOURS
  2.        (C_ID VARCHAR2 (4) NOT NULL,
  3.         HC VARCHAR2 (4),
  4.         AC VARCHAR2 (4),
  5.         TOTAL NUMBER (2),
  6.         SCORES NUMBER (2));
  7.  
  8.  
  9. INSERT INTO COLOURS VALUES
  10. ('C1', 'RED', 'BLUE',8,'');
  11.  
  12. INSERT INTO COLOURS VALUES
  13. ('C2', 'RED', 'BLUE', 9,'');
  14.  
  15. INSERT INTO COLOURS VALUES
  16. ('C3','BLUE', 'RED', 10,'');
  17.  
  18. INSERT INTO COLOURS VALUES
  19. ('C4','BLUE', 'RED', 11,'');
  20.  
  21.  

And my select statement:

Expand|Select|Wrap|Line Numbers
  1. SELECT   HC, C_ID, TOTAL, TOTAL(HC) as TOTALSCORES
  2. FROM  COLOURS
  3. ORDER BY totalscores DESC;
  4.  
Thanks again.
Apr 20 '13 #1

✓ answered by Rabbit

The basic syntax to create a procedure is:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE procedurename ()
  2. BEGIN
  3.    SELECT COUNT(*) INTO param1 FROM t;
  4. END
More can be found on the MySQL documentation. https://dev.mysql.com/doc/refman/5.0...procedure.html

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,359
You mean a stored procedure? Functions don't return result sets.
Apr 20 '13 #2

P: 2
Yup sorry thats the one.
Apr 20 '13 #3

Rabbit
Expert Mod 10K+
P: 12,359
The basic syntax to create a procedure is:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE procedurename ()
  2. BEGIN
  3.    SELECT COUNT(*) INTO param1 FROM t;
  4. END
More can be found on the MySQL documentation. https://dev.mysql.com/doc/refman/5.0...procedure.html
Apr 21 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.