Mesaje recente

Members
Stats
  • Total Posts: 17,786
  • Total Topics: 1,234
  • Online today: 340
  • Online ever: 340
  • (Today at 00:10)
Users Online
Users: 0
Guests: 254
Total: 254

Stored procedures in Mysql

Started by kquizak, 10 December 2007, 21:40

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kquizak

Imi trebuie proceduri stocate pe mysql, mi se pare 'brainfucking' sintaxa din mysql(fata de oracle..poate si pt ca asta mi se pare naturala daca toata ziua scriu pl/sql ).Ma poate ajuta careva cu ceva simplu?

mysql> create procedure check_user(in pcnp bigint(13), out exista int)
    -> begin
    -> declare v_cnp bigint(13);
    -> declare v_exista int;
    -> declare cursor c for
    -> Select 1 from users where cnp = v_cnp;
    -> set v_cnp = pcnp;
    -> open c;
    -> fetch c into v_exista;
    -> close c;
    -> set exista = v_exista;
    -> end;//
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cursor c for
Select 1 from users where cnp = v_cnp;
set v_cnp = pcnp;
open c;
f' at line 5
mysql>       

ce vreau eu e asa
create or replace function check_user(pcnp in number(13))  return boolean is
cursor c is
  select true from users where cnp = pcnp;
v_exista boolean := false;
begin
  open c;
  fetch c into v_exista;
  close c;
  return v_exista;
end;
network-tools.ath.cx ---nmap yourself

kman

adica simplificat

create or replace function check_user(pcnp in number(13)) return boolean is
n number;
begin
  select count(1) into n from users where cnp=pcnp;
  if n>0 then
    return true
  else
    return false;
  end if;
end;


ceea ce s-ar putea sa mearga si pe mysql unde nu ai variabile de tip cursor din cate stiu eu.

PS: posibil sa mai fie ceva imbecilitati in ce am scris mai sus ca nu am mai scris SQL de vreo 6 luni.

Praetor

Cred ca totusi trebuie procedure si nu function. Si la return sau la un param out merge 0 sau 1 :)