473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1398
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

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

Similar topics

7
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
6
by: Terentius Neo | last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a select statement? I mean something like this: Select c.number, call procedure( c.number ) as list from table c With best...
1
by: N. Graves | last post by:
I have a table of education records. ex: recid Empl Course Title Complete 1 123 t123a 123 class A Y 2 123 t123b 123 class B Y 3 234 t123a 123 class A Y 4 345 t123b 123 class B Y etc
1
by: Mr Utkal Ranjan Pradhan | last post by:
Hi Friends I want to develop a windows service application, which will open a port on the machine and constantly it will listen from that port. And when any data comes to that port I want to...
3
by: skinnybloke | last post by:
Hi - can anybody point me to a tutorial that explains how to format a date field within a SELECT statement. I am trying to create a datafeed into another system. The date field displays as ...
1
by: rickn | last post by:
Being new to VB and programming, I'm not sure how to modify the following or if required have a Select statement to NOT allow any duplicates. I'm trying not to have any duplicates in the LOTNUM_72...
1
by: themightyrhino | last post by:
I'm writing a process to perform multiple updates on a main table from information stored in different component reports. As you can see from the below, I'm using a select query to base the update...
2
by: ankitmathur | last post by:
Hi All, I'm facing a problem I'm unable to find a solution for. I hope fellow members would be able to help me out. System Info: PHP v5 MSSQL 2008 Linux box
1
kirubagari
by: kirubagari | last post by:
My form displays a combo box populated by a SQL SELECT statement. The user will select a row from the combo box. I then want the value in a field of the row selected in the combo box to be used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.