数值函数
绝对值
select abs(-3) from dual;
向下取整
select floor(3.456) from dual;
向上取整
select ceil(3.1) from dual;
拼接字符串
select concat('hello','world') from dual;
查看数据库
select database() from dual;
查看数据库版本
select version() from dual;
查看数据库密码
select PASSWORD('root') from dual;
视图:视图就是一条SELECT语句执行后返回的结果集,
视图作用:简化用户的操作,对机密数据提供保护作用
创建表
CREATE TABLE t_employee(
ID INT PRIMARY KEY AUTO_INCREMENT,
NAME CHAR(30) NOT NULL,
GENDER CHAR(2) NOT NULL,
AGE INT NOT NULL,
DEPARTMENT CHAR(10) NOT NULL,
SALARY INT NOT NULL,
HOME CHAR(30),
MARRY CHAR(2) NOT NULL DEFAULT '否',
HOBBY CHAR(30)
);
create TABLE t_employee_detail(
ID INT PRIMARY KEY,
POS CHAR(10) NOT NULL,
EXPERENCE CHAR(10) NOT NULL,
CONSTRAINT `FK_ID` FOREIGN KEY(ID) REFERENCES t_employee(ID)
);
INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('张飞','女',21,'人事部','9000','北京','否','网球');INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('刘备','男',22,'研发部','8000','上海','否','音乐');
INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('关羽','女',23,'研发部','9000','重庆','否','无');
INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('马超','女',24,'研发部','9000','四川','是','足球');
INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('赵云','男',25,'销售部','6000','福建','否','游戏');
INSERT INTO t_employee(NAME, GENDER, AGE,DEPARTMENT, SALARY, HOME, MARRY, HOBBY) VALUES('诸葛亮','女',26,'销售部','5000','山西','否','篮球');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(1,'人事管理','工作二年');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(2,'人事招聘','工作二年');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(3,'初级工程师','工作一年');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(4,'中级工程师','工作二年');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(5,'高级工程师','工作三年');
INSERT INTO t_employee_detail(ID,POS,EXPERENCE) VALUES(6,'销售代表','工作二年');
-- 练习1: 创建一个员工基本信息的视图。
select * from t_employee;
select name,gender,age,home,marry,hobby from t_employee;创建视图
create view v_t_employee as select age,home,marry,hobby from t_employee;
select * from v_t_employee;select * from t_employee as t1 LEFT JOIN t_employee_detail as t2 on t1.id=t2.id;
创建视图
create view v_emp_detail as select t1.*,t2.POS,t2.EXPERENCE from t_employee as t1 LEFT JOIN t_employee_detail as t2 on t1.id=t2.id;
select * from v_emp_detail;
修改表视图也会发生变化