SQL*PLUS를 사용하여 SQL SCRIPT를 동적으로 생성, 수행

제품 : SQL*PLUS
작성날짜 : 2003-05-29
이 Documents 는 SQL 과 SQL*PLUS를 동적으로 생성하고 수행하는 방법을
소개하고 있다. 이를 위해 자주 사용하는 3가지 사용 예를 소개한다.
이 Document는 다음과 같이 구성되어져 있다.
1. CREATING A DYNAMIC DROP TABLE SCRIPT
2. CREATING A DYNAMIC GRANT PRIVILEGES SCRIPT
3. CREATING A DYNAMIC SCRIPT TO SET SQL PROMPT TO DATABASE NAME
1. CREATING A DYNAMIC DROP TABLE SCRIPT
개발 과정 중 우리는 Table을 Drop하고 Original Data를 Import하는 작업을
빈번하게 수행하는데, 이 때 개개의 Drop 문을 사용하지 않고
SET_UP_DROP.SQL 이라 불리우는 다음의 Script를 사용한다.
set heading off
set feedback off
spool drop_all.sql
select 'drop table'||table_name||';'from user_tables;
spool off
set feedback on
start drop_all.sql
DROP_ALL.SQL script 는 다음과 같다.
drop table DEPT;
drop table BONUS;
drop table SALGRADE;
drop table DUMMY;
drop table CUSTOMER;
drop table ORD;
drop table ITEM;
drop table PRODUCT;
drop table PRICE;
2. CREATING A DYNAMIC GRANT PRIVILEGES SCRIPT
자신의 모든 Table 을 다른 사람에게 SELECT 권한을 부여하고자 할 때 다음
의 SET_UP_GRANT.SQL 을 이용하면 빠르고 손쉽게 해결할 수 있다.
set heading off
set feedback off
spool grant_all.sql
select 'grant select on'||table_name||'to SCOTT;'from user_tables;
spool off
set feedback on
start grant_all.sql
GRANT_ALL.SQL 의 script 는 다음과 같다.
grant select on DEPT to SCOTT;
grant select on BONUS to SCOTT;
grant select on SALGRADE to SCOTT;
grant select on DUMMY to SCOTT;
grant select on CUSTOMER to SCOTT;
grant select on ORD to SCOTT;
grant select on ITEM to SCOTT;
grant select on PRODUCT to SCOTT;
grant select on PRICE to SCOTT;
3. CREATING A DYNAMIC SCRIPT TO SET SQL PROMPT TO DATABASE NAME
위의 개념들을 보다 더 잘 사용하기 위해서는 SQL Prompt를 자신의
Database로 변환해주는 SET_UP_PROMPT.SQL Script를 login.sql File 에
추가시켜 자동적으로 SQL*PLUS를 불러 올 수 있게 한다.
이는 Multiple Databases에 유용하다.
set termout off
set heading off
set feedback off
spool set_prompt.sql
select 'set sqlprompt'||value||'>"from v$parameter
where name='db_name';
spool off
start set_prompt.sql
SET_PROMPT.SQL 은 다음과 같다.
set sqlprompt V734>
V$PARAMETER 는 Dynamic Performance Table 의 View 이다. Install 후 SYS
user만이 Dynamic Performance Table을 수행할 수 있으므로 위의 Script를
사용하기 위해 View를 Create 하거나 User에게 Access 권한을 부여하여야
한다.
Reference Documents
<Note:17387.1>

Similar Messages

  • How does SQL*PLUS read script files

    Hello!
    well, it is possible to start sqlplus with an sql script file:
    sqlplus user/pass@srv @my_script.sqlok, so what happens if I delete the file my_script.sql ?
    My script here is about 1 GB big! sqlplus was half way done when I deleted the file.
    Is the sqlplus going to stop with an error? Or just hang?
    I copied the my_script.sql file now to the folder again and I think that sqlplus is still working fine. But can I be sure, that all statements in the script have been processed?
    Thanks in advance!

    Results are OS dependent which you declined to share with us.
    I suspect *NIX & not Windoze.
    On Windoze, you can not delete open file.
    On *NIX open file does not actually get deleted until fclose() is called.
    All in all, you are OK.

  • REPORT generating dilema SQL plus, SQL worksheet, SQL developer, when to yo

    hi i am always generating report for my company into excel sheet..
    and i encoutner a scenario where by i need to do a
    BREAK ON col skip 1 command.
    now i am wondering..
    1) i am using sql developer to export the report into excel sheet everytime. and ihave tried using the break on col skip 1 command, it will not work on sql developer.
    if i run it in a script [F5] i cannot export the data in excel..
    2) if i use sql*plus to do the report, i wont not be able to see all the columns in 1 straight row..
    even though i have set the linesize to the maximum..my tables has too many columns..
    2nd , can sql*plus generate excel file?
    3) what is the difference between sqlworksheet and sqlplus, does oracle10g still support sqlworksheet? i cant seem to find it in oracle10g
    4) somehow i feel certain mechanism inside sqldeveloper sqlworksheet are the same of sqlplus,
    anybody has a clue?
    thats all 10s

    SQL Worksheet is no longer supported.
    The SQL Developer team are trying to make the worksheet in SQLDeveloper compatible with sqlplus, but they have some way to go.
    SQL*Plus can't generate excel files directly, but you can use 'set colsep ,' to get a comma separated file of sorts.
    The maximum linesize in sqlplus is 32767. Are you sure you need all that information in one line?
    You may need to look at better report writers such as Apex or Oracle reports, or use MSQuery to pull the data directly into Excel.

  • Interactive script in SQL*PLUS

    Hi,
    I am a student and we need to write a script to be executed in SQL*PLUS.
    Script has to execute an insert statement but all values need to be provided during runtime and in the end there should be a question if you wan't to save data. When yes then commit when no then rollback.
    Below is my code. Problem is that program asks for variables' values after beginning then it displays all dbms_output.put_line and then continue with pl/sql.
    I want to for examle:
    - display message 'provide date'
    - covvert string date to date type
    - when error then exit, when ok then continue
    - provide other variables in the same way
    - ask for saving.
    My code:
    SET SERVEROUTPUT ON
    set verify off
    ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';
    declare
    do_save varchar2(240) ;
    v_ename varchar2(50);
    v_job varchar2(50);
    v_sal number;
    v_hiredate date;
    v_tmp varchar(50);
    begin
    DBMS_OUTPUT.put_line('Provide name:');
    v_tmp := '&val_ename';
    v_ename := v_tmp;
    DBMS_OUTPUT.put_line('Provide salary:');
    v_tmp := '&val_sal';
    begin
    v_sal := cast(v_tmp as number);
    exception when others then
    DBMS_OUTPUT.put_line('Incorrect salary format.');
    end;
    DBMS_OUTPUT.put_line('Provide data:');
    v_tmp := '&val_hiredate';
    begin
    v_hiredate := to_date(v_tmp);
    exception when others then
    DBMS_OUTPUT.put_line('Incorrect date format.');
    end;
    INSERT INTO EMP(ENAME, SAL, HIREDATE)
    VALUES (v_ename, v_sal, v_hiredate);
    DBMS_OUTPUT.put_line('Do you want to save? [Y/N]');
    do_save := '&val_save';
    do_save := upper(ltrim(substr(nvl(do_save, 'N'), 1,1)));
    IF do_save = 'Y' THEN
    commit;
    DBMS_OUTPUT.put_line('Data saved.');
    ELSE
    rollback;
    DBMS_OUTPUT.put_line('Data rejected.');
    END IF;
    end;
    /

    user10613699 wrote:
    it is not solving my problem,...Why not? Did you test and also check the documentation link?
    SQL> accept DO_SAVE  prompt 'Do you want to save (Y/N)? ';
    Do you want to save (Y/N)? Y
    SQL> begin
      2    if '&do_save' in ('Y','y') then
      3      commit;
      4    else
      5      rollback;
      6    end if;
      7  end;
      8  /
    old   2:   if '&do_save' in ('Y','y') then
    new   2:   if 'Y' in ('Y','y') then
    PL/SQL procedure successfully completed.
    SQL> Edited by: Sven W. on Nov 17, 2008 4:53 PM

  • Semicolon and / in SQL Plus scripts?

    Anyone,
    Seem to have some confusion over the use of / and ; inside PL SQL Scripts run in SQL Plus.
    I seem to get two commits thereby two rows on INSERT clase that has a ; and a /.
    i.e.
    /* Insert record into table for recording statistics on the runtime of this script */
    INSERT INTO MYTABLE ( col1, col2) VALUES ( value1, value2);
    COMMIT;
    /The above will get two of the same rows in the table. Is this an issue with SQL Plus settings? What do people typically use? I have a combination of SQL and DDL in my scripts and I need / for the DDL typically as I understand. How do othere intermix these and what standard is used.

    Dave, here are the very basics.
    The SQL language does not have command separators as only a single command at a time can be issued. Thus the following is invalid SQL:
    SELECT * FROM emp;
    The semicolon as command separator (or terminator) is not valid SQL. This is valid SQL:
    SELECT * FROM emp
    PL/SQL is a programming language similar to Pascal, C and Java. Multiple commands are used in a program. These need to be separated so that the parser/compiler can know where a command starts and where it ends. In PL/SQL the semicolon is used.
    The following is invalid PL/SQL as it is missing command separators:
    declare
    i integer
    begin
    i := 1234
    endThe following is valid PL/SQL :
    declare
    i integer;
    begin
    i := 1234;
    end;SQL*Plus is an Oracle CLI (command line interface) client. It can submit both SQL and PL/SQL to the database. It needs to know when you have stopped entering commands into its input buffer and to submit what you've entered to the database.
    SQL*Plus uses two characters for this. The semicolon and the forward slash. If you want to submit the above SELECT to Oracle using SQL*Plus, SQL*Plus needs to know when to submit its input buffer's content - thus:
    SQL> SELECT * FROM emp;
    Or:
    SQL> SELECT * FROM emp
    SQL> /
    When using PL/SQL in SQL*Plus, SQL*Plus "understands" that the semicolons you use are for the PL/SQL language - not an instruction from you to it to submit its buffer to Oracle for execution.
    The forward slash can also be at anytime used to resubmit the current SQL*Plus input buffer again. E.g.
    SQL> SELECT * FROM emp;
    .. now do the last SQL (or PL/SQL) in the buffer again
    SQL> /[i]

  • (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-22
    (SQL*PLUS HELP) RUNNING PUPBLD OR HELPINS ASKS FOR SYSTEM_PASS
    ==============================================================
    PURPOSE
    이 내용은 SQL*Plus 상에서 SQL*Plus command의 help를 보기 위한 방법이다.
    Problem Description
    SQL*Plus command의 help를 보기 위해서 helpins를 수행하면
    SYSTEM_PASS is not set이라는 에러 메시지가 발생하는 경우가 있다.
    이 자료는 pupbld 또는 helpins를 수행하기 전에 SYSTEM_PASS 환경변수를
    셋팅하는 방법에 대한 자료이다.
    아래와 같은 에러가 발생하는 경우 조치 방법에 대해 알아본다.
    SYSTEM_PASS not set.
    Set and export SYSTEM_PASS, then restart help (for helpins or
    profile for pupbld) installation.
    Workaround
    none
    Solution Description
    이 스크립트는 system user로 database에 connect되어 수행되어야 한다.
    helpins를 수행하기 위해서는 SYSTEM_PASS 환경변수가 셋팅되어 있어야 한다.
    NOTE
    For security reasons, do not set this variable in your shell
    startup scripts. (i.e. .login or .profile.).
    Set this environment variable at the prompt.
    1. Prompt에서 환경변수를 셋팅하기
    For C shell:
    % setenv SYSTEM_PASS system/<password>
    For Korn or Bourne shells:
    $ SYSTEM_PASS=system/<password> ;export SYSTEM_PASS
    2. Now run "$ORACLE_HOME/bin/pupbld" or "$ORACLE_HOME/bin/helpins".
    % cd $ORACLE_HOME/bin
    % pupbld
    or
    % helpins
    주의사항
    $ORACLE_HOME/bin/pupbld 스크립트와 $ORACLE_HOME/bin/helpins 스크
    립트를 수행하기 위해서는 반드시 SYSTEM_PASS 환경변수를 필요로 한다.
    Reference Document
    <Note:1037075.6>

    check it please whether it is a database version or just you are installing a client. Install Enterprize database on 2k system. I you are running a client software then you are to deinstall it.

  • OEM and SQL*Plus(Strange)

    hii,
    i use this command to see the space usage of my tablespaces using this script from sql*plus
    SQL>select * from dba_tablespace_usage_metrics
    After that i use OEM to monitor the space uage of my tablespaces.To my surprise used (%) result from SQL*Plus and OEM are entirely different.
    SYSAUX used percent is 1.06315663 from SQL*Plus where as
    SYSAUX used percent is 96.79 from OEM Grid control.
    For all the tablespaces used(%) value differ
    NOTE:The database i am monotoring from SQL*Plus and OEM is same.
    Why different values for the same database.
    Thankx....

    This is an undocumented view and bugged for DB version under 10g release 2
    Bug 4203626 DBA_TABLESPACE_USAGE_METRICS / V$FILESPACE_USAGE may be wrong
    Range of versions believed to be affected Versions < 10.2

  • Would like to write SQL code to generate a 'spool' statement in SQL Plus.

    Hi,
    We're using Oracle 11.1.
    I'm spooling data to a file from a SQL Plus shell script .
    The format of the file name they're giving me has the current date on the end, so something like:
    filenameMMDDYYYY.txtWhen I write my spool statement I'd like to do it so that I give it the file name with a formatted sysdate at the end.
    I think I need to generate SQL to do this but I don't have experience in generating SQL.
    How would I do this in a SQL Plus Linux shell script?

    set termout off
    col dt new_value dt
    select to_char(sysdate,'YYYYMMDDHH24MISS') dt from dual;
    set termout on
    spool file_&dt
    Handle:      816567
    Status Level:      Newbie
    Registered:      Nov 29, 2010
    Total Posts:      73
    Total Questions:      30 (20 unresolved)
    so many questions & so few answers.
    Edited by: sb92075 on May 12, 2011 4:27 PM

  • Checking Module to Prevent SQL Plus usage on Database

    I have a question regarding logon triggers checking against SYS_CONTEXT('USERENV', 'MODULE'). I created a logon trigger that looks for SYS_CONTEXT('USERENV', 'MODULE') = 'SQLPLUS.EXE'
    and if it matches then it only allows specified users to log in to the database. This code works but I am confused as to why when I check SYS_CONTEXT('USERENV', 'MODULE') after I login in
    shows SQL*Plus which clearly does not match my IF statement in my logon trigger.
    Second issue. If I rename sqlplus.exe to jeff.exe and run it I am abled to log in to the database as a non DBA user. But the module still shows as SQL*Plus. Why is this?
    Database Version: 11.2.0.2 64bit
    OS: Windows Server 2003 R2
    Client: 11.2.0.1
    /*********************Create Trigger******************************/
    CREATE OR REPLACE TRIGGER application_check_al
      after logon ON database 
    DECLARE
      l_username VARCHAR2(20);
      l_module   VARCHAR2(20);
    BEGIN
      l_username := SYS_CONTEXT('USERENV', 'SESSION_USER');
      l_module   := UPPER(SYS_CONTEXT('USERENV', 'MODULE'));
      IF l_module LIKE 'SQLPLUS.EXE' AND
         l_username NOT IN ('SYS', 'SYSTEM', 'DVOWNER', 'DVMGR') THEN
        raise_application_error(-20001, 'SQLPLUS ACCESS RESTRICTED FOR NON DBA USERS');
      END IF;
    END application_check_al;
    /*********************Run SQLPLUS******************************/
    SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 7 12:22:23 2012
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Enter user-name: jeffc@dev
    Enter password:
    ERROR:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-20001: SQLPLUS ACCESS RESTRICTED FOR NON DBA USERS
    ORA-06512: at line 10
    Enter user-name: system@dev
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining, Oracle Database Vault
    and Real Application Testing options
    system@dev> select sys_context('USERENV','MODULE') from dual;
    SYS_CONTEXT('USERENV','MODULE')
    SQL*Plus
    SQL>

    jeff81 wrote:
    That doesn't make sense. Why am I able to log in when I renamed the exe? And why does the module still show as SQL*Plus?You are right - it does not make sense. The idea that Oracle might perhaps set module to SQLPLUS.EXE on executable start, and then re set from SQLPLUS.EXE to SQL*Plus after connect, or in glogin.sql, to ensure it is consistent across all operating system never crossed my mind.
    You might want to refer to Support Note "SQL*Plus Session/Module is Not Showing in V$SESSION" [ID 1312340.1] to see whether anything in there helps. I'm pretty sure http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve040.htm#i2698573 doesn't help much, though.
    I'd certainly be raising it with Support as a potential security challenge, to get that potential hole closed.
    Edited by: Hans Forbrich on Mar 7, 2012 2:23 PM
    I wonder whether Oracle put that capability in there - if an untained SQLPLUS.EXE, it tells you that it is SQLPLUS.EXE, but if renamed it tells you 'SQL*Plus'? Specuklation, but it is one thing I might do to subtly raise the flag. Best bet - ask Support.
    Edited by: Hans Forbrich on Mar 7, 2012 2:29 PM

  • Refcursor not returning rows when called from non SQL*Plus IDE or other

    Hi all,
    I have a very weird problem.
    We have recently performed a minor upgrade to our oracle database and are now using:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    PL/SQL Release 10.2.0.5.0 - Production
    CORE    10.2.0.5.0      Production
    TNS for Linux: Version 10.2.0.5.0 - Production
    NLSRTL Version 10.2.0.5.0 - Production
    5 rows selected.We have a crystal report selecting data from a refcursor returned by a stored procedure.
    The stored procedure updates data when called as well as returning the refcursor in question.
    Observe the following test scenario executed in SQL*Plus:
    SQL> create table testtab (teststr varchar2(100));
    Table created.
    Elapsed: 00:00:00.00
    SQL> insert into testtab values ('X');
    1 row created.
    Elapsed: 00:00:00.00
    SQL> create or replace procedure testtabproc (p_listcur in out sys_refcursor)
      2  as
      3  begin
      4 
      5     open p_listcur for
      6        select *
      7          from testtab
      8         where teststr = 'X';
      9 
    10 
    11     update testtab
    12        set teststr = 'Y';
    13 
    14        commit;
    15 
    16  end;
    17  /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> declare
      2 
      3  v_list_cur sys_refcursor;
      4 
      5  type t_out_rec is record (teststr varchar2(100) );
      6 
      7 
      8 
      9  v_out_rec t_out_rec;
    10 
    11  v_rec_count   number := 0;
    12  v_count_limit number := 10000;
    13 
    14  begin
    15 
    16  dbms_output.put_line('about to call proc');
    17
    18  testtabproc(v_list_cur);
    19 
    20  dbms_output.put_line('about to fetch records');
    21 
    22  fetch v_list_cur into v_out_rec;
    23  while v_list_cur%found loop
    24     v_rec_count := v_rec_count + 1;
    25     if v_rec_count <= v_count_limit then
    26       dbms_output.put_line(v_out_rec.teststr);
    27     end if;
    28  fetch v_list_cur into v_out_rec;
    29  end loop;
    30  dbms_output.put_line('complete. selected '||v_rec_count||' records.');
    31 
    32 
    33  end;
    34  /
    about to call proc                                                                                                                 
    about to fetch records                                                                                                             
    X                                                                                                                                  
    complete. selected 1 records.                                                                                                      
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> select * from testtab;
    TESTSTR
    Y
    1 row selected.
    Elapsed: 00:00:00.00
    SQL> as you can see, the cursor returns data and the table is updated.
    now, our problem is with crystal and also when I use the same test case via another IDE like TOAD.
    No data is returned from the list but the table is still updated.
    We suspect that something is happening that is causing the table to be updated before the refcursor is opened, or at least before the predicates are applied.
    has anyone else encountered this problem before?

    Tubby wrote:
    WhiteHat wrote:
    nope - it works from sqlplus itermitantly (i.e. we always get the debug output but the cursor only sometimes fetches the rows).
    it is almost as if the commit is being executed before the cursor is opened.
    I still havn't been able to reproduce it except with the actual scenario that I am working with...Is the code you are dealing with exactly the same as the skeleton you've posted in your original post? Do you perhaps have a generic exception catcher in there somewhere (perhaps catching and hiding an ORA-01555) when the cursor is being fetched?
    Not that i expect it to make any difference, but i'm curious as to why you've declared your cursor as IN / OUT ?
    p_listcur in out sys_refcursor
    the code structure in the real example is almost identical to that test case I produced - the exception handler is only catering for no_data_found, all other errors should be raised as normal.
    edit: sorry I forgot to add - it's in/out because apparently that's what crystal reports needs in order to use the refcursor..... I'm not a crystal guy so I can't be any more specific than that sorry......
    Edited by: WhiteHat on Oct 11, 2010 9:34 AM

  • Not able to connect as sysoper in sql*plus

    Friends,
    Why i am not able to connect as sysoper?
    OS: win 2000
    Oracle db: oracle 9i
    tool is sql*plus
    SQL> connect / as sysdba
    Connected.
    SQL> show user
    USER is "SYS"
    SQL> connect / as sysoper
    ERROR:
    ORA-01031: insufficient privileges
    Warning: You are no longer connected to ORACLE.
    SQL>
    where i am making mistake?
    Thanks
    Sathyguy

    In Linux i know to add.
    But in windows....i dont know.
    could you please tell me how to add this group.
    Actually we will login to the os using our company name as a group.

  • Can't connect to SQL Plus after installation...

    Windows XP (Admin account)
    installed 10g XE
    I have no other ORACLE_HOME or TNS files.
    All services are started
    here is the listener
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Beta
    Start Date 17-NOV-2005 23:34:31
    Uptime 0 days 0 hr. 5 min. 22 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Default Service XE
    Listener Parameter File C:\oraclexe\app\oracle\product\10.2.0\server\network\a
    dmin\listener.ora
    Listener Log File C:\oraclexe\app\oracle\product\10.2.0\server\network\l
    og\listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1ipc)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=VANDERBI-M8R870)(PORT=1521)))
    Services Summary...
    Service "CLRExtProc" has 1 instance(s).
    Instance "CLRExtProc", status UNKNOWN, has 3 handler(s) for this service...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    when I try to connect with SQL PLUS
    SQL*Plus: Release 10.2.0.1.0 - Beta on Thu Nov 17 23:44:45 2005
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL> connect / as sysdba
    ERROR:
    ORA-12560: TNS:protocol adapter error
    I do have the entry in TNSNAMES.ORA
    XE =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = VANDERBI-M8R870)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = XE)
    any ideas?

    The TNS-12154 (ORA-12154) error appears when SQL*Net cannot find the alias specified for a connection in the TNSNAMES.ORA file or other naming adapter.
    Since we can clearly see the XE entry in your TNSNAMES.ORA file from your further post, the message implies that you are not using the TNSNAMES.ORA that contains the entry, or something is changing the lookup so the entry is not found.
    Using a different TNSNAMES.ORA can occur under the following situations:
    1) You have a TNS_ADMIN environment variable or registry entry that points somewhere other than this TNSNAMES.ORA
    2) You are on Windows NT and are using a SQLPLus that is in a different ORACLE_HOME. The WIndows environment forces the use of the networking subsystem in the ORACLE_HOME as the client program (such as SQLPLUS), which defaults to the TNSNAMES.ORA in the home as the client.
    Things I would check:
    - is there another TNSNAMES.ORA anywhere on the system
    - is there a system environment variable called TNS_ADMIN, or is that string found in the registry
    - is there possibly a second SQLPlus.exe (even on a networked drive) that migt be called before the XE - supplied SQLPLUS
    It is also possible to have a SQLNET.ORA impacting the way TNSNAMES.ORA is used. If all else checks out, we should look at the %ORACLE_HOME%\network\admin\sqlnet.ora in detail as well.
    By the way, the Oracle Network Administration docco has two whole chapters devoted to troubleshooting networking issues, from initial config through data errors in the various config files. If you want to track it faster, check out http://download-east.oracle.com/docs/cd/B19306_01/network.102/b14212/troublestng.htm

  • "ORA-1722 Invalid number" error while runing a SQL script in SQL*Plus

    Hello,
    I created a SQL script that is intended to populate tables with
    baseline data. When I run the script in the SQL*Plus program
    that comes with the Oracle 8.1.6 (client), I receive an "ORA-
    1722 Invalid number".
    The error always occurs when SQL*Plus tries to execute the
    following SQL statement:
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,1046682,'y');
    The datatypes for the columns on the components table are as
    follows:
    db_ind varchar2(2);
    module_id number;
    ext_compid number;
    active varchar2(1);
    It seems that for some reason Oracle is having trouble
    recognizing 1046682 as a number.
    I also tried the following INSERT statements to see if that
    would work:
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,to_number('1046682'),'y');
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,'1046682','y');
    but I still receive the same error message
    Is there some NLS setting(s) I need to modify so that Oracle
    does not give me this error? Does anyone know the answer to
    this problem?
    Your help is greatly appreciated.
    Oscar
    (NOTE: I also receive this same error when trying run the
    script in SQL Navigator and Toad programs)

    Please see the following docs.
    R12: JBO-27122 Error Message Clicking On Supplier Accounting Link With Unexpected Error [ID 1218903.1]
    Supplier Management Accounting Link Gives Unexpected Error and JBO-27122 at SELECT * FROM (select pvsa.ADDRESS_STYLE [ID 1340655.1]
    Adding Accounting Information or Operating Unit Information fails with APP-FND-1564: ORACLE error 1722 in FDFGVD [ID 364265.1]
    Thanks,
    Hussein

  • Error in calling SQL plus program with parameter from Shell script

    This is my Shell script. I am trying to call in the SQL plus program with the parameter and the shell script is registered as a concurrent program.
    PARAMETERS=`echo $1 |tr -d '\"'`
    DB_USER_ID=`echo $PARAMETERS|cut -d" " -f3|cut -d"=" -f2`
    CONN_STRING=$DB_USER_ID
    REQ_DATE=`echo $PARAMETERS|cut -d" " -f9|cut -d"=" -f2`
    timestamp=`date +%m-%d-%y-%H:%M:%S-%Z`
    timestam=`date +%y-%m-%d`
    sqlplus -s $CONN_STRING @ar_statement.sql $REQ_DATE
    chmod 755 statement.sh
    . statement.sh
    My Sql plus program is like this.
    set pagesize 0
    set heading off
    set feedback off
    spool $GEC_TOP/log/ge_ar_statement.sh
    select output_file_name
    from fnd_concurrent_requests
    where trunc(actual_completion_date) = '&2';
    spool off;
    exit;
    When i run the concurrent program, i am getting the following error:
    ar_statement: line 14: REQ_DATE: command not found
    Enter value for 2:
    User requested Interrupt or EOF detected.
    ar_statement.sh: line 1: Enter: command not found
    ar_statement.sh: line 2: User: command not found
    ar_statement
    Program exited with status 127
    I am not strong at Unix Porgamming and i would request someone who can
    help me out as soon as possible.
    I need this solution quickly and thank everyone in advance.
    Thanks.

    Can you put your coding between code statements, like shown in the FAQ. It will be easier to read.
    Looking at your script, my first guess is that crontab will not find your sqlplus since your script does not have $HOME/bin in the $PATH. From what I understand, running .profile in your script will not work either because variables are exported to sub-shells, not to the shell above. You can call your script with a dot like . ./script which means that the script will run like it was typed at the command prompt. But it will be less confusing to define appropriate variables in the script. eg.
    ORACLE_SID=my_instance_name
    ORACLE_HOME=/my_path_to_oracle_home_directory
    LD_LIBRARY_PATH=$ORACLE_HOME/lib
    PATH=$ORACLE_HOME/bin:$PATH
    I remember some slightly different way of coding to handle the sqlplus return codes.
    For instance:
    sqlplus -s /nolog > /dev/null <<-EOF
    connect system/manager
    @ssm.sql
    whenever oserror exit failure
    whenever sqlerror exit failure
    EOF
    sql_err=$?
    if [ $sql_err -ne 0 ]; then
       echo "FAILURE"
    else
       echo "SUCCESS"
    fiThe - in -EOF supresses tab's
    Using connect will prevent ps from showing your login credentials
    In some versions of bash the ending EOF needs to be at the beginning of the line to work.
    Edited by: waldorfm on Jul 14, 2010 7:05 PM
    complaining about putting code between code delimiters and forgot myself ;-)
    Edited by: waldorfm on Jul 14, 2010 7:08 PM
    Btw, if you "source" a script running it like . .script, than an exit in that script will log you out.

  • How to detect client OS from SQL*Plus script

    Sometimes in a SQL*Plus script I need to execute OS commands e.g.
    host rm tempfile.bufHowever of course Windows has no "rm" command by default, so I have to edit the script to use
    host del tempfile.bufNow if I could define &DELETE (for example, "cat"/"type" is another) as a substitution variable, I could just use
    host &DELETE tempfile.bufMaybe I need more coffee but all I could come up with was something like this:
    def rm=rm
    def cat=cat
    spool sqlplus_windows_defs.cmd
    prompt echo def rm=del
    prompt echo def cat=type
    spool off
    host .\sqlplus_windows_defs > sqlplus_windows_defs.sql
    @sqlplus_windows_defs.sql
    host &rm sqlplus_windows_defs.cmd
    host &rm sqlplus_windows_defs.sqlthe idea being that you first define the variables for nix ("rm" and "cat"), then attempt to create and execute a Windows command file containing DOS versions ("dele" and "type"), which does not run under nix. Unfortunately the OS failure message (".sqlplus_windows_defs: not found" in Unix) appears on the screen despite SET TERM OFF, so I'm back where I started.
    I know there are various ways to get the server OS, and you can get the SQL*Plus version with &_SQLPLUS_RELEASE and so on, but I can't see a way to determine the client OS. Any suggestions?

    Thanks guys. This seems to work in Windows XP - will try on Unix when I get a chance:
    col DELETE_COMMAND new_value DELETE_COMMAND
    col LIST_COMMAND new_value LIST_COMMAND
    def list_command = TYPE
    def delete_command = DEL
    SELECT DECODE(os,'MSWIN','TYPE','cat') AS list_command
         , DECODE(os,'MSWIN','DEL','rm')   AS delete_command
    FROM   ( SELECT CASE WHEN UPPER(program) LIKE '%.EXE' THEN 'MSWIN' END AS os
             FROM   v$session
             WHERE  audsid = SYS_CONTEXT('userenv','sessionid') );
    host &LIST_COMMAND xplan_errors.lst
    host &DELETE_COMMAND xplan_errors.lstIf the user doesn't have access to v$session it will just default to the Windows commands.
    http://www.williamrobertson.net/code/xplan.sql

Maybe you are looking for

  • Intermittent Blank Rows coming in BI Publisher Report output

    Hi, We are working on a BI Publisher report output. Issue The report sometimes creates a blank row along with the headings of the report columns. Table has multiple records and between 2 records we have a data being displayed which is optional. When

  • Why can't I connect to WiFi?

    Why can't I connect to WiFi when asked for a password, but I can connect to the same WiFi if no password is required?  When I type in the password, I get the following message, "There was an error joining the AirPort network "Verizon SCH-LC11 d8dd Se

  • Lightroom 4 beta - captions out of sync with photo

    I thought this email export was great and includig my capitons as well.  When I emailed them the captions would't stay with the photo they belonged to - out of order.   Exported 12 pics with email - all out of order.  Exported again just 3 pics and i

  • Create an aac version problem bug

    Hello ! okay so since 30 minutes I'm trying to create an Aac version of a song... I had many problems but I'v solved them. For example I didn't find ''Create aac version '' . Now I'm clicking on ''create aac version '' but the only thing it's telling

  • Head office and branch office accounts

    HI sap gurus, can any explain the configuration steps for head office and branch office accounts in vendor and customer master accounts and how to post an invoice in this configuration Regards, Umesh