IN expireDate VARCHAR(20),IN resType INT
//-----------------------------------------------------------------------------------
BEGIN
DECLARE a,b,icon_id INT;
DECLARE cur_1 CURSOR FOR SELECT id from `tbl_resource` WHERE discriminator="RC_CON" and robot_type=resType and add_date<=expireDate;/*robot_type 代替资源类型*/
DECLARE CONTINUE HANDLER FOR NOT FOUND
SET b = 1;
OPEN cur_1;
REPEAT
FETCH cur_1 INTO a;
SELECT smallIcon INTO icon_id from tbl_resource WHERE id=a; /*得到缩略图片的id*/
DELETE from `tbl_resource` WHERE parent_id=a; /*删除这个content所含的资源*/
DELETE from `tbl_visitrecords` WHERE resource_id=a; /*删除访问信息*/
DELETE from `tbl_detailrecord` WHERE resource_id=a; /*删城祥细访问信息 */
DELETE from `tbl_comment` WHERE resource_id=a; &n ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:54815324;
mso-list-type:hybri ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:54815324;
mso-list-type:hybri ......
MySQL 存储过程是从 MySQL 5.0 开始增加的新功能。存储过程的优点有一箩筐。不过最主要的还是执行效率和SQL 代码封装。特别是 SQL 代码封装功能,如果没有存储过程,在外部程序访问数据库时(例如 PHP),要组织很多 SQL 语句。特别是业务逻辑复杂的时候,一大堆的 SQL 和条件夹杂在 PHP 代码中,让人不寒而栗。现在有了 MySQL 存储过程,业务逻辑可以封装存储过程中,这样不仅容易维护,而且执行效率也高。
一、MySQL 创建存储过程
“pr_add” 是个简单的 MySQL 存储过程,这个存储过程有两个 int 类型的输入参数 “a”、“b”,返回这两个参数的和。
drop procedure if exists pr_add;
-- 计算两个数之和
create procedure pr_add
(
a int,
b int
)
begin
declare c int;
if a is null then
set a = 0;
end if;
if b is null then
set b = 0;
end if;
set c = a + b;
select c as sum;
/*
return c ......
补充一点:还是中文乱码的问题,就是在配置文件里比如有:
<connection-url>jdbc:mysql://localhost:3306/ejbtest?useUnicode=true&characterEncoding=UTF-8</connection-url>
这句话了,
在新建数据库ejbtest的时候,如果只给ejbtest里的表设置为utf8编码的时候,没有给ejbtest这个数据库设置为utf8编码,在程序插入中文的时候则还是会乱码。
在新建数据库ejbtest的时候,如果只要给ejbtest这个数据库设置为utf8编码,在程序插入中文的时候就不会乱码。 ......
由于直接使用临时表来创建中间表,其速度不如人意,因而就有了把临时表建成内存表的想法。但内存表和临时表的区别且并不熟悉,需要查找资料了。
一开始以为临时表是创建后存在,当连接断开时临时表就会被删除,即临时表是存在于磁盘上的。而实际操作中发现临时表创建后去目录下查看发现并没有发现对应的临时表文件(未断开链接).因而猜测临时表的数据和结构都是存放在内存中,而不是在磁盘中.
这样一想内存表不是也是存在在内存中吗,那么他和临时表有什么区别?他们的速度是什么样子?
查找了官方手册有以下的一些解释:
The MEMORY storage engine creates tables with contents that are stored in memory. Formerly, these were known as HEAP tables. MEMORY is the preferred term, although HEAP remains supported for backward compatibility.
Each MEMORY table is associated with one disk file. The filename begins with the table name and has an extension of .frm to indicate that it stores the table definition.
由此可以看出来内存表会把表结构存放在磁盘上 ,把数据放 ......
修改该表的编码:ALTER TABLE 'tablename' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
查看表的编码:SHOW create table 表名
查看数据库编码:show variables like '%character_set%'
命令行启动mysql服务:net start mysql
命令行进入数据库:mysql -u用户名 -p密码
查看表结构:desc 表名
增加字段:
alter table dbname add column <字段名><字段选项>
修改字段:
alter table dbname change <旧字段名> <新字段名><选项>
删除字段:
alter table dbname drop column <字段名>
复制表结构
create table user_bak like user;
或CREATE TABLE 新表 SELECT * from 旧表 WHERE 1=2
复制表(包括记录)
create table newtable select * from oldtable;
或CREATE TABLE 新表 SELECT * from 旧表
复制旧表的数据到新表(假设两个表结构一样)
INSERT INTO 新表 SELECT * from 旧表
复制旧表的数据到新表(假设两个表结构不一样)
INSERT INTO 新表(字段1,字段2,.......) SELECT 字段1,字段2,...... from 旧表
添加主键
alter table tablename add constraint primary key(id);
添加外键
alter table tablenam ......