Linux/Unix shell 参数传递到SQL脚本
在数据库运维的过程中,Shell 脚本在很大程度上为运维提供了极大的便利性。而shell 脚本参数作为变量传递给SQL以及SQL脚本也是DB
在数据库运维的过程中,Shell 脚本在很大程度上为运维提供了极大的便利性。而shell 脚本参数作为变量传递给SQL以及SQL脚本也是DBA经常碰到的情形之一。本文主要讨论了如何将shell脚本的参数传递到SQL脚本之中并执行SQL查询。
有关shell与SQL之间的变量传递,请参考: Linux/Unix shell sql 之间传递变量
1、启动sqlplus时执行脚本并传递参数
robin@SZDB:~/dba_scripts/custom/awr> more tmp.sh
#!/bin/bash
# ----------------------------------------------
# Set environment here
# Author : Robinson Cheng
# Blog :
# ----------------------------------------------
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile
fi
if [ -z "${1}" ] || [ -z "${2}" ] || [ -z "${3}" ] ;then
echo "Usage: "
echo " `basename $0`
read -p "please input begin ORACLE_SID:" ORACLE_SID
read -p "please input begin date and time(e.g. yyyymmddhh24):" begin_date
read -p "please input end date and time(e.g. yyyymmddhh24):" end_date
else
ORACLE_SID=${1}
begin_date=${2}
end_date=${3}
fi
export ORACLE_SID begin_date end_date
#Method 1: pass the parameter to script directly after script name
sqlplus -S gx_adm/gx_adm @/users/robin/dba_scripts/custom/awr/tmp.sql $begin_date $end_date
exit
robin@SZDB:~/dba_scripts/custom/awr> more tmp.sql
SELECT snap_id, dbid, snap_level
FROM dba_hist_snapshot
WHERE TO_CHAR (begin_interval_time, 'yyyymmddhh24') = '&1'
AND TO_CHAR (end_interval_time, 'yyyymmddhh24') = '&2';
exit;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











According to news on June 30, Li Auto’s L series models, including L7, L8 and L9, have achieved considerable sales results in their respective price ranges. However, according to the editor’s understanding, Li Auto hopes to further increase sales, and its focus is on the performance of another new car, the Li Li L6. Recently, a blogger allegedly photographed a camouflaged Ideal L6 car in a highway service area. According to the photos taken by the blogger, the camouflaged car suspected to be the Lili L6 is not driving normally, but is parked on a trailer. Compared with the white Weilai SUV next to it, even as the lowest-positioned model in the L series, the Lideal L6 appears to be quite large. It is reported that the Lili L6 is positioned as a medium-sized five-seat SUV. Although these photos don't provide much information about the appearance details

Shell scripts use the command interpretation function of Shell to parse a plain text file and then execute these functions. It can also be said that a Shell script is a collection of a series of commands.

Security of Linux Shell Scripting: Avoiding Security Vulnerabilities Introduction: With the popularity and application of Linux operating system, Linux shell script programming has become a very important skill. However, due to the nature and usage of shell scripts, writing unsafe scripts may lead to security vulnerabilities. This article explores how to write secure shell scripts and uses code examples to illustrate how to avoid common security vulnerabilities. 1. Avoid using clear text passwords in shell scripts to avoid

Shell scripts use the command interpretation function of Shell to parse a plain text file and then execute these functions. It can also be said that a Shell script is a collection of a series of commands.

Linux is a powerful operating system with many useful commands and tips to help you use it more efficiently. 1. Check the file check value. During the file copying or transmission process, the file may be damaged or modified. In this case, the check value can be used for verification. Usually, we need to use some interface programs provided by other teams in our work. Whenever the running results of these programs are not as expected, we will compare the md5 check values of both parties to confirm the consistency of the data. There are many ways to generate the check value of a file. Commonly used ones include md5sum check, crc check, sum check, etc. The commands are: md5sumfile_namecksumfile_namesum algorithm parameter file

In Linux, shell refers to a user-oriented command interface, which is expressed as an interface that can be entered by the user. This interface can also feed back running information. The shell receives the commands entered by the user and sends them to the kernel for execution. It is an interpreter program between the Linux kernel and the user. The default shell under Linux is the Bourne Again shell (bash).

Zsh is a powerful shell under Linux. Since most Linux products are installed and use the bash shell by default, this does not affect the geeks' enthusiasm for zsh. Almost every Linux product includes zsh, which can usually be used with apt- Install using package managers such as get, urpmi or yum

In the world of computer programming, finding the number of numbers in a given range that is coprime to a specific number can be a common task. Relatively prime numbers, also known as relative prime numbers, are numbers that have no common factors other than 1. In this article, we will explore finding the number of numbers that are relatively prime to a specific number P between the given integers L and R by using C++ language. Syntax We will first outline the syntax of the method we will use in the following code examples - intcountCoprimes(intL,intR,intP); Algorithm The algorithm we will use to count the number of coprime numbers is as follows − Initialize the variable count as 0, used to store the count of relatively prime numbers. Iterate over each number num starting from L until R. for each
