468,483 Members | 2,710 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,483 developers. It's quick & easy.

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 1219
Rabbit
12,513 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,513 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
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.