LoginSignup
0
0

More than 5 years have passed since last update.

MySQL -- コマンドラインだって、変数をうまく使おう!

Posted at

1_準備するもの

CREATE TABLE `test`.`userProps` (
  `idUser` VARCHAR(16) NOT NULL COMMENT '',
  `seqProp` INT NOT NULL COMMENT '',
  `nameProp` VARCHAR(45) NOT NULL COMMENT '');

INSERT INTO `test`.`userProps` (`idUser`, `seqProp`, `nameProp`) VALUES ('userABC', '1', '心');
INSERT INTO `test`.`userProps` (`idUser`, `seqProp`, `nameProp`) VALUES ('userABC', '2', '技');
INSERT INTO `test`.`userProps` (`idUser`, `seqProp`, `nameProp`) VALUES ('userABC', '3', '体');

2_変数の活用法

SELECT @nameProp:='技';

SELECT seqProp INTO @seqProp FROM userProps WHERE nameProp=@nameProp;

SELECT @seqProp;

※最後のSELECTは、「2」と表示される。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0