Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE PROCEDURE pr_nowy_klub
- (
- IN id_klubu INT,
- OUT nazwa_klubu VARCHAR(40)
- )
- BEGIN
- SELECT NazwaKlubu INTO nazwa_klubu FROM Kluby WHERE id_klubu = NrKlubu
- END;
- BEGIN
- DECLARE @Nazwa VARCHAR(40);
- CALL pr_nowy_klub (10,@Nazwa);
- message @Nazwa TO client;
- END;
- -----------------------------------------------------------------
- CREATE OR REPLACE FUNCTION liczba_zawodnikow
- (
- IN zapytanie INT
- )
- RETURNS INTEGER
- BEGIN
- DECLARE @liczba_wierszy INTEGER;
- SET @liczba_wierszy = (SELECT COUNT(NrZawodnika) FROM Zawodnicy WHERE zapytanie = NrKlubu);
- RETURN @liczba_wierszy;
- END;
- SELECT liczba_zawodnikow(10);
- -------------------- MOJE
- create or replace function nazwaklubu
- (
- IN @nazwaklubu int
- )
- returns integer
- begin
- declare @nr integer;
- set @nr = (select NrKlubu
- from Kluby
- where NazwaKlubu = @nazwaklubu);
- return @nr;
- end;
- select nazwaklubu('UWKS WAT Warszawa');
- ----
- select * from kluby;
- describe Kluby;
- ----
- select rand();
- ----
- create or replace function fn_losuj
- (
- IN a int,
- IN b int
- )
- return real
- begin
- declare @wynik real;
- set @wynik = rand()*(b+1-a)+a;
- return @wynik;
- end;
- select fn_losuj(5,10);
- CREATE OR REPLACE FUNCTION fn_losuj
- (
- IN a INTEGER,
- IN b INTEGER
- )
- RETURNS INTEGER
- BEGIN
- DECLARE @liczba INTEGER;
- SET @liczba=a+(b+1-a)*rand();
- RETURN @liczba
- END;
- CREATE OR REPLACE FUNCTION fn_losuj
- (
- IN a INTEGER,
- IN b INTEGER
- )
- RETURNS INTEGER
- BEGIN
- DECLARE @liczba INTEGER;
- DECLARE @tmp INTEGER;
- IF (a>b) THEN
- SET @tmp = a;
- SET a=b;
- SET b=@tmp;
- END IF;
- SET @liczba=a+(b+1-a)*rand();
- RETURN @liczba
- END;
- select fn_losuj(15,10);
- ---
- 1 tabela o konstrukcji
- liczba/czestotliwosc/procent
- 2 procedura ktora wypelnia tabele danymi poczatkowymi
- 3 procedura - arg. liczba losowan
- ---
- describe testlosowe;
- create or replace procedure init_testlosowe
- (
- IN a int,
- IN b int
- )
- begin
- declare @cur int;
- declare @tmp int;
- IF (a>b) THEN
- SET @tmp = a;
- SET a=b;
- SET b=@tmp;
- end if;
- set @cur = a;
- while @cur<b
- loop
- insert into testlosowe
- values (@cur, 0, 0);
- //(liczba)
- //values (@cur);
- set @cur=@cur+1;
- end loop
- end;
- ----
- create or replace procedure stworz_testlosowe()
- begin
- create table testlosowe
- (
- liczba integer primary key,
- czestotliwosc integer,
- procent integer
- );
- end;
- ----
- create or replace procedure toss_testlosowe
- (
- IN ilerazy integer,
- IN a int,
- IN b int
- )
- begin
- declare @cur int;
- declare @los int;
- set @cur = 0;
- while @cur < ilerazy
- loop
- set @los = fn_losuj(a,b);
- update testlosowe
- set czestotliwosc = czestotliwosc + 1
- where liczba = @los;
- set @cur = @cur + 1;
- end loop;
- end;
- call toss_testlosowe(30,0,10);
- ----
- create or replace procedure pr_testlosowe
- (
- IN ilerazy integer
- )
- begin
- declare @los int;
- declare @cur int;
- declare a int;
- declare b int;
- set a = (select min(liczba) from testlosowe);
- set b = (select max(liczba) from testlosowe);
- while @cur < ilerazy
- loop
- set @los = fn_losuj(a,b);
- update testlosowe
- set czestotliwosc = czestotliwosc + 1
- where liczba = @los;
- end loop;
- end;
- call pr_testlosowe(30);
- ----
- create or replace procedure testuj
- (
- IN ile int,
- IN min int,
- IN max int
- )
- begin
- IF EXISTS (select 1 from sysobjects where name = 'testlosowe' AND type = 'U')
- then
- drop table testlosowe;
- end if;
- call stworz_testlosowe();
- call init_testlosowe(0,10);
- call toss_testlosowe(30,0,10);
- //call pr_testlosowe(30);
- select * from testlosowe;
- //drop table testlosowe;
- end;
- call testuj(30,0,50);
- ----
Advertisement
Add Comment
Please, Sign In to add comment