sqlplus

How to make a menu in SQLPlus or PL/SQL?

北慕城南 提交于 2019-12-01 23:12:04
I am making this program that will have a menu that gets the user's input and performs a certain script based on his/her choice. Something along the lines of: Please make a selection: 1: Do script a 2: Do script b 3: Do script c I looked at this link : How to make SQLPlus or PL/SQL Menu And I was able to get something out of it, BUT it's not fully functional. Because there are certain lines I don't understand. See below. PROMPT 1: Make a sales invoice PROMPT 2: Inquire a sales invoice accept selection PROMPT "Enter option 1-2: " set term off column script new_value v_script -- What's column

I want to pass a variable argument to external SQL file (PL/SQL with SQL*Plus)

人盡茶涼 提交于 2019-12-01 20:05:30
I have search this forum and via google for an answer for my question, but I can't find a specific answer for my challenge. That is why I am asking it here to hope to receive an answer from one of you guys. I want to work with multiple SQL files, whereas one SQL file is the control file that executes the other SQL files with parameters. That file is called: startup.sql I have a table with all my values (don't mind the names of the columns, I changed them for my post). create table control ( S varchar2(15) not null, N varchar2(25 char) not null, B varchar2(25 char) not null, Acheck varchar2(25

Oracle SQLPlus setting environment variable based on variable

谁都会走 提交于 2019-12-01 19:31:25
I want to set the environment variable long based on the size of the XML data I'm trying to retrieve. The idea is something like this: var XML_DATA_SIZE number; SELECT TRIM(LENGTH(xmltype.getClobVal(xml_data))) INTO :XML_data_size FROM xml_tab WHERE key = '1234'; print XML_DATA_SIZE set long XML_DATA_SIZE set pagesize 0 set line 2000 set termout off spool XMLDATA.xml select xml_data from xml_tab where key = '1234'; spool off This yields an error: SP2-0268: long option not a valid number , and the XML file only contains 80 characters. Instead of set long XML_DATA_SIZE try set long &XML_DATA

sqlplus print running statement

时光毁灭记忆、已成空白 提交于 2019-12-01 17:43:20
Is there a way where sqlplus can print what statement it executed. I mean I have some .sql files that I run in a bash script. I need to know when I read the log file which statement sqlplus ran. Example: Say I have this test.sql file: set timing on create table foo (a varchar2(10)); create table bar (b varchar2(10)); exit When I check the log I get this: Table created. Elapsed: 00:00:00.02 Table created. Elapsed: 00:00:00.01 Which is not informative. Is there a way where I can get output like this: Table foo created. Elapsed: 00:00:00.02 Table bar created. Elapsed: 00:00:00.01 Or even like

sqlplus print running statement

情到浓时终转凉″ 提交于 2019-12-01 15:34:55
问题 Is there a way where sqlplus can print what statement it executed. I mean I have some .sql files that I run in a bash script. I need to know when I read the log file which statement sqlplus ran. Example: Say I have this test.sql file: set timing on create table foo (a varchar2(10)); create table bar (b varchar2(10)); exit When I check the log I get this: Table created. Elapsed: 00:00:00.02 Table created. Elapsed: 00:00:00.01 Which is not informative. Is there a way where I can get output like

Pass values read from a file as input to an SQL query in Oracle

元气小坏坏 提交于 2019-12-01 14:18:45
#cat file.txt 12354 13456 13498 #!/bin/bash for i in `cat file.txt` do sqlplus XXXXX/XXXXX@DB_NAME << EOF select *from TABLE_NAME where id="$i" EOF done This is not working for me. Help me how I can solve this. codeforester Here is the right way to use the heredoc << , along with the choice of while read instead of for to read the file: #!/bin/bash while read -r value; do sqlplus xxxxx/xxxxx@db_name << EOF select * from table_name where id='$value'; # make sure heredoc marker "EOF" is not indented EOF done < file.txt See also: How can I write a here doc to a file in Bash script? BashFAQ001 to

sqlplus中使用spool导出数据(转)

帅比萌擦擦* 提交于 2019-12-01 09:33:49
关于SPOOL(SPOOL是SQLPLUS的命令,不是SQL语法里面的东西。) 对于SPOOL数据的SQL,最好要自己定义格式,以方便程序直接导入,SQL语句如: T_port表中:select t.dslamip||'|'||t.dslamno from t_port t where t.dslamip='200.224.49.5'; spool常用的设置 set colsep '|';    //域输出分隔符: 最好在SQL中自己指定。 set echo off;    //显示start启动的脚本中的每个sql命令,缺省为on set feedback off;  //回显本次sql命令处理的记录条数,缺省为on set heading off;   //输出域标题,缺省为on set pagesize 0;   //输出每页行数,缺省为24,为了避免分页,可设定为0。 set termout off;   //显示脚本中的命令的执行结果,缺省为on set trimout on;   //去除标准输出每行的拖尾空格,缺省为off set trimspool on;  //去除重定向(spool)输出每行的拖尾空格,缺省为off set linesize 2500; //设定每行的size 注:LINESIZE要稍微设置大些,免得数据被截断

ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务

不打扰是莪最后的温柔 提交于 2019-12-01 07:20:45
具体操作是删除了原有数据库,然后重新创建了数据库,之后用sqlplus可以正常链接, 但是plsql链接不上,看了网上配置环境变量,配置plsql连接信息都不行。 监听服务也都重启过也不行 tnsnames.ora文件也正常,没有改动, 最后就只有listener.ora文件了,看着也正常,最后参考资料添加了当前数据库信息 如下: (SID_DESC = (SID_NAME = orcl) (ORACLE_HOME = D:\app\fei.yang\product\11.2.0\dbhome_1) ) 修改后的文件截图,红色圈住部分 来源: oschina 链接: https://my.oschina.net/u/1437947/blog/3127738

Oracle SQL privelege authorization on multiple attributes and tables with one statement

萝らか妹 提交于 2019-12-01 07:12:40
问题 Is it possible to grant different privileges on different tables or attributes within the one statement? For example I want to combine: GRANT SELECT ON tbl TO user; and GRANT UPDATE OF attr ON tbl TO user; Furthermore, could I combine granting privilege on a different relation: GRANT INSERT ON tbl2; All in the one statement. 回答1: You can combine multiple object privileges in one GRANT , but only for the same object. For example: GRANT SELECT, UPDATE(column1, column2), INSERT on TBL to user;

In Oracle 11g how do you time weight average data hourly between two dates?

可紊 提交于 2019-12-01 06:29:22
问题 I have replaced my original question with this final answer. With the help from Mr. MTO and Mr. Ponder Stibbons and four months of playing around with my oracle 11G instance, I finally have what you see here. This query is Designed for SCADA systems primarily and will do the following... This query will perform a Time Weighted Average hourly between two date times as TWA, Minimum and Maximum Values during that Interval as Vmin and Vmax. It will also return Time of Minimum and Time of Maximum