我有一个从命令行执行的 sql 文件,它工作正常。
sqlplus username/password@DBInstance @filename.sql
我的filename.sql看起来是这样的:
set colsep ';'
set echo off
set feedback off
set sqlprompt ''
set trimspool on
set headsep off
set termout off
--set define off
set serveroutput on
set verify off
set autoprint off
set pagesize 0
set linesize 9999
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ', ';
spool STOCK.csv
SELECT ils.item
|| ';'
|| ';'
|| ';'
...
Where loc = store_no
--store_no is typed in the script by hand--
...;
spool …Run Code Online (Sandbox Code Playgroud) 我想为我的 SQL 披萨餐厅数据库创建一份“销售报告”。当我尝试使用 sum(order_amount) 运行 SELECT 查询时,该列未格式化。我正在使用 Oracle SQL。这是代码:
column order_amount heading "Order Amount" format '$9,999,999.00';
select order_id, count(order_id) as "Number of Orders", sum(pizza_quantity) as "Pizzas Sold",
sum(order_amount) as "Total Profit"
from order_details group by order_id;
Run Code Online (Sandbox Code Playgroud)
这是输出:
SQL> select order_id, count(order_id) as "Number of Orders",sum(pizza_quantity) as "Pizzas Sold",
2 sum(order_amount) as "Total Profit"
3 from order_details group by order_id;
Order ID Number of Orders Pizzas Sold Total Profit
---------- ---------------- ----------- ------------
1 2 5 105
6 1 2 20 …Run Code Online (Sandbox Code Playgroud) 我刚刚在 Windows 8.1 计算机上安装了 Oracle XE 18c。
我正在尝试通过高级配置创建新数据库,但是当我进入配置设置步骤时,它会抛出错误:
[DBT-50000] 无法检查可用内存。
我已尝试按照此处的建议绕过验证检查,但仍然没有成功。
我还尝试通过命令提示符创建它:
dbca -createDatabase -silent -gdbName ora18c -templateName General_Purpose.dbc
-sysPassword sys123 -systemPassword sys123 -dbsnmpPassword sys123 -
datafileDestination /u01/oradata -storageType FS -memoryPercentage 20 -
emConfiguration NONE -sampleSchema false -J-Doracle.assistants.dbca.validate.ConfigurationParams=false
Run Code Online (Sandbox Code Playgroud)
但它也会抛出一个错误,指出 Oracle 不可用。
我非常感谢您的帮助。
我有一个具有OUT参数的存储过程,表示错误代码.如果错误代码不是0,那么我引发错误
DECLARE
BEGIN
foo (err_code);
IF (err_code <> 0) THEN
raise_application_error(...);
END;
Run Code Online (Sandbox Code Playgroud)
到目前为止一切都那么好,但这是我的问题.
这段代码(如上所示)由sqlplus执行,sqlplus是从shell脚本调用的,它应该以0/not 0(作为sql脚本)退出.
#shell script
sqlplus ... @myscript
return $?
Run Code Online (Sandbox Code Playgroud)
执行raise_application_error时,控制权返回sqlplus.
sql>
Run Code Online (Sandbox Code Playgroud)
我想要的是一种退出shell的方法,没有sqlplus在$上返回0?
有什么想法吗?提前致谢.
在Windows上使用sqlplus 11g在11g数据库上运行sql脚本.如果在脚本中留下插入行,则Sqlplus挂起.如果我注释掉插入行,脚本将返回记录.
在sql developer中运行时,脚本执行时间<1秒.
我试图使插入语句一个连续的行与相同的resutls.
使用echo on,它在sql最后一行(...为null;)之后立即挂起并显示一个新行开始,从不处理commit.我假设我的insert语句没有正确的语法在sqlplus中运行
命令行调用:
sqlplus e_fraud/e_fraud@eftst2 @"C:\temp\Actimize_ETL\Versions\03\sql\merge2000_insert_new_bank_keys.sql"
Run Code Online (Sandbox Code Playgroud)
sql脚本:
--insert into e_fraud.bank
select stg.bank_key bank_key, stg.bank_key bank_name from
(
select distinct account_bank bank_key
from e_fraud.rgbk_stg_account
where account_bank is not null
or account_bank != ''
UNION
select distinct bank_key
from e_fraud.rgbk_stg_branch
where bank_key is not null
or bank_key != ''
) stg
left outer join e_fraud.bank b
on stg.bank_key = b.bank_key
where b.bank_key is null;
commit;
exit;
Run Code Online (Sandbox Code Playgroud) 这可能有问题:我在我的bash文件中有内联sqlplus调用,我想传递一个参数
这段代码就是我正在尝试的
c_id=`sqlplus -S $login/$password $id << EOF
set pagesize 0
set verify off
set head off
set feedback off
SELECT id from bdd.table where ID not in (select id from bdd.TMP_table) and id > &1 and ROWNUM <= 1000 order by id;
exit;
EOF`
Run Code Online (Sandbox Code Playgroud)
如何在where语句(&1)中使用我的$ id参数?
我通常会SQL在Bash shell脚本中内联编写语句,以便在SQLPlusas-中执行
#! /bin/sh
sqlplus user/pwd@dbname<<EOF
insert into dummy1
select * from dummy2;
commit;
exit;
EOF
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,并dummy1在执行时插入行.我的一位同事前几天来找我,脚本如下(简化)
#! /bin/sh
sqlvar="insert into dummy1 select * from dummy2;commit;"
echo $sqlvar|sqlplus user/pwd@dbname
Run Code Online (Sandbox Code Playgroud)
这个问题是在执行变量时将变量sqlvar扩展*为当前目录中的所有文件,最终会出错 - 如
SQL> insert into dummy1 select <--all the file names in the current directory-->
from dummy2;commit
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
Run Code Online (Sandbox Code Playgroud)
我们对这一个的第一个立场是shell *在通配符上下文中解释并列出所有文件名,而shell变量扩展(不太确定为什么...... ???).所以,为了理解这一点,我们做了类似下面的事情 -
$ var="hello *"
$ echo $var …Run Code Online (Sandbox Code Playgroud) 我一直在修补sqlplus一段时间了,我已经设法让sqlplus将文件内容读入替换变量中:
exit | sqlplus -s login/pass@db @script.sql "`cat file.txt`"
Run Code Online (Sandbox Code Playgroud)
这主要是因为我的脚本需要...甚至保留文件中的换行符.但是,我只使用了50或60字节大小的示例文件.我最终使用的实际文件将至少为几千字节.所以就在这时我决定检查一个替换变量的最大大小:240个字符.
我的sqlplus脚本中有没有办法将文件的内容读入绑定变量?Oracle文档似乎用GET命令暗示了这一点,并说通常你只是用它来加载sql/sqlplus脚本.
http://docs.oracle.com/cd/B10501_01/server.920/a90842/ch13.htm#1009882
file_name [.ext]表示要加载的文件(通常是脚本).
使用SQL工具,我想创建一个具有VARCHAR记录的文本文件.
使用SQL Developer我通过调用脚本成功创建了输出文本文件.但根据我的研究,SQL Developer目前不支持TRIMSPOOl命令,使我的输出具有尾随空格.
这是脚本中的代码:
spool on
set echo off
set verify off
set feedback off
set heading off
set trimspool on
set termout off
spool C:\SQLFiles\Output.txt;
select cust_name || cust_addr as Cust_Details
from customer_db;
spool off;
我现在有SQL Plus 11g,我正在尝试运行我在SQL Developer中创建的脚本.我收到SP2-0606错误,说:
SP2-0606: Cannot create SPOOL file "on.LST:
基于我做的研究,这是因为Spool命令,我没有权限访问默认文件夹??
您能否帮助我做一些我应该改变的设置,以便在SQL Plus中获得所需的结果.