Diferència entre revisions de la pàgina «ASIX/M10/UF1/A05/E1»

De Lordwektabyte Wiki
Salta a la navegació Salta a la cerca
Línia 1: Línia 1:
 
==ASIX M10 UF1==
 
==ASIX M10 UF1==
 
===Pt5. Codificació de funcions===
 
===Pt5. Codificació de funcions===
Andreu Potrony (host: PC04)
+
Guillem Solà i Boeck (host: PC05)
 
==Enunciat==
 
==Enunciat==
Crear un procediment/funció, de tal forma que si li passem el nom d'un país, ens mostri els territoris que el formen.
+
Crear un procediment/funció, de tal forma que si li passem el nom d'un llenguatge, ens mostri els paisos que el tenen com a oficial.
  
 
===Solució===
 
===Solució===
 
<source lang="mysqle">
 
<source lang="mysqle">
CREATE DEFINER=`root`@`localhost` PROCEDURE `act_51`(in Nom_pais varchar(30))
+
CREATE DEFINER=`root`@`localhost` PROCEDURE `paisos_llengua`(in llenguatge varchar(30))
 
BEGIN
 
BEGIN
SELECT Distinct City.District
+
DECLARE pais varchar(30);
   FROM Country Join City on Country.code = City.CountryCode
+
  SELECT Country.Name
   WHERE Country.Name=Nom_pais;
+
   FROM CountryLanguage JOIN Country ON Country.Code = CountryLanguage.CountryCode
 +
   WHERE CountryLanguage.Language=llenguatge AND CountryLanguage.IsOfficial="T";
 
END
 
END
 
</source>
 
</source>
Línia 17: Línia 18:
 
==Execució==
 
==Execució==
 
<source lang="mysqle">
 
<source lang="mysqle">
call act_51 ("spain");
+
MariaDB [world]> call paisos_llengua("English");
 
</source>
 
</source>
  
<source lang="mysql">
+
<source>
+--------------------+
+
+--------------------------------------+
| District          |
+
| Name                                |
+--------------------+
+
+--------------------------------------+
| Madrid            |
+
| Anguilla                            |
| Katalonia          |
+
| American Samoa                      |
| Valencia          |
+
| Antigua and Barbuda                  |
| Andalusia          |
+
| Australia                            |
| Aragonia          |
+
| Belize                              |
| Baskimaa          |
+
| Bermuda                              |
| Canary Islands     |
+
| Barbados                            |
| Murcia             |
+
| Canada                              |
| Balears            |
+
| Cocos (Keeling) Islands              |
| Castilla and León  |
+
| Christmas Island                    |
| Galicia            |
+
| Cayman Islands                      |
| Asturia            |
+
| Falkland Islands                    |
| Cantabria          |
+
| United Kingdom                      |
| Navarra            |
+
| Gibraltar                            |
| Kastilia-La Mancha |
+
| Guam                                |
| Extremadura        |
+
| Hong Kong                            |
| La Rioja          |
+
| Ireland                              |
+--------------------+
+
| Saint Kitts and Nevis                |
17 rows in set (0.00 sec)
+
| Saint Lucia                          |
 
+
| Lesotho                              |
Query OK, 0 rows affected (0.00 sec)
+
| Marshall Islands                     |
 
+
| Malta                                |
 +
| Northern Mariana Islands             |
 +
| Montserrat                          |
 +
| Norfolk Island                      |
 +
| Niue                                |
 +
| Nauru                                |
 +
| New Zealand                          |
 +
| Palau                                |
 +
| Saint Helena                        |
 +
| Seychelles                          |
 +
| Turks and Caicos Islands            |
 +
| Tokelau                              |
 +
| Tonga                                |
 +
| Tuvalu                              |
 +
| United States Minor Outlying Islands |
 +
| United States                        |
 +
| Saint Vincent and the Grenadines    |
 +
| Virgin Islands, British              |
 +
| Virgin Islands, U.S.                |
 +
| Vanuatu                              |
 +
| Samoa                                |
 +
| South Africa                        |
 +
| Zimbabwe                            |
 +
+--------------------------------------+
 +
44 rows in set (0.01 sec)
  
 +
Query OK, 0 rows affected (0.01 sec)
 
</source>
 
</source>

Revisió del 15:59, 8 feb 2018

ASIX M10 UF1

Pt5. Codificació de funcions

Guillem Solà i Boeck (host: PC05)

Enunciat

Crear un procediment/funció, de tal forma que si li passem el nom d'un llenguatge, ens mostri els paisos que el tenen com a oficial.

Solució

CREATE DEFINER=`root`@`localhost` PROCEDURE `paisos_llengua`(in llenguatge varchar(30))
BEGIN
DECLARE pais varchar(30);
  SELECT Country.Name
  FROM CountryLanguage JOIN Country ON Country.Code = CountryLanguage.CountryCode
  WHERE CountryLanguage.Language=llenguatge AND CountryLanguage.IsOfficial="T";
END

Execució

MariaDB [world]> call paisos_llengua("English");
+--------------------------------------+
| Name                                 |
+--------------------------------------+
| Anguilla                             |
| American Samoa                       |
| Antigua and Barbuda                  |
| Australia                            |
| Belize                               |
| Bermuda                              |
| Barbados                             |
| Canada                               |
| Cocos (Keeling) Islands              |
| Christmas Island                     |
| Cayman Islands                       |
| Falkland Islands                     |
| United Kingdom                       |
| Gibraltar                            |
| Guam                                 |
| Hong Kong                            |
| Ireland                              |
| Saint Kitts and Nevis                |
| Saint Lucia                          |
| Lesotho                              |
| Marshall Islands                     |
| Malta                                |
| Northern Mariana Islands             |
| Montserrat                           |
| Norfolk Island                       |
| Niue                                 |
| Nauru                                |
| New Zealand                          |
| Palau                                |
| Saint Helena                         |
| Seychelles                           |
| Turks and Caicos Islands             |
| Tokelau                              |
| Tonga                                |
| Tuvalu                               |
| United States Minor Outlying Islands |
| United States                        |
| Saint Vincent and the Grenadines     |
| Virgin Islands, British              |
| Virgin Islands, U.S.                 |
| Vanuatu                              |
| Samoa                                |
| South Africa                         |
| Zimbabwe                             |
+--------------------------------------+
44 rows in set (0.01 sec)

Query OK, 0 rows affected (0.01 sec)