-- 商品表 --
CREATE TABLE "SCOTT"."GOODS"
(
"id" NUMBER NOT NULL,
"name" VARCHAR2(255) NULL,
"price" NUMBER NULL,
"unit" VARCHAR2(255) NULL,
"address" VARCHAR2(255) NULL,
"pack" VARCHAR2(255) NULL,
"property" VARCHAR2(255) NULL,
PRIMARY KEY ("id")
)
NOCOMPRESS
;
COMMENT ON COLUMN "SCOTT"."GOODS"."id" IS '商品编号';
COMMENT ON COLUMN "SCOTT"."GOODS"."name" IS '商品名称';
COMMENT ON COLUMN "SCOTT"."GOODS"."price" IS '价格';
COMMENT ON COLUMN "SCOTT"."GOODS"."unit" IS '单位';
COMMENT ON COLUMN "SCOTT"."GOODS"."address" IS '产地';
COMMENT ON COLUMN "SCOTT"."GOODS"."pack" IS '包装';
COMMENT ON COLUMN "SCOTT"."GOODS"."property" IS '特征';
-- 查询所有根据id排序 --
SELECT * FROM GOODS ORDER BY "id";
-- 单条添加 --
INSERT INTO GOODS ("id","name","price","unit","address","pack","property")
VALUES (1,'三只松鼠',39.9,'120.0g','国产','袋装','带皮');
-- 批量添加 --
INSERT ALL
INTO GOODS ("id","name","price","unit","address","pack","property") VALUES(2,'百草味熟板栗仁',13.0,'90.0g','国产','袋装','果仁')
INTO GOODS ("id","name","price","unit","address","pack","property") VALUES(3,'三只松鼠开口松子',35.9,'245.0g','国产','袋装','带皮')
INTO GOODS ("id","name","price","unit","address","pack","property") VALUES(4,'碧东碧东6味全坚果',110.0,'5.8kg','国产','礼盒装','带皮')
INTO GOODS ("id","name","price","unit","address","pack","property") VALUES(5,'鲁花花生油',165.90,'120.0g','国产','独立包装','压榨')
INTO GOODS ("id","name","price","unit","address","pack","property") VALUES(6,'太粮籼米',99.0,'10.06kg','国产','袋装','无')
SELECT 1 FROM dual;
-- 更新操作 --
UPDATE GOODS SET "name"='三只松鼠开心果' WHERE "id"=1;
-- 删除操作 --
DELETE FROM GOODS WHERE "id"=7;
-- 分页查询 --
-- 1*3 (page*size) 第一页,每页4个
-- (1-1)*4 (page-1)*size
SELECT * FROM(SELECT ROWNUM AS rowno,g.* FROM GOODS g
WHERE ROWNUM <= 1 * 4
)TABLE_ALIAS WHERE TABLE_ALIAS.ROWNO > (1-1)*4;
-- 有order by 情况
SELECT * FROM(
SELECT ROWNUM AS rowno,G.* FROM(
SELECT * FROM GOODS G WHERE G."property"='带皮' ORDER BY G."id" DESC
) G
WHERE ROWNUM <= 1 * 4
) TABLE_ALIAS WHERE TABLE_ALIAS.ROWNO > (1 - 1) * 4;
--- sql server 分页
--- 根据fssj 排序分页,一页10个 ,2 - 1 表示第2 页
SELECT * FROM( SELECT (row_number() over(order by fssj DESC) - 1) / 10 as pagenum,fssj,name,message FROM sjdxfk sf WHERE fssj LIKE '2019-03-08%' AND mbbh LIKE 'scly')t where pagenum = 2 - 1;