471,058 Members | 995 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,058 software developers and data experts.

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

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

3 1266
Rabbit
12,516 Expert Mod 8TB
You mean a stored procedure? Functions don't return result sets.
Apr 20 '13 #2
Raisen
2
Yup sorry thats the one.
Apr 20 '13 #3
Rabbit
12,516 Expert Mod 8TB
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.

Similar topics

1 post views Thread by N. Graves | last post: by
1 post views Thread by Mr Utkal Ranjan Pradhan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.