小编Eri*_*rik的帖子

SQL Server:Where & Like 语句

我对我的 SQL 游戏相当生疏。我有一些代码(见下文)检查数据库实例(instance001、instance002 等),然后查找 LAST_READ 和 LAST_WRITE 字段何时为空,以及上次重置的时间。没有什么太过分了。

我遇到的问题是如何跨多个实例执行此操作。你会看到我注释掉了一个部分。如果我添加了适当的 OR 语句 ( or inst_name like 'instance002'),它不会得到我想要的结果。

示例:instance001 产生 1 条记录。instance002 产生 60。如果我使用, where inst_name like 'instance001' or inst_name like 'instance002' 我会得到 210 条记录。我将如何操作 SQL 以提供 61?

declare @timeString nvarchar(50) = CONVERT(varchar(24), GETDATE(), 120)
select DB_NAME, INST_NAME, MIN([LAST_SRVR_RST]) AS MIN_SRVR_RST, LAST_READ, LAST_WRITE, LOG_DATE=@timeString
from CMS_DB_LAST_READ_WRITE     -- Targeted DB with data.
where inst_name                 -- Targeted instance(s)
    like 'instance001'
    /*
    like 'instance002'
    like 'instance003'  
    like 'instance004'
    */
    and LAST_READ is null       -- …
Run Code Online (Sandbox Code Playgroud)

sql sql-server where

3
推荐指数
1
解决办法
65
查看次数

Bash:awk使用和放置到具有3个条件的数组中

在过去的几个月里,我一直依赖于使用这行代码从文件中获取我需要的内容:

declare -a arr_dbs=(`awk -F: -v key='/software/oracle/ora-11' '$2 ~ key{print $1}' /etc/oratab`)
Run Code Online (Sandbox Code Playgroud)

这将通过/ etc/oratab文件运行,该文件包含如下文本:

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# The first and second fields are the system identifier and home
# …
Run Code Online (Sandbox Code Playgroud)

bash awk

0
推荐指数
1
解决办法
92
查看次数

标签 统计

awk ×1

bash ×1

sql ×1

sql-server ×1

where ×1