Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Basi di dati ~ informatica triennale > conversioni in plpgsql
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
conversioni in plpgsql

'sera...
ho un dubbio sulle funzioni di plpgsql...
vorrei convertire un char in un integer ( per la precisone la conversione che mi interessa è char(1)-->smallint ) cosi ho creato questa semplice funzione:

code:
CREATE function rrreplace(char(1)) RETURNS character AS $$ BEGIN RETURN $1::smallint+3; END; $$ LANGUAGE plpgsql;


tuttavia, quando la invoco ad esempio tramite SELECT ccconvert('A');
ottnego questo messaggio di errore:

code:
ERROR: invalid input syntax for integer: "a" CONTEXT: PL/pgSQL function "ccconvert" line 1 at RETURN


avete qualche suggerimento???

07-03-2008 22:40
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
n3o
tanto c'è SPASS...

User info:
Registered: Oct 2005
Posts: 134 (0.02 al dì)
Location: Brescia
Corso: Informatica Magistrale
Anno:
Time Online: 1 Day, 19:26:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Se ciò che intendi è la conversione tra carattere e indice nella ASCII table
ci sono un paio di funzioni SQL (per altro esistono identiche anche in PHP!)

code:
SELECT ascii ('a')::smallint; -- 97 SELECT chr (97)::char(1); -- 'a'
A questo punto puoi crearti una funzione che modifichi il valore di
una lettera per esempio
code:
CREATE FUNCTION r3place (CHAR (1)) RETURNS SMALLINT AS $$ BEGIN RETURN (ascii ($1) - ascii ('a') + 1)::SMALLINT; END; $$ LANGUAGE plpgsql;
bye!

__________________
The answer is blowing in the wind...

Last edited by n3o on 07-03-2008 at 23:14

07-03-2008 23:08
Click Here to See the Profile for n3o Click here to Send n3o a Private Message Find more posts by n3o Add n3o to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

grazie mille...
:ciao:

08-03-2008 12:44
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

hola...
altro quesisto, sempre per plpgsql...

ho una query all'interno di una funzione...
ES. query

code:
SELECT * FROM film WHERE titolo = 'il petroliere' AND anno = '2007';

come faccio a sapere se questa query ha prodotto (o no) in output una tupla?
vi è un valore di defaul (EX. 0) che dovrebbe venire restituito?

se si, è possibile fare una cosa del tipo:
code:
IF SELECT * FROM film WHERE titolo = 'il petroliere' AND anno = '2007'; THEN ...

P.S. a me basta una tupla, se l'output fosse un multiinsieme, credo che bisognerebbe ricorrere ai cursori...

08-03-2008 22:56
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

trovata la risposta.. (anche se non sono riuscito a creare la funzione)
mi rispondo da solo...
si utilizza la variabile predefinita FOUND, poiché

A SELECT INTO statement sets FOUND true if a row is assigned, false if no row is returned.

'notte

09-03-2008 00:02
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 21:23.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.103 seconds (62.40% PHP - 37.60% MySQL) con 26 query.