Calling SQL statement from a script problem

Hello,
I have a script e.g query.sh:
#!/bin/sh
sqlplus -s ${ORACLE_USER} << HIC
set heading off
set newpage none
SELECT 'ALTER TABLE '||'TEST_TABLE'||' ADD PARTITION '||' P'|| TO_CHAR(TRUNC(sysdate+7), 'IYYY')||'W'|| TO_CHAR(TRUNC(sysdate+7), 'IW')||' VALUES LESS THAN(TO_DATE('''|| TO_CHAR(sysdate + 14, 'YYYYMMDD')||''',''YYYYMMDD''));' FROM DUAL;
exit
HIC
This will actually give me: ALTER TABLE TEST_TABLE ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyyymmdd'));
I am executing this output from the second script. e.g create_part.sh
#!/bin/sh
SQL=`/home/bill/scripts/query.sh`
sqlplus ${ORACLE_USER} << EOF
set serveroutput on size 1000000
set heading off
$SQL
exit
EOF
When I am running the 2nd script I am getting:
SQL> SQL> SQL> SQL> 2 ALTER TABLE test_table ADD PARTITION P2010W46 VALUES LESS THAN(TO_DATE('20101122','yyy
ERROR at line 1:
ORA-01861: literal does not match format string
I suspect that the output from the 1st script wraps to a second line, and it failes to execute properly.
Oracle is 9i
Please suggest a way to overcome this problem.
Thank you in advance.

If you are not passing in any variable values that you need the shell to substitute intot he source then placing the SQL into a separate .sql file and then just using start scriptname from the shell can simplify the code especially if any shell script meta-characters like '$' appear in the SQL. Otherwise you have to escape the meta-characters.
sqlplus /nolog <<EOF
start script_name
exit
EOF
It is also possible to write the sqlplus script to accept substitution variable from the caller so the line above would look like start script_name $var1 $var2
HTH -- Mark D Powell --

Similar Messages

  • Calling SQL statements from Shell scripts

    Hi,
    I want to call external package procedures, declare some variables & do some oracle validations in the shell script.
    How SQL environment is set in shell script & is this one time process or I have to write few statements before every SQL statement.
    Please explain with an example.
    Thanks..

    is this one time process Yes. Example :
    $ cat script.sh
    export ORACLE_HOME=/home/oracle/base/OraHome10
    export ORACLE_SID=db102
    export PATH=$ORACLE_HOME/bin:$PATH
    sqlplus -s / as sysdba << EOF
    select to_char(sysdate,'dd/mm/yyyy hh24:mi:ss') date_time
    from dual;
    exit
    EOF
    sqlplus -s / as sysdba << EOF
    col global_name for a60
    select * from global_name;
    exit
    EOF
    $ ./script.sh
    DATE_TIME
    27/02/2008 11:11:27
    GLOBAL_NAME
    DB102
    $

  • Call sql statement from JComboBox component

    Hi there,
    I Have created a frame to populate two JComboBoxs, I'm populating the first one from a database using SQL, this datable is showing the category to below every report.
    anybody know how can I select from my first JComboBox a record a call a second SQL statement acutomatic, the idea is populate me second JCombox with data like my first one, remember the first one is a header

    With a JComboBox you have to be careful that you don't run a query when just the cursor is moved up or down the list. If you want the listener to fire just when enter is pressed or the mouse is clicked, then do this:
    //This stops events being fired when the cursor is used on the list
    comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);You should also attach an event listener like this one:
    comboBox.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent evt) {
                            executeSomeQuery(comboBox.getSelectedItem().toString());               }
              });Or something similar to above, have a play around with it and it should work how you want it to.
    Message was edited by:
    JStudent911

  • How To Execute SQL Statements From Shell Scripts?

    I need to extecute some SELECT statements from a shell scripts. Could anybody kindly tell me how to do that, or which document i should refer to ? Thank you very much!

    You can execute SQLPlus with the SQL in a file (sqlplus -s @<sql-script>).

  • Error while calling sql loader from shell script.

    In the table DBMS_SCHEDULER_JOB_RUN_DETAILS im getting the error as ""SQL*Loader-128: unable to begin a session ORA-01017: invalid username/password; logon denied""....do we need previliges for creating session of the db user????.....or wht other settings we require to do.....if the username and password used is right.

    user1122577 wrote:
    SQL*Loader-128: unable to begin a session ORA-01017: invalid username/password; logon deniedI don't know, but somehow the error you recived looks like ORA-01017 : )
    [oracle@dell ~]$ sqlplus ring/ring
    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Jul 22 11:50:58 2010
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, Data Mining and Real Application Testing options
    SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
    With the Partitioning, Data Mining and Real Application Testing options
    [oracle@dell ~]$
    [oracle@dell ~]$
    [oracle@dell ~]$ sqlldr ring/ring
    control = i don't have it
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Jul 22 11:51:08 2010
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL*Loader-500: Unable to open file (i don't have it.ctl)
    SQL*Loader-553: file not found
    SQL*Loader-509: System error: No such file or directory
    [oracle@dell ~]$
    [oracle@dell ~]$
    [oracle@dell ~]$ sqlldr ring/wrongpassword
    control = i don't have it again
    SQL*Loader: Release 10.2.0.4.0 - Production on Thu Jul 22 11:51:38 2010
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL*Loader-128: unable to begin a session
    ORA-01017: invalid username/password; logon denied
    [oracle@dell ~]$

  • Run sql statement from batch file

    How can we execute SQL Statement using Batch file???
    I did a test.
    create batch file test.bat
    sqlplus "username@db /pass" @\script.sql
    script.sql file has following statement
    select sysdate from dual;
    exit
    it is working but I want to call sql statement in the same batch file instead of calling .sql script file. how can I do that any idea..

    This is very easy in unix shell scripting, but AFAIK, not available with Windows. It's a function of how the shell/command processor handles input redirection.

  • Calling Sql*Loader from oracle Form builder

    How do i call sql* loader from my forms to import the external data in different formats into my existing database?
    Specify the flexibility of sql* loader to import external data from .txt files or .xls files.
    Would be thankful if certain examples are given along with the answer.

    Hi,
    1. First you have to create seperate ctl (Control files) which maps to different file formats
    2. Using Oracle Forms,
    2a) You can use the 'HOST' command to execute the command line ie. In this case executing
    SQL*Loader script
    2b) You also have the feature in ORACLE forms to read text files and load the data into
    ORACLE db.
    This can be achieved by using TEXT_IO package which comes with ORACLE Forms.
    Hope this helps
    Ta
    Shailender

  • How to call SQL statements in InDesign CS6?

    Hi,
         My plug-in needs to interact with the database, and update the database content, how should I do, can I call SQL statements in InDesign CS6?
         Thanku very much.

    The same way you'd call them from any C++ program. You don't mention which platform, and that probably makes a difference.
    I'm accessing an SQL database in InDesign CS6 on Windows. I'm using the ODBC interface to SQL database that Windows provides, via the nanodbc wrapper. So I'm linking to odbc32.lib and odbccp32.lib, and including the nanodbc.cpp and nanodbc.h files. (See http://lexicalunit.github.io/nanodbc/ )
    Paul.

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • Exec SQL statement from BW to MS SQL

    Hi Experts,
    I need to execute sql statement from BW on MS SQL Server.
    I want to do it in process chain. There is a so called ABAP Program Component.
    How to implement such a program or function module that will execute on MS SQL Server an sql statement such as for instance:
    "Create view SOME_VIEW as select * from XTABLE".
    I have already configured database connection using DBCO transaction.
    Waiting for response.
    Krzysztof

    Thanks, but that is not what I was asking for.
    I just need to send some SQL statement from BW to MS SQL Server using ABAP program (exec sql or something like this).
    Could you provide me a pattern of such an ABAP program?
    The sql statement is not importent here, I have already extracted data from MS SQL to BW, I have configured dataflow, process chains and so on.
    No I need to determine DELTA on MS SQL Server. I've got some ideas but I need to know how to send SQL statement from BW to MS SQL Server using ABAP program.
    Please any help will be appreciated

  • Building up dymanic SQL statement from user entered fields on a jsp

    Hi guys.
    I'm building up a sql statement from a bunch of input fields that the users can type in on a .jsp page. No real problem there, but I get a problem when they type in words with ' character in it Eg: Don't, I'll etc.
    This confuses the java code totally and usually results in a spectacular crash of the system.
    Any ideas/thought/wild speculations would be most appreciated.
    Regards
    Elmar Matthee
    University of Stellenbosch
    South Africa

    Even in pure read-only databases SQL injection can be a problem, as the user might be able to read data he should not be able to see.
    You can also create dynamically created sql statements using PreparedStatements, that's not a problem, I'm doing it pretty often myself.
    List<Object> arguments = new ArrayList<Object>();
    StringBuilder sql = new StringBuilder("SELECT foo FROM bar WHERE");
    if (someCondition) {
      sql.append(" foobar = ? ");
      arguments.add(someValue);
      if (someOtherCondition) {
        sql.append(" AND barfoo = ?");
        arguments.add(someOtherValue);
    // later on use setObject() to fill in the parametersObviously you'll have to handle putting the correct ANDs and ORs there, but you probably has solved that already, as it isn't any different if you don't use a PreparedStatement.

  • Getting SQL statement from OCIStmt

    Is there a way to retrieve the SQL statement from OCIStmt structure? That is, does anyone know what this structure is? For example, if used OCIPrepareStmt, then bound all the variables to OCIStmt, can I tell from OCIStmt what the final SQL statement is? What about the statement string that was originally passed to OCIPrepareStmt()?
    Thanks!
    Igor

    Hey! Thanks for your time!
    use preparedStatements.I'm trying that
    Then use a wrapper class called
    [url=http://www.javaworld.com/javaworld/jw-01-2002/jw-0
    25-overpower.html]debuggableStatement. You willget the SQL that the driver is using.
    Is that only for Debugging or can i use that in live code?
    Thanks again,
    Ryan

  • How to alter a button's enabled state from a script?

    How do I enable a button's enabled state from a script?
    The problem is, that I can't figure out how to reference that
    button!!! Let's say I have this script:
    pbPreviewTest.enabled() = lbTest.length >= 1;
    OK... well how do I get my script to be able to access
    pvPreviewTest and lbTest?
    I got this mxml...
    <mx:Button id="pbPreviewTest" label="Preview Test"
    right="5" top="5" enabled="false"/>
    and this also:
    <mx:DataGrid id="lbTest" height="413" width="100%" y="31"
    draggableColumns="false">
    but it doesn't seem to work :(

    This is my mxml, how do I access pbPreviewTest from the
    application script?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Panel layout="absolute" top="0" bottom="0" left="0"
    right="0">
    <mx:Script>...
    </mx:Script>
    <mx:TextInput x="6" y="5" width="162"/>
    <mx:Button x="176" y="5" label="S" width="22"/>
    <mx:Button x="202" y="5" label="B" width="22"/>
    <mx:VDividedBox id="div1" x="0" y="35" height="100%"
    width="100%">
    <mx:HDividedBox width="100%" height="159">
    <mx:DataGrid id="lbPaths"
    initialize="lbPaths.dataProvider = acPaths" height="100%"
    sortableColumns="false" draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Path"
    dataField="Name"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid id="lbView" height="100%" width="176"
    sortableColumns="false" draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="View"
    dataField="col3"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:DataGrid id="lbQuestions" height="100%"
    draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="Title"
    dataField="col1"/>
    <mx:DataGridColumn headerText="Questions"
    dataField="col2"/>
    <mx:DataGridColumn headerText="Level"
    dataField="col3"/>
    <mx:DataGridColumn headerText="Apparatus"
    dataField="col3"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:HDividedBox>
    <mx:Canvas id="cn1" width="100%" height="100%">
    <mx:Text x="3" y="7" text="Questions in Test:"
    width="209"/>
    <mx:DataGrid id="lbTest" height="413" width="100%" y="31"
    draggableColumns="false">
    <mx:columns>
    <mx:DataGridColumn headerText="No." dataField="col1"/>
    <mx:DataGridColumn headerText="Title"
    dataField="col2"/>
    <mx:DataGridColumn headerText="Question"
    dataField="col3"/>
    <mx:DataGridColumn headerText="Level"
    dataField="col4"/>
    <mx:DataGridColumn headerText="Apparatus"
    dataField="col5"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:Button id="pbPreviewTest" label="Preview Test"
    right="5" top="5" enabled="false"/>
    </mx:Canvas>
    </mx:VDividedBox>
    <mx:Button x="300" y="5" label="Add"/>
    <mx:Button x="357" y="5" label="Remove"/>
    <mx:Button label="Preview Question" enabled="false"
    right="4" top="5"/>
    </mx:Panel>
    </mx:Application>

  • How to call a subroutine from sap script

    hi friends,
    Can anybody tell me How to call a subroutine from sap script .
    thanks n regards .
    Mahesh

    hi..
    Calling ABAP Subroutines: PERFORM 
    You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.
    PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.
    The system does not execute the PERFORM command within SAPscript replace modules, such as TEXT_SYMBOL_REPLACE or TEXT_INCLUDE_REPLACE. The replace modules can only replace symbol values or resolve include texts, but not interpret SAPscript control commands.
    Syntax in a form window:
    /: PERFORM <form> IN PROGRAM <prog>
    /: USING &INVAR1&
    /: USING &INVAR2&
    /: CHANGING &OUTVAR1&
    /: CHANGING &OUTVAR2&
    /: ENDPERFORM
    INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.
    OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.
    The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:
    FORM <form> TABLES IN_TAB STRUCTURE ITCSY
    OUT_TAB STRUCTURE ITCSY.
    ENDFORM.
    The values of the SAPscript symbols passed with /: USING... are now stored in the internal table IN_TAB . Note that the system passes the values as character string to the subroutine, since the field Feld VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80). See the example below on how to access the variables.
    The internal table OUT_TAB contains names and values of the CHANGING parameters in the PERFORM statement. These parameters are local text symbols, that is, character fields. See the example below on how to return the variables within the subroutine.
    From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called. Then the simple barcode contained there (‘First page’, ‘Next page’, ‘Last page’) is printed as local variable symbol.
    Definition in the SAPscript form:
    /: PERFORM GET_BARCODE IN PROGRAM QCJPERFO
    /: USING &PAGE&
    /: USING &NEXTPAGE&
    /: CHANGING &BARCODE&
    /: ENDPERFORM
    / &BARCODE&
    Coding of the calling ABAP program:
    REPORT QCJPERFO.
    FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY
    OUT_PAR STRUCTURE ITCSY.
    DATA: PAGNUM LIKE SY-TABIX, "page number
    NEXTPAGE LIKE SY-TABIX. "number of next page
    READ TABLE IN_PAR WITH KEY ‘PAGE’.
    CHECK SY-SUBRC = 0.
    PAGNUM = IN_PAR-VALUE.
    READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.
    CHECK SY-SUBRC = 0.
    NEXTPAGE = IN_PAR-VALUE.
    READ TABLE OUT_PAR WITH KEY ‘BARCODE’.
    CHECK SY-SUBRC = 0.
    IF PAGNUM = 1.
    OUT_PAR-VALUE = ‘|’. "First page
    ELSE.
    OUT_PAR-VALUE = ‘||’. "Next page
    ENDIF.
    IF NEXTPAGE = 0.
    OUT_PAR-VALUE+2 = ‘L’. "Flag: last page
    ENDIF.
    MODIFY OUT_PAR INDEX SY-TABIX.
    ENDFORM.
    regards,
    veeresh

  • Extracting SQL statement from a Webi document's data provider using SDK.

    Hi all,
    Is it possible to extract the SQL statement from an existing Webi document's data provider using BO SDK?  I've searched through the class library but haven't found any information on this yet.  If you have done it, could you provide some guidance.  Many thanks.

    I found the following Java code that might be of some help to you. I realize you are using .NET but this might push you down the right path.
    The trick here is to use the Report Engine SDK to get the DataProvider of the DocumentInstance. Then, look at the SQLDataProvider to get your SQLContainer.
    My apologies for the poor formatting. This didn't copy and paste over to the forums very well. I've cleaned up as much as I could.
    <%@ page import="com.crystaldecisions.sdk.framework.*" %>
    <%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
    <%@ page import="com.crystaldecisions.sdk.occa.infostore.*" %>
    <%@ page import="com.businessobjects.rebean.wi.*" %>
    <%
    boolean loginSuccessful = false;
    IEnterpriseSession oEnterpriseSession = null;
    String username = "username";
    String password = "password";
    String cmsname  = "cms_name";
    String authenticationType = "secEnterprise";
    try
    //Log in. oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon( username, password, cmsname, authenticationType);
    if (oEnterpriseSession == null)
    out.print("<FONT COLOR=RED><B>Unable to login.</B></FONT>");
    else
    {  loginSuccessful = true;
    catch (SDKException sdkEx)
    { out.print("<FONT COLOR=RED><B>ERROR ENCOUNTERED</B><BR>" + sdkEx + "</FONT>");}
    if (loginSuccessful) { IInfoObject oInfoObject = null;
    String docname = "WebI document name";
    //Grab the InfoStore from the httpsession IInfoStore oInfoStore = (IInfoStore) oEnterpriseSession.getService("", "InfoStore");  //Query for the report object in the CMS.  See the Developer Reference guide for more information the query language.   String query = "SELECT TOP 1 * " +        "FROM CI_INFOOBJECTS " +        "WHERE SI_INSTANCE = 0 And SI_Kind = 'Webi' " +        "AND SI_NAME='" + docname + "'";
    IInfoObjects oInfoObjects = (IInfoObjects) oInfoStore.query(query);
    if (oInfoObjects.size() > 0)
    //Retrieve the latest instance of the report  oInfoObject = (IInfoObject) oInfoObjects.get(0);
      // Initialize the Report Engine  ReportEngines oReportEngines = (ReportEngines)
    oEnterpriseSession.getService("ReportEngines"); 
    ReportEngine oReportEngine = (ReportEngine) oReportEngines.getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);
      // Openning the document  DocumentInstance oDocumentInstance = oReportEngine.openDocument(oInfoObject.getID());   
    DataProvider oDataProvider = null; 
    SQLDataProvider oSQLDataProvider = null; 
    SQLContainer oSQLContainer_root = null; 
    SQLNode oSQLNode = null;
    SQLSelectStatement oSQLSelectStatement = null; 
    String sqlStatement = null;
      out.print("<TABLE BORDER=1>");
    for (int i=0; i<oDocumentInstance.getDataProviders().getCount(); i++)
    oDataProvider = oDocumentInstance.getDataProviders().getItem(i);
      out.print("<TR><TD COLSPAN=2 BGCOLOR=KHAKI>Data Provider Name: " + oDataProvider.getName() + "</TD></TR>");
       if (oDataProvider instanceof SQLDataProvider)
    oSQLDataProvider = (SQLDataProvider) oDataProvider;
        oSQLContainer_root = oSQLDataProvider.getSQLContainer();
        if (oSQLContainer_root != null)
    for (int j=0; j<oSQLContainer_root.getChildCount(); j++)
    oSQLNode = (SQLNode) oSQLContainer_root.getChildAt(j);
          oSQLSelectStatement = (SQLSelectStatement) oSQLNode;             
    sqlStatement = oSQLSelectStatement.getSQL();     
    out.print("<TR><TD>" + (j+1) + "</TD><TD>" + sqlStatement + "</TD></TR>");   
    else
    out.print("<TR><TD COLSPAN=2>Data Provider is not a SQLDataProvider.  SQL Statement can not be retrieved.</TD></TR>");   }  }  out.print("</TABLE>");
      oDocumentInstance.closeDocument(); }
    oEnterpriseSession.logoff();}%>

Maybe you are looking for