📄 ps.result
字号:
set @var=null;select @var is null, @var is not null, @var;@var is null @var is not null @var1 0 NULLexecute stmt using @var, @var, @var;? is null ? is not null ?1 0 NULLcreate table t1 (pnum char(3));create table t2 (pnum char(3));prepare stmt from "select pnum from t2 having pnum in (select 'p1' from t1)";execute stmt;pnumexecute stmt;pnumexecute stmt;pnumdeallocate prepare stmt;drop table t1, t2;create table t1 (a varchar(20));insert into t1 values ('foo');prepare stmt FROM 'SELECT char_length (a) FROM t1';ERROR 42000: FUNCTION test.char_length does not existdrop table t1;prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";execute stmt;fooSELECT FOUND_ROWS();FOUND_ROWS()2execute stmt;fooSELECT FOUND_ROWS();FOUND_ROWS()2deallocate prepare stmt;create table t1 (a char(3) not null, b char(3) not null,c char(3) not null, primary key (a, b, c));create table t2 like t1;prepare stmt from"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) where t1.a=1";execute stmt;aexecute stmt;aexecute stmt;aprepare stmt from"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from(t1 left outer join t2 on t2.a=? and t1.b=t2.b)left outer join t2 t3 on t3.a=? where t1.a=?";set @a:=1, @b:=1, @c:=1;execute stmt using @a, @b, @c;a b c a b cexecute stmt using @a, @b, @c;a b c a b cexecute stmt using @a, @b, @c;a b c a b cdeallocate prepare stmt;drop table t1,t2;SET @aux= "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A, INFORMATION_SCHEMA.COLUMNS B WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA AND A.TABLE_NAME = B.TABLE_NAME AND A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME = 'user'";prepare my_stmt from @aux;execute my_stmt;COUNT(*)37execute my_stmt;COUNT(*)37execute my_stmt;COUNT(*)37deallocate prepare my_stmt;drop procedure if exists p1|drop table if exists t1|create table t1 (id int)|insert into t1 values(1)|create procedure p1(a int, b int)begindeclare c int;select max(id)+1 into c from t1;insert into t1 select a+b;insert into t1 select a-b;insert into t1 select a-c;end|set @a= 3, @b= 4|prepare stmt from "call p1(?, ?)"|execute stmt using @a, @b|execute stmt using @a, @b|select * from t1|id17-117-1-5deallocate prepare stmt|drop procedure p1|drop table t1|drop table if exists t1;Warnings:Note 1051 Unknown table 't1'create table t1 (c1 int(11) not null, c2 int(11) not null,primary key (c1,c2), key c2 (c2), key c1 (c1));insert into t1 values (200887, 860);insert into t1 values (200887, 200887);select * from t1 where (c1=200887 and c2=200887) or c2=860;c1 c2200887 860200887 200887prepare stmt from"select * from t1 where (c1=200887 and c2=200887) or c2=860";execute stmt;c1 c2200887 860200887 200887prepare stmt from"select * from t1 where (c1=200887 and c2=?) or c2=?";set @a=200887, @b=860;execute stmt using @a, @b;c1 c2200887 860200887 200887deallocate prepare stmt;drop table t1;create table t1 (id bigint(20) not null auto_increment,code varchar(20) character set utf8 collate utf8_bin not null default '',company_name varchar(250) character set utf8 collate utf8_bin default null,setup_mode tinyint(4) default null,start_date datetime default null,primary key (id), unique key code (code));create table t2 (id bigint(20) not null auto_increment,email varchar(250) character set utf8 collate utf8_bin default null,name varchar(250) character set utf8 collate utf8_bin default null,t1_id bigint(20) default null,password varchar(250) character set utf8 collate utf8_bin default null,primary_contact tinyint(4) not null default '0',email_opt_in tinyint(4) not null default '1',primary key (id), unique key email (email), key t1_id (t1_id),constraint t2_fk1 foreign key (t1_id) references t1 (id));insert into t1 values(1, 'demo', 'demo s', 0, current_date()),(2, 'code2', 'name 2', 0, current_date()),(3, 'code3', 'name 3', 0, current_date());insert into t2 values(2, 'email1', 'name1', 3, 'password1', 0, 0),(3, 'email2', 'name1', 1, 'password2', 1, 0),(5, 'email3', 'name3', 2, 'password3', 0, 0);prepare stmt from 'select t2.id from t2, t1 where (t1.id=? and t2.t1_id=t1.id)';set @a=1;execute stmt using @a;id3select t2.id from t2, t1 where (t1.id=1 and t2.t1_id=t1.id);id3deallocate prepare stmt;drop table t1, t2;create table t1 (a int);insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);prepare stmt from "select * from t1 limit ?, ?";set @offset=0, @limit=1;execute stmt using @offset, @limit;a1select * from t1 limit 0, 1;a1set @offset=3, @limit=2;execute stmt using @offset, @limit;a45select * from t1 limit 3, 2;a45prepare stmt from "select * from t1 limit ?";execute stmt using @limit;a12prepare stmt from "select * from t1 where a in (select a from t1 limit ?)";ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'prepare stmt from "select * from t1 union all select * from t1 limit ?, ?";set @offset=9;set @limit=2;execute stmt using @offset, @limit;a101prepare stmt from "(select * from t1 limit ?, ?) union all (select * from t1 limit ?, ?) order by a limit ?";execute stmt using @offset, @limit, @offset, @limit, @limit;a1010drop table t1;deallocate prepare stmt;create table t1 (id int);prepare stmt from "insert into t1 (id) select id from t1 union select id from t1";execute stmt;execute stmt;deallocate prepare stmt;drop table t1;create table t1 (id int(11) unsigned not null primary key auto_increment,partner_id varchar(35) not null,t1_status_id int(10) unsigned);insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"),("3", "partner3", "10"), ("4", "partner4", "10");create table t2 (id int(11) unsigned not null default '0',t1_line_id int(11) unsigned not null default '0',article_id varchar(20),sequence int(11) not null default '0',primary key (id,t1_line_id));insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"),("2", "2", "sup", "2"), ("2", "3", "sup", "3"),("2", "4", "imp", "4"), ("3", "1", "sup", "0"),("4", "1", "sup", "0");create table t3 (id int(11) not null default '0',preceeding_id int(11) not null default '0',primary key (id,preceeding_id));create table t4 (user_id varchar(50) not null,article_id varchar(20) not null,primary key (user_id,article_id));insert into t4 values("nicke", "imp");prepare stmt from'select distinct t1.partner_idfrom t1 left join t3 on t1.id = t3.id left join t1 pp on pp.id = t3.preceeding_idwhere exists ( select * from t2 as pl_inner where pl_inner.id = t1.id and pl_inner.sequence <= ( select min(sequence) from t2 pl_seqnr where pl_seqnr.id = t1.id ) and exists ( select * from t4 where t4.article_id = pl_inner.article_id and t4.user_id = ? ) ) and t1.id = ?group by t1.idhaving count(pp.id) = 0';set @user_id = 'nicke';set @id = '2';execute stmt using @user_id, @id;partner_idexecute stmt using @user_id, @id;partner_iddeallocate prepare stmt;drop table t1, t2, t3, t4;prepare stmt from 'select ?=?';set @a='CHRISTINE ';set @b='CHRISTINE';execute stmt using @a, @b;?=?1execute stmt using @a, @b;?=?1set @a=1, @b=2;execute stmt using @a, @b;?=?0set @a='CHRISTINE ';set @b='CHRISTINE';execute stmt using @a, @b;?=?1deallocate prepare stmt;create table t1 (a int);prepare stmt from "select ??";ERROR 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 '?' at line 1prepare stmt from "select ?FROM t1";ERROR 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 '?FROM t1' at line 1prepare stmt from "select FROM t1 WHERE?=1";ERROR 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 'FROM t1 WHERE?=1' at line 1prepare stmt from "update t1 set a=a+?WHERE 1";ERROR 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 '?WHERE 1' at line 1select ?;ERROR 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 '?' at line 1select ??;ERROR 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 '??' at line 1select ? from t1;ERROR 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 '? from t1' at line 1drop table t1;CREATE TABLE b12651_T1(a int) ENGINE=MYISAM;CREATE TABLE b12651_T2(b int) ENGINE=MYISAM;CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2;PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)';EXECUTE b12651;1DROP VIEW b12651_V1;DROP TABLE b12651_T1, b12651_T2;prepare stmt from "select @@time_zone";execute stmt;@@time_zoneSYSTEMset @@time_zone:='Japan';execute stmt;@@time_zoneJapanprepare stmt from "select @@tx_isolation";execute stmt;@@tx_isolationREPEATABLE-READset transaction isolation level read committed;execute stmt;@@tx_isolationREAD-COMMITTEDset transaction isolation level serializable;execute stmt;@@tx_isolationSERIALIZABLEset @@tx_isolation=default;execute stmt;@@tx_isolationREPEATABLE-READdeallocate prepare stmt;prepare stmt from "create temporary table t1 (letter enum('','a','b','c')not null)";execute stmt;drop table t1;execute stmt;drop table t1;execute stmt;drop table t1;set names latin1;prepare stmt from "create table t1 (a enum('test') default 'test') character set utf8";execute stmt;drop table t1;execute stmt;drop table t1;execute stmt;drop table t1;set names default;deallocate prepare stmt;create table t1 (word_id mediumint(8) unsigned not null default '0',formatted varchar(20) not null default '');insert into t1 values(80,'pendant'), (475,'pretendants'), (989,'tendances'),(1019,'cependant'),(1022,'abondance'),(1205,'independants'),(13,'lessiver'),(25,'lambiner'),(46,'situer'),(71,'terminer'),(82,'decrocher');select count(*) from t1 where formatted like '%NDAN%';count(*)6select count(*) from t1 where formatted like '%ER';count(*)5prepare stmt from "select count(*) from t1 where formatted like ?";set @like="%NDAN%";execute stmt using @like;count(*)6set @like="%ER";execute stmt using @like;count(*)5set @like="%NDAN%";execute stmt using @like;count(*)6set @like="%ER";execute stmt using @like;count(*)5deallocate prepare stmt;drop table t1;prepare stmt from 'create table t1 (a varchar(10) character set utf8)';execute stmt;insert into t1 (a) values (repeat('a', 20));select length(a) from t1;length(a)10drop table t1;execute stmt;insert into t1 (a) values (repeat('a', 20));select length(a) from t1;length(a)10drop table t1;deallocate prepare stmt;create table t1 (id int);prepare ins_call from "insert into t1 (id) values (1)";execute ins_call;select row_count();row_count()1drop table t1;create table t1 (a int, b int);insert into t1 (a,b) values (2,8),(1,9),(3,7);prepare stmt from "select * from t1 order by ?";execute stmt using @a;a b2 81 93 7set @a=1;execute stmt using @a;a b1 92 83 7set @a=2;execute stmt using @a;a b3 72 81 9deallocate prepare stmt;select * from t1 order by 1;a b1 92 83 7prepare stmt from "select * from t1 order by ?+1";set @a=0;execute stmt using @a;a b2 81 93 7set @a=1;execute stmt using @a;a b2 81 93 7deallocate prepare stmt;select * from t1 order by 1+1;a b2 81 93 7drop table t1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -