linux下如何运行plsql

linux下如何运行plsql,第1张

1,首先去运行perl-v命令查看您的linux系统上面是否安装了perl工具,如果已安装的话,会输出版本号,如果没有安装,则安装perl。

sudo apt-get install perl

2,使用cd命令切换到安装的目录下

cd xxxx/ xxxx

3,执行pl文件

sudo /xxxxxpl

使用crontab定时任务
crontab -e 进入编辑
基本格式 :
command
分 时 日 月 周 命令
第1列表示分钟1~59 每分钟用或者 /1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
crontab文件的一些例子:
30 21 /usr/local/etc/rcd/lig>主要有以下几种方法:
1、将SQL语句直接嵌入到shell脚本文件中
代码如下:
--演示环境
[root@SZDB ~]# more /etc/issue
CentOS release 59 (Final)
Kernel \r on an \m
root@localhost[(none)]> show variables like 'version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5612-log |
+---------------+------------+

[root@SZDB ~]# more shell_call_sql1sh
#!/bin/bash
# Define log
TIMESTAMP=`date +%Y%m%d%H%M%S`
LOG=call_sql_${TIMESTAMP}log
echo "Start execute sql statement at `date`" >>${LOG}

# execute sql stat
mysql -uroot -p123456 -e "
tee /tmp/templog
drop database if exists tempdb;
create database tempdb;
use tempdb
create table if not exists tb_tmp(id smallint,val varchar(20));
insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');
select from tb_tmp;
notee
quit"

echo -e "\n">>${LOG}
echo "below is output result">>${LOG}
cat /tmp/templog>>${LOG}
echo "script executed successful">>${LOG}
exit;

[root@SZDB ~]# /shell_call_sql1sh
Logging to file '/tmp/templog'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled
2、命令行调用单独的SQL文件
代码如下:
[root@SZDB ~]# more tempsql
tee /tmp/templog
drop database if exists tempdb;
create database tempdb;
use tempdb
create table if not exists tb_tmp(id smallint,val varchar(20));
insert into tb_tmp values (1,'jack'),(2,'robin'),(3,'mark');
select from tb_tmp;
notee
[root@SZDB ~]# mysql -uroot -p123456 -e "source /root/tempsql"
Logging to file '/tmp/templog'
+------+-------+
| id | val |
+------+-------+
| 1 | jack |
| 2 | robin |
| 3 | mark |
+------+-------+
Outfile disabled
3、使用管道符调用SQL文件
代码如下:
[root@SZDB ~]# mysql -uroot -p123456 </root/tempsql
Logging to file '/tmp/templog'
id val
1 jack
2 robin
3 mark
Outfile disabled
#使用管道符调用SQL文件以及输出日志
[root@SZDB ~]# mysql -uroot -p123456 </root/tempsql >/tmp/templog
[root@SZDB ~]# more /tmp/templog
Logging to file '/tmp/templog'
id val
1 jack
2 robin
3 mark
Outfile disabled
4、shell脚本中MySQL提示符下调用SQL
代码如下:
[root@SZDB ~]# more shell_call_sql2sh
#!/bin/bash
mysql -uroot -p123456 <<EOF
source /root/tempsql;
select current_date();
delete from tempdbtb_tmp where id=3;
select from tempdbtb_tmp where id=2;
EOF
exit;
[root@SZDB ~]# /shell_call_sql2sh
Logging to file '/tmp/templog'
id val
1 jack
2 robin
3 mark
Outfile disabled
current_date()
2014-10-14
id val
2 robin
5、shell脚本中变量输入与输出
代码如下:
[root@SZDB ~]# more shell_call_sql3sh
#!/bin/bash
cmd="select count() from tempdbtb_tmp"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit
[root@SZDB ~]# /shell_call_sql3sh
Warning: Using a password on the command line interface can be insecure
Current count is : 3

[root@SZDB ~]# echo "select count() from tempdbtb_tmp"|mysql -uroot -p123456 -s
3

[root@SZDB ~]# more shell_call_sql4sh
#!/bin/bash
id=1
cmd="select count() from tempdbtb_tmp where id=${id}"
cnt=$(mysql -uroot -p123456 -s -e "${cmd}")
echo "Current count is : ${cnt}"
exit

[root@SZDB ~]# /shell_call_sql4sh
Current count is : 1


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13170297.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-15
下一篇 2023-06-15

发表评论

登录后才能评论

评论列表(0条)

保存