《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
CREATE TABLE bookshelf
(
BOOK_ID NUMBER,
BOOK_NAME VARCHAR2(100),
BOOK_TYPE VARCHAR2(100),
AUTHOR VARCHAR2(100),
INTIME DATE
);
表名为:bookshelf,有列:图书id,图书名称,图书类型,作者,入库时间。通过上面学习的 SELECT语法,来查询一下这张表:
SELECT * FROM bookshelf;
可以发现,新建的bookshelf表没有任何记录。现在,图书馆里已经增加一个空的书架,是不是需要将书放入书架上呢?这时就需要用到 增 操作了。
INSERT INTO bookshelf
(book_id,
book_name,
book_type,
author,
intime)
VALUES
(1,
‘飘’,
‘长篇小说’,
‘玛格丽特·米切尔’,
SYSDATE);
COMMIT;
增 的基本语法:
insert into 表名 (需要插入的列名,用逗号隔开) values (对应列名的值);
通过sql查询发现,这本书《飘》已经放入了书架上,可供大家借用和查看。
改 的基本语法:
UPDATE 表名 SET 列名 = 新的值;
删 的基本语法:
DELETE FROM 表名;
现在来模拟一下场景:
1、修改作者名:
UPDATE bookshelf SET author=‘Margaret Mitchell’;
COMMIT;
2、下架图书:
DELETE FROM bookshelf;
COMMIT;
通过以上两个场景,演示了 改 和 删 两种操作。
先上架3本书:
INSERT INTO bookshelf (book_id,book_name,book_type,author,intime) VALUES (1,‘飘’,‘长篇小说’,‘玛格丽特·米切尔’,SYSDATE);
INSERT INTO bookshelf (book_id,book_name,book_type,author,intime) VALUES (2,‘倾城之恋’,‘爱情小说’,‘张爱玲’,SYSDATE);
INSERT INTO bookshelf (book_id,book_name,book_type,author,intime) VALUES (3,‘从你的全世界路过’,‘短篇小说’,‘张嘉佳’,SYSDATE);
COMMIT;
查看《倾城之恋》:
SELECT * FROM bookshelf WHERE BOOK_NAME = ‘倾城之恋’;
更新《飘》:
UPDATE bookshelf SET author=‘Margaret Mitchell’ WHERE book_name = ‘飘’;
COMMIT;
删除《从你的全世界路过》:
DELETE FROM bookshelf WHERE book_name = ‘从你的全世界路过’;
COMMIT;
通过上面的几个栗子🌰,应该能很好的理解 WHERE 查询条件的使用了。
=======================================================================
文末,赠送给各位看官几个一句SQL画图的趣味小SQL:
⭐️ 五角星:
WITH a AS
(SELECT DISTINCT round(SUM(x) over(ORDER BY n)) x,
round(SUM(y) over(ORDER BY n)) y
FROM (SELECT n,
cos(trunc(n / 20) * (1 - 1 / 5) * 3.1415926) * 2 x,
sin(trunc(n / 20) * (1 - 1 / 5) * 3.1415926) y
FROM (SELECT rownum - 1 n
FROM all_objects
WHERE rownum <= 20 * 5)))
SELECT REPLACE(sys_connect_by_path(point,
‘/’),
‘/’,
NULL) star
FROM (SELECT b.y,
b.x,
decode(a.x,
NULL,
’ ',
‘*’) point
FROM a,
(SELECT *
FROM (SELECT rownum - 1 + (SELECT MIN(x)
FROM a) x
FROM all_objects
WHERE rownum <= (SELECT MAX(x) - MIN(x) + 1
FROM a)),
(SELECT rownum - 1 + (SELECT MIN(y)
FROM a) y
FROM all_objects
WHERE rownum <= (SELECT MAX(y) - MIN(y) + 1
FROM a))) b
WHERE a.x(+) = b.x
AND a.y(+) = b.y)
WHERE x = (SELECT MAX(x)
FROM a)
START WITH x = (SELECT MIN(x)
FROM a)
CONNECT BY y = PRIOR y
AND x = PRIOR x + 1;
📢 注意: 调整期中数字 5,你还可以输出 7 角星,9 角星!
🇨🇳 奥运五环:
WITH a AS
(SELECT DISTINCT round(a.x + b.x) x,
round(a.y + b.y) y
FROM (SELECT (SUM(x) over(ORDER BY n)) x,
round(SUM(y) over(ORDER BY n)) y
FROM (SELECT n,
cos(n / 30 * 3.1415926) * 2 x,
sin(n / 30 * 3.1415926) y
FROM (SELECT rownum - 1 n
FROM all_objects
WHERE rownum <= 30 + 30))) a,
(SELECT n,
(SUM(x) over(ORDER BY n)) x,
round(SUM(y) over(ORDER BY n)) y
FROM (SELECT n,
cos(m / 3 * 3.1415926) * 2 * 15 x,
sin(m / 3 * 3.1415926) * 15 y
FROM (SELECT CASE
WHEN rownum <= 2 THEN
3
WHEN rownum = 3 THEN
-2
ELSE
-6
END m,
rownum - 1 n
FROM all_objects
WHERE rownum <= 5))) b)
SELECT REPLACE(sys_connect_by_path(point,
‘/’),
‘/’,
NULL) star
FROM (SELECT b.y,
b.x,
decode(a.x,
NULL,
’ ',
‘*’) point
FROM a,
(SELECT *
FROM (SELECT rownum - 1 + (SELECT MIN(x)
FROM a) x
FROM all_objects
WHERE rownum <= (SELECT MAX(x) - MIN(x) + 1
FROM a)),
总结
对于面试,一定要有良好的心态,这位小伙伴面试美团的时候没有被前面阿里的面试影响到,发挥也很正常,也就能顺利拿下美团的offer。
小编还整理了大厂java程序员面试涉及到的绝大部分面试题及答案,希望能帮助到大家,
最后感谢大家的支持,希望小编整理的资料能够帮助到大家!也祝愿大家都能够升职加薪!
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
M (SELECT rownum - 1 + (SELECT MIN(x)
FROM a) x
FROM all_objects
WHERE rownum <= (SELECT MAX(x) - MIN(x) + 1
FROM a)),
总结
对于面试,一定要有良好的心态,这位小伙伴面试美团的时候没有被前面阿里的面试影响到,发挥也很正常,也就能顺利拿下美团的offer。
小编还整理了大厂java程序员面试涉及到的绝大部分面试题及答案,希望能帮助到大家,
[外链图片转存中…(img-2ABUv69o-1714678407495)]
[外链图片转存中…(img-lbeIVVMc-1714678407496)]
最后感谢大家的支持,希望小编整理的资料能够帮助到大家!也祝愿大家都能够升职加薪!
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!