SQL statement in Unix script

Hello
10 g R2 on AIX 6.1.

in a shell script, I want to do:
sqlplus user/password@mydb

select * from mytable.
How to do this?

Thank you.

sqlplus user/password@mydb<>
Select * from myTable.
output
EXPRESSIONS OF FOLKLORE

Tags: Database

Similar Questions

  • Need an example of loop with sql statement in shell script values

    Hello

    I have to present a simultaneous program to each line of the table through script shell (only).

    The table has all the parameters required to pass to the concurrent program.

    I have trouble in a loop with the lines of sql statement results.

    Could someone give me an example of a shell script with a loop with the sql statement values.

    appreciate your time and your help.

    Thank you

    Ganesh

    Hello

    Here is a guide using 3 parameters:

    {

    sqlplus-s $OA_USR / $OA_PWD<>

    SET THE OFF POSITION;

    SET FEEDBACK OFF;

    SET LINESIZE 300;

    SELECT param1, param2, param3

    Of your_param_table;

    ENDOFSQL

    } | while reading line

    do

    If ['$line'] # line non-NULL

    then

    set $line

    param1 = "$1."

    param2 = "$2."

    param3 = "$3."

    # Pass parameters to a script, sql more

    sqlplus-s $apps_usr / $apps_pwd @SUBMIT_CONC_PROG.sql $param1 $param2 $param3

    FI

    fact

    }

    In your SQL * more script you run 3 parameters into variables:

    declare

    VARCHAR2 (10) param1: = ' & &1';

    VARCHAR2 (10) param2: = ' & &2';

    param3 varchar2 (10): = ' & &3';

    .....

  • PL/SQL block in unix script

    The block of problem:
    ***************************************************
    sqlplus-s ${db_login} < < EOF > > ${log_file} 2 > & 1
    Set serveroutput on
    Set of feedback on
    declare
    ERRCODE varchar2 (200);
    ErrMsg varchar2 (200);
    retcur sys_refcursor: = null;
    src_sys varchar2 (20): = null;
    proc varchar2 (200);
    Start
    ora_var: = ' ${unix_var} ";
    If ora_var = 'A' or 'C' = ora_var then
    some_pkg.some_proc_$ {unix_var}(Errcode,errmsg,retcur);
    on the other
    some_pkg.some_proc_$ {unix_var}(Errcode,errmsg,retcur,'${another_unix_var});
    end if;
    end;

    ************************************************
    some_pkg-> lets say a package in oracle
    some_proc_-> lets say a procedure in the above mentioned package where the '' can be 'A' or 'B' or'C.

    Take the varaiable as parameters in calls to shell script.

    Statement of the problem: Whenever I have call the script 'A' or 'B' if part gets called and even when I pass 'C', and then also the if part is called. How to solve this problem?
    HELP PLZ

    Published by: Jaguar on December 13, 2011 04:35

    It should be failed with 'A' as well. The reason is
    ora_var: = ' ${unix_var} ";
    The single quotation mark is hiding the $ from Unix and if ora_var is the real sting ' ${unix_var} "instead of the value of unix_var. I think that put a------should fix before the two single quotes:
    ora_var: = \'${unix_var}\';

  • Why the sql statement was extucted twice in shell script?

    I tried to test the rac load balancing using the shell script depending on suse 10 + oracle 10g rac.
    oracle@SZDB:~> more load_balance.sh
    #!/bin/bash
    for i in {1..20}
    do
    echo $i
    sqlplus -S system/oracle@ORA10G <<EOF
    select instance_name from v\$instance;
    /
    EOF
    sleep 1
    done
    exit 0
    After run the shell script, I got the result to follow.
    oracle@SZDB:~> ./load_balance.sh
    1
    
    INSTANCE_NAME
    ----------------
    ora10g2
    
    INSTANCE_NAME
    ----------------
    ora10g2
    
    2
    
    INSTANCE_NAME
    ----------------
    ora10g1
    
    INSTANCE_NAME
    ----------------
    ora10g1
    
    3
    
    INSTANCE_NAME
    ----------------
    ora10g1
    
    INSTANCE_NAME
    ----------------
    ora10g1
    Seem that the sql statement was run twice in each loop. If you help please take a look. Thanks in advance.

    Robinson

    Because you have one; and one.

  • Call a pl/sql package unix script

    Hello

    With the help of 11.2.0.3 on AIX.

    Is it possible to call the pl/sql package unix script?

    I am cretaing a file in a directory but would like it to automatically write to a directory to archive as well.

    Could use either 2 utl_file.put_lines to 2 separate directories or 1 utl_file and cal script to archive files in another directory. ?

    Thoughts?

    Thank you

    user5716448 wrote:

    Thoughts?

    Use UTL_FILE. FCOPY copy the file you created in the directory of the archive.

    SY.

  • Game of demand does not pick up the good period open to active fixed from the SQL statement

    Hello

    We have a demand that could kick off the simultaneous application of the value: Ixr: list of asset by period and Ixr: reserve book report.


    ON overall demand, we set the parameter: default period based on a SQL = select period_name from FA_DEPRN_PERIODS where book_type_code = 'PER2011' and period_close_date is null


    The query runs with the good period, until we open the new period, the game application will still come closed period.

    When I run this script on the database, it gives the correct name of the open period.


    Why all the demand does not pick up the open period?


    Rock


    Hello

    When planning, the parameter values that you gave when planning will not change.

    For the test, for a simultaneous program, I create a parameter and has given the value 100 tank and default type sql statement and the value as below.

    Select to_char (sysdate, 'dd-mon-yyyy hh24:mi:ss') of double

    If, at the time of the program, it shows a default value such as the date and time with seconds. Then I planned it for every minute.

    When you check in for each race it is seen the first time only, it does not.

    so in your case, you must plan its new after change of period.

    Hope this will help you...

  • will not appear sql statemnt in shell script

    Hello

    I have a shell script with an unfavourable sql she calls another script where I connect to dabase.

    In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?

    Thank you

    Hello

    2650697 wrote:

    Hello

    I have a shell script with an unfavourable sql she calls another script where I connect to dabase.

    In the journal of the script, I see the sql statement and I wish that that do not show me anything. How I make these?

    Thank you

    Your postal code.  It is very difficult to tell what you're doing wrong without knowing what you are doing.

    You can have SQL statements directly in your shell script.  They must be in a script by themselves, said fubar.sql, and shell script must contain

    @fubar

    instead of real SQL statements.

  • Time of execution of SQL statements

    Is there a way to see the time of the last sql instructions? (as the TOAD request viewer)

    Without having to execute the statement as a script and use "set timing on."

    Kind regards

    Carsten

    We show the run down by the exit time

    You can also see the query execution times in the historical Panel SQL

  • Try to run a SQL statement through the window of OEM 12 c run SQL.  Statement fails

    All,

    I have a 11g database.  When it is initially installed, I installed it in $ORACLE_BASE = / orabin/app/oracle/product and $ORACLE_HOME = $ORACLE_BASE/11gDB_R2.  This is the version 11.2.0.1 to give birth to 11.2.0.3.

    Recently, I installed 11.2.0.4 in $ORACLE_BASE/11.2.0.4.  Then, I upgraded my database at 11.2.0.4.  Everything works fine.

    All my scripts on the linux host logon changed to point my environment at $ORACLE_BASE/11.2.0.4 House and my $PATH when I connect to the linux host is: /orabin/app/oracle/product/11.2.0.4/bin:/orabin/app/oracle/product/11.2.0.4/OPatch:/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin

    On my OEM Console, the database appears as 11.2.0.4 and me can manage very well.

    However, when I try to use the window of the OEM Console to execute SQL to execute any type of SQL statement, it fails.

    The failure error is:

    Could not launch/orabin/app/oracle/product/11gDB_R2/bin/sqlplus-s/nolog: no such file or directory

    It would be a mistake since the 11gDB_R2 directory tree (the 11.2.0.3 software) has been removed from the host, now that the database is set to level and working as 11.2.0.4.

    I wonder if somewhere in the OEM software, there is always a pointer to the old ORACLE_HOME?  I can't find anything in the .bashrc or other shell scripts that are executed when a Shell session on the host computer which were still the reference to the old directory of 11gDB_R2 so I'm a bit puzzled.

    I have 8 guests, and all have been improved in the same way at 11.2.0.4.  For some databases, the OEM window run SQL is executing the SQL code.

    Someone has some ideas on this?

    Go to the Configuration of the analysis of the database (when you set the password) and update of the Oracle home.   Also do this for all targets listener on this host as well.

  • MERG to sql statements

    any body can help me to merg below of the sql statements for the information

    No. 1

    Select S.USERNAME, s.sid, s.osuser, t.sql_id, sql_text

    de v$ sqltext_with_newlines t, V$ SESSION s

    t.Address = s.sql_address

    et t.hash_value = s.sql_hash_value

    et s.status = 'ACTIVE'

    et s.UserName <> 'SYSTEM'

    order by s.sid, t.piece

    /


    Statements #2


    SELECT SID, to_char (start_time,'hh24:mi:ss') stime,

    message, (sofar/totalwork) * 100%

    DE v$ session_longops

    sofar/totalwork < 1

    /


    I tried


    Select S.USERNAME, s.sid, s.osuser, t.sql_id, sql_text, to_char (sl.start_time,'hh24:mi:ss') stime,

    1. SL.message, (sl.sofar/sl.totalwork)* 100%

    de v$ sqltext_with_newlines t, V$ SESSION s, v$ session_longops sl

    where s.sid = sl.sid

    and where t.Address = s.sql_address

    et t.hash_value = s.sql_hash_value

    et s.status = 'ACTIVE'

    et s.UserName <> 'SYSTEM'

    et sl.sofar/sl.totalwork < 1

    order by s.sid, t.piece


    but it gives me error.


    SQL > select S.USERNAME, s.sid, s.osuser, t.sql_id, sql_text, to_char(sl.start_time,'hh24:mi:ss') stime,.

    2 sl.message, (sl.sofar/sl.totalwork)* 100%

    3 v $ sqltext_with_newlines t, V$ SESSION s, v$ session_longops sl

    4 where s.sid = sl.sid

    5 and where t.address = s.sql_address

    and t.hash_value = s.sql_hash_value

    6 and 7 s.status = 'ACTIVE '.

    8 and s.username <>'SYSTEM '.

    9 and WHERE the sl.sofar/sl.totalwork < 1

    10 decree by s.sid, t.piece

    11.

    and where t.address = s.sql_address

    *

    ERROR on line 5:

    ORA-00936: lack of expression

    any body can help out?

    Not tested, but you can try:

    SELECT s.sid,

    s.Serial #.

    s.machine,

    Round (SL.elapsed_seconds/60). ':' || MOD(SL.elapsed_seconds,60) has elapsed,

    Round (SL.time_remaining/60). ':' || MOD(SL.time_remaining,60) remaining.

    ROUND (sl.sofar/sl.totalwork*100, 2) progress_pct.

    t.sql_id,

    t.sql_text

    V $ session s,.

    v$ session_longops sl.

    v$ sqltext_with_newlines t

    WHERE s.sid = sl.sid

    AND s.serial # sl.serial = #.

    and t.address = s.sql_address

    and t.hash_value = s.sql_hash_value

    and s.status = 'ACTIVE '.

    and s.username <> 'SYSTEM '.

    order of s.sid, t.piece;

    Or see if you can find a useful script here:

    http://www.Oracle-base.com/DBA/scripts.php

  • Word key missing in to_number conversion in the SQL statement select error

    ORA-00905: lack keyword for the below SQL statement error. It should be of to_number (m.EQUIP_SUB_CLASS_ID, '9999')
    between 3800 and the 3699 where Clause. Is that what I miss in the SQL below?

    SELECT  M.EQUIP_NO,M.EQUIP_CLASS_ID, M.EQUIP_DESCR,M.ORG_ID
      from  MAMIS.EQUIP M
     where M.EQUIP_NO in  (  SELECT  M.EQUIP_NO  from  MAMIS.EQUIP M, MAMIS.ORG O 
    where upper(M.ORG_ID) like upper(O.ORG_ID) 
    and length(replace(translate(M.EQUIP_SUB_CLASS_ID, '0123456789', '000000000'), '0')) is null
    and upper(M.fleet_status) like 'ACTIVE'  
    and upper(M.ORG_ID) not like 'NA'  
    and to_number(m.EQUIP_SUB_CLASS_ID , '9999') 
    between 3699 and 3800  )

    Hello

    I don't see obvious errors.

    Whenever you have a problem, please post a full test script that people can run to recreate the problem and test their ideas. Include CREATE TABLE and INSERT statements for all of the tables involved and the results desired from these data. Format your code so people can read and understand.
    See the FAQ forum {message identifier: = 9360002}

    I saw a couple of things you need to know about Oracle, but none of them would cause an error "Missing key word".

    There is no point in using the LIKE operator if you do use wildcards. For example

    upper (M.fleet_status)      like 'ACTIVE'  
    

    is slower than, but otherwise equivalent to

    upper (M.fleet_status)      = 'ACTIVE'  
    

    What are you trying to do here?

    length ( replace ( translate ( M.EQUIP_SUB_CLASS_ID
                                , '0123456789'
                        , '000000000'
                        )
               , '0'
               )
           )               is null
    

    Want to see if m.equip_sub_class_id consists only of numbers, from ' 0 'to 9'?
    If so, you can simply say

    TRANSLATE ( m.equip_sub_class_id
           , 'X0123456789'
           , 'X'
           )          IS NULL
    

    Depending on your front end, you may need a sem, i-colon (;) the end of your query.

  • DDL or SQL statement

    Guyz,

    I created ODBC for access when I import tables from MS SQL Server 2005 through ODBC and MS Access links MS Access to Oracle 9i which works very well...

    can someone tell me where can I see SCRIPT DDL or SQL statement in the block properties or form in oracle forms after creating the block. as example below.
    SELECT OTb_num,OTb_Acc,OTb_ename,OTb_aname,OTb_Remark FROM DBO_COMPANY
    I use oracle 9i with forms 6i.

    Concerning

    Houda

    Published by: houda Shareef on 6 March 2012 23:23

    Do not create with Create table as select you will find the same question on the column names.
    Create manually the new table with no quotation marks around the column name, and then fill it with:

    insert into table2 select * as table1
    

    François

  • SQL statement for the hierarchy of the Organization

    Nice day

    I was wondering if there is a script/sql statement that would generate the hierarchy of the Organization (similar to the organization hierarchy editor) in Oracle EBS HRMS 11.5.10

    Thank you
    Elmer

    I was wondering if there is a script/sql statement that would generate the hierarchy of the Organization (similar to the organization hierarchy editor) in Oracle EBS HRMS 11.5.10

    Please see if (how to extract HR organization hierarchies in SQL? [REF 463359.1]) help.

    Thank you
    Hussein

  • run in parallel sql statement block

    Hello
    I'm looking for a way to run 2 blocks from the sql statement at the same time in sqlplus

    Block1
    drop table CTSGLOB_TABLE;
    create the table CTSGLOB_TABLE select * from CTSGLOB_VIEW;
    create index TEMPS_CTSGLOB_IDX ON CTSGLOB_TABLE("TEMPS");
    create index ORGA_CTSGLOB_IDX ON CTSGLOB_TABLE("ORGA");
    create index RUBSRH_CTSGLOB_IDX ON CTSGLOB_TABLE("RUBSRH");

    Block2
    drop table CTSGLOB_TABLE_2;
    create the table CTSGLOB_TABLE_2 select * from CTSGLOB_VIEW_2;
    create index TEMPS_CTSGLOB_IDX_2 ON CTSGLOB_TABLE_2("TEMPS");
    create index ORGA_CTSGLOB_IDX_2 ON CTSGLOB_TABLE_2("ORGA");
    create index RUBSRH_CTSGLOB_IDX_2 ON CTSGLOB_TABLE_2("RUBSRH");

    I know that I can open 2 client session to run, but I would like to know another way.

    Best regards
    Jean-Marc

    Well, that depends on what you mean exactly when you say "run 2 blocks from the sql statement at the same time in sqlplus '...
    You can also copy all statements in a sql script and run that, just.
    If this isn't what you want, then please explain why.

  • Date range of calculation with the SQL statement

    I'm sure that there is a way to do this in SQL, but I can't understand it. I can write a PL/SQL script to do it, but prefer to use a SQL statement. My database is the database of Oracle 10.2.0.4.0.

    I have a table that contains information such as employee number, service id, and date effective start-up of the person in this Department. There are data in another table I want to update their department number in based on their date of entry in the range. If I could figure out how to correctly select the entry into force, I can do the rest.

    I have data such as:
    EMP_ID DEPT_NO EFFECTIVE
    -------------- ----------------- ---------------------
    101 1000 1/15 / 2001
    1050 101 5/24 / 2005
    101 2010 6/8/2008
    101 1000 8/2/2010

    I want to write a SELECT statement that returns something like this where the end_date is the eve of the ENTRY into force and the last record didn't an end_date because they are always assigned to this service. In addition, the first record in the column, I won't choose a DEPT_NO because the logic of the entry into force has been added in January 2001, he says if a person started in 1985 they might have zero departments at several times so I won't update all data for this period:

    EMP_ID DEPT_NO EFFECTIVE END_DATE
    --------------- ---------------- ---------------- ----------------
    101 1/14 / 2001
    101 1000 1/15 / 2001 5/23/2005
    1050 101 5/24 / 2005 6/7/2008
    101 2010 6/8/2008-8/1/2010
    101 1000 8/2/2010

    Here is a script to create the data into a temporary table which can be used to write a SELECT statement. I added two records of employees with different dates.

    create the table temp_activity
    (emp_id number (12),)
    dept_no number (12).
    (entry into force);

    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (101,1000,to_date('1/15/2001','MM/DD/YYYY'))
    /
    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (101,1050,to_date('5/24/2005','MM/DD/YYYY'))
    /
    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (101,2010,to_date('6/8/2008','MM/DD/YYYY'))
    /
    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (101,1000,to_date('8/2/2010','MM/DD/YYYY'))
    /
    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (102,1040,to_date('1/15/2001','MM/DD/YYYY'))
    /
    INSERT INTO temp_activity
    (EMP_ID, DEPT_NO, ENTERED INTO FORCE)
    VALUES
    (102,2000,to_date('6/16/2006','MM/DD/YYYY'))
    /

    Any help is appreciated. It's probably easy, but I can't get my brain wrapped around it.

    Thanks - mike
    select  emp_id,
            dept_no,
            effective,
            end_date
      from  (
              select  emp_id,
                      dept_no,
                      effective,
                      lead(effective) over(partition by emp_id order by effective) - 1 end_date,
                      row_number() over(partition by emp_id order by effective) rn
                from  temp_activity
             union all
              select  emp_id,
                      null dept_no,
                      null effective,
                      min(effective) - 1 end_date,
                      0 rn
                from  temp_activity
                group by emp_id
            )
      order by emp_id,
               rn
    /
    
        EMP_ID    DEPT_NO EFFECTIVE  END_DATE
    ---------- ---------- ---------- ----------
           101                       01/14/2001
           101       1000 01/15/2001 05/23/2005
           101       1050 05/24/2005 06/07/2008
           101       2010 06/08/2008 08/01/2010
           101       1000 08/02/2010
           102                       01/14/2001
           102       1040 01/15/2001 06/15/2006
           102       2000 06/16/2006
    
    8 rows selected.
    
    SQL> 
    

    SY.

Maybe you are looking for