å¼æ°ãåãä»ããã¹ãã¢ãããã·ã¼ã¸ã£ãä½ã
å¼æ°ãåãä»ããã¹ãã¢ãããã·ã¼ã¸ã£ã®ãµã³ãã«ã§ãã昨日のプロシージャã«å¼æ°ã§æå®ããååã§ä¸è¦§ãçµãè¾¼ãæ©è½ã追å ãã¦ã¿ã¾ããã
CREATE PROCEDURE proc_GetKittenByName @name VARCHAR(100) AS SELECT * FROM kittens WHERE name = @name
- å¼æ°ã¯ãããã·ã¼ã¸ã£å(proc_GetKittenByName)ã®å¾ããASãã®åã«ãã@<å¼ãæ°å> <å>ãã¨ãã£ãæãã§æå®ãã¾ãã
- ããã·ã¼ã¸ã£ã®å¦çé¨åã§ã¯ãã@nameãã§å¼æ°ãåç §ã§ãã¾ãã
ããã·ã¼ã¸ã£ã®å®è¡ã³ãã³ãã¯æ¬¡ã®éããããã·ã¼ã¸ã£åã®å¾ã«å¼æ°ãæå®ãã¾ãã
EXEC proc_GetKittenByName 'mii'
昨日ã¨åããã¼ã¿ã§ããã°ã以ä¸ã®ã¬ã³ã¼ããè¿ãããã¯ãã
name | age |
---|---|
mii | 1 |
å¼æ°ãè¤æ°ããå ´åã
ã«ã³ãåºåãã§ãã
CREATE PROCEDURE proc_GetKittenByAge @min INT, @max INT AS SELECT * FROM kittens where age between( @min, @max )
å®è¡ããã¡ããã«ã³ãã§ã
EXEC proc_GetKittenByAge 0, 100
å¼æ°ã®åæå¤
ã@<å¼ãæ°å> <å> = <åæå¤>ãã¨ãã¦å¼æ°ã®ããã©ã«ãå¤ãè¨å®ã§ãã¾ãã
CREATE PROCEDURE proc_GetKittenByName2 @name VARCHAR(100) = 'mii' AS SELECT * FROM kittens WHERE name = @name
å¼æ°ãªãã§å®è¡ã§ãã¾ãã
EXEC proc_GetKittenByName2
以ä¸ã®ãã¼ã¿ãè¿ãããã¯ãã
name | age |
---|---|
mii | 1 |