使用 SQL Like 语句查找特定值

Find Specific Values using SQL Like Statement

我正在尝试根据今天的日期从我的 table 中的文件中读取一个文件。比如今天是11月21日,我要显示LIST_21-11-2018。这是我的查询:

CREATE TABLE "FILE_LIST" (
"FILENAME" VARCHAR2(40),
"STATUS" CHAR(1 Byte)
);

INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_20-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_21-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_22-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_23-11-2018','N');

SELECT FILENAME FROM FILE_LIST WHERE FILENAME LIKE %'TO_CHAR(SYSDATE,'DD-MM-YYYY')'% AND STATUS = 'N'

LIKE 语句似乎不起作用。希望知道我的错误是什么....

% 字符必须在您要查找的字符串内:

CREATE TABLE "FILE_LIST" (
"FILENAME" VARCHAR2(40),
"STATUS" CHAR(1 Byte)
);

INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_20-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_21-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_22-11-2018','N');
INSERT INTO "FILE_LIST" ("FILENAME","STATUS") VALUES('LIST_23-11-2018','N');

SELECT FILENAME FROM FILE_LIST WHERE FILENAME LIKE '%' + TO_CHAR(SYSDATE,'DD-MM-YYYY') + '%' AND STATUS = 'N'

试试这个:

SELECT FILENAME FROM FILE_LIST WHERE FILENAME LIKE '%' || TO_CHAR(SYSDATE,'DD-MM-YYYY') || '%' AND STATUS = 'N';