Sql command example in oracle 9

Hi,
I want to use oracle 9
select * from tab .
And use the output to issue "desc XXX " for every row of output in select statement...
How can I do it automatically ???
Any example ???

You cannot issue sql commands in plsql. Try this way:
SQL> ed
Wrote file afiedt.buf
  1  declare
  2  cursor c1 is select * from all_tab_Cols where table_name = 'ALL_OBJECTS';
  3  BEGIN
  4  FOR I IN C1 LOOP
  5  DBMS_OUTPUT.PUT_LINE(I.table_name||' : '||I.column_name||' '||I.data_type||'('||I.data_length||
  6  END LOOP;
  7* END;
SQL> set serveroutput on
SQL> /
ALL_OBJECTS : OWNER VARCHAR2(30)
ALL_OBJECTS : OBJECT_NAME VARCHAR2(30)
ALL_OBJECTS : SUBOBJECT_NAME VARCHAR2(30)
ALL_OBJECTS : OBJECT_ID NUMBER(22)
ALL_OBJECTS : DATA_OBJECT_ID NUMBER(22)
ALL_OBJECTS : OBJECT_TYPE VARCHAR2(18)
ALL_OBJECTS : CREATED DATE(7)
ALL_OBJECTS : LAST_DDL_TIME DATE(7)
ALL_OBJECTS : TIMESTAMP VARCHAR2(19)
ALL_OBJECTS : STATUS VARCHAR2(7)
ALL_OBJECTS : TEMPORARY VARCHAR2(1)
ALL_OBJECTS : GENERATED VARCHAR2(1)
ALL_OBJECTS : SECONDARY VARCHAR2(1)
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • UTL_HTTP, different error codes: APEX SQL Commands vs. Oracle SQL Developer

    Hi, omniscient all!
    I have a code sample where I try to request some URL from an inactive server:
    declare
      l_text varchar2(32000);
    begin
      l_text := utl_http.request('http://inactive.url:7777');
    exception
      when others then
        declare
          l_errcode number := utl_http.get_detailed_sqlcode;
        begin
          dbms_output.put_line(l_errcode);
          dbms_output.put_line(sqlerrm(l_errcode));
        end;
    end;
    /When I run it in Oracle SQL Developer it shows:
    anonymous block completed
    -12541
    ORA-12541: TNS:no listenerWhen I run it in the APEX 4.0 SQL Commands window it shows:
    -29263
    ORA-29263: HTTP protocol error
    Statement processed.The question is: why?
    In real world, I need to make a HTTP POST request (no problem) and catch some exceptions. But instead of the usual ORA-12541 error APEX throws an ORA-29261 one.

    Any thoughts?

  • Executing PL/SQL Commands.. Oracle API newbie

    Hi,
    I am using Oracle 10G and am calling stored procedures from my code written in C#.
    Currently I am getting the following error when the stored procedure is called:
    ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'SP_COURSE_GET' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
    .. from a recent thread someone was able to point me in the right direction and suggest that the error was in the way I was calling the stored procedure
    Now that I have resolved the previous issue, I need to be able to add the additional two lines (lines 1 & 3) to my code so that the table is returned after executing the stored procedure
    var vrct refcursor // line 1
    exec sp_course_get(501,:vrct)
    print vrct // line 3
    My code currently looks like
    cmd.Connection = conn;
                        cmd.CommandText = sStoredProc;
                        cmd.CommandType = CommandType.StoredProcedure;
                        // add the parameters
                        int iNumParams = 0;
                        if (null!= arParams)
                             iNumParams = arParams.Length / 2; // divide by 2 b/c length is total # of items, not the # of rows
                             for (int i=0; i<iNumParams; i++)
                                       cmd.Parameters.Add(new OracleParameter(arParams[i,0].ToString(), arParams[i,1]));
                        // add the output param
                        OracleParameter output = null;
                        if (OracleType.Int32 == oType)
                             output = cmd.Parameters.Add(new OracleParameter(sOutputName, oType));
                        else
                             output = cmd.Parameters.Add(new OracleParameter(sOutputName, oType, size));
                        output.Direction = ParameterDirection.Output;
                        cmd.ExecuteNonQuery();
    Can an expert advise the best way for me to send the declaration of the cursor variable and the print command for the cursor to the database. At the moment I am just calling the stored procedure. Thank you in advance for your help
    Cheers

    > Does that look right or is there any easier way to pass the 3 lines thru to
    the database
    ie 1 var vrct refcursor
    2 exec sp_course_get(501,:vrct)
    3 print vrct
    The VRCT output variable needs to be a client cursor in the client language you're using. Simply put - when you define a variable in C/C++/C# and pass that to Oracle via a PL/SQL call, that variable has to match the data type that PL/SQL expects. And vice verse.
    Line 1 above:
    var vrct refcursor]
    ..is exactly that. The client "language" is SQL*Plus. A client variable is defined in the language. It is a client cursor (aka reference cursor). The output from PL/SQL (a reference cursor) can now be stored in the client variable. This client variable can now be used by the client to fetch rows from the cursor and display them - which is what the above SQL*Plus PRINT command does.
    Okay, so in .NET (which I assume you're using) you need to use the correct variables/parameters to set your local client variable equal to the output from PL/SQL ref cursor.
    [url http://download-east.oracle.com/docs/cd/B19306_01/win.102/b14307/featRefCursor.htm]Oracle® Data Provider for .NET Developer's Guide lists the following example:
    The following example demonstrate passing a REF CURSOR:
    connect scott/tiger@oracle
    create table test (col1 number);
    insert into test(col1) values (1);
    commit;
    create or replace package testPkg as type empCur is REF Cursor;
    end testPkg;
    create or replace procedure testSP(param1 IN testPkg.empCur, param2 OUT NUMBER)
    as
    begin
    FETCH param1 into param2;
    end;
    // C#
    using System;
    using Oracle.DataAccess.Client;
    using System.Data;
    class InRefCursorParameterSample
      static void Main()
        OracleConnection conn = new OracleConnection
          ("User Id=scott; Password=tiger; Data Source=oracle");
        conn.Open(); // Open the connection to the database
        // Command text for getting the REF Cursor as OUT parameter
        String cmdTxt1 = "begin open :1 for select col1 from test; end;";
        // Command text to pass the REF Cursor as IN parameter
        String cmdTxt2 = "begin testSP (:1, :2); end;";
        // Create the command object for executing cmdTxt1 and cmdTxt2
        OracleCommand cmd = new OracleCommand(cmdTxt1, conn);
        // Bind the Ref cursor to the PL/SQL stored procedure
        OracleParameter outRefPrm = cmd.Parameters.Add("outRefPrm",
          OracleDbType.RefCursor, DBNull.Value, ParameterDirection.Output);
        cmd.ExecuteNonQuery(); // Execute the anonymous PL/SQL block
        // Reset the command object to execute another anonymous PL/SQL block
        cmd.Parameters.Clear();
        cmd.CommandText = cmdTxt2;
        // REF Cursor obtained from previous execution is passed to this
        // procedure as IN parameter
        OracleParameter inRefPrm = cmd.Parameters.Add("inRefPrm",
          OracleDbType.RefCursor, outRefPrm.Value, ParameterDirection.Input);
        // Bind another Number parameter to get the REF Cursor column value
        OracleParameter outNumPrm = cmd.Parameters.Add("outNumPrm",
          OracleDbType.Int32, DBNull.Value, ParameterDirection.Output);
        cmd.ExecuteNonQuery(); //Execute the stored procedure
        // Display the out parameter value
        Console.WriteLine("out parameter is: " + outNumPrm.Value.ToString());
    }[url http://msdn2.microsoft.com/en-us/library/system.data.oracleclient.oracledatareader(vs.80).aspx]Microsoft Visual Studio 2005/.NET Framework 2.0 also shows some examples.
    Which kinds of beg the question why did you not refer to the appropriate OracleDataReader documentation up front? It would seem that these manuals cover interaction with Oracle pretty well, and includes sample code.

  • Executing multi-line sql commands via ADO/Oracle drivers

    Hi,
    I'm trying to do multiple inserts via my ADOConnection object with the following as my SQL parameter.
    "insert into TMP_PORTFOLIO values ('3011');"
    i.e. (from VB):
    Call adoConnnection.Execute(strSQL)
    This works fine but I want to execute more than one insert at a time e.g.
    "insert into TMP_PORTFOLIO values ('3021');
    insert into TMP_PORTFOLIO values ('3478');"
    ,where there is a crlf between the statements, I get the following error
    "[Oracle][ODBC][Ora]ORA-00911: invalid character".
    So I try it wihout the crlfs and just the semi-colons and it still doesn't work. Is it possible to do this? It is fine on Sybase. I guess the Oracle provider is stripping out the crlfs. I don't want to have to loop round an array calling multiple ADO executes.
    Here's my provider details Provider=MSDASQL.1;DRIVER=Oracle in OraHome92;
    Driver version is 9.02.00.00
    Hope someone can help
    Thanks
    Paul

    In Oracle, you would probably have to turn this into a PL/SQL block and execute that, i.e.
    BEGIN
      INSERT ...
      INSERT ...
    END;My ADO is rather rusty, but I'm reasonably confident that there are ways to do array binds in ADO that would eliminate the excess round-trips. If you are using string literals in your SQL as it appears rather than using bind variables, that is going to have a very negative impact on performance in Oracle. I would strongly suggest modifying your code to use bind variables, particularly if you have more than a couple rows to insert.
    Justin

  • SQL Command code for multiple value string parameter

    Hi,
    I'm using crystal 2008 and there is a check box for multiple value  SQL Command  I need some help in writing the SQL Command code  for oracle (or sql server) for a multiple value STRING  parameter.
    Thanks in advance,
    Marilyn

    I could be wrong here, but I do not believe you can pass a multiple valued parameter to an SQL Command data source.  How I have gotten around this in the past is to put the "real" report into a subreport.  In the main report, create a formula field (basic syntax):
    formula = join({?parameter}, "|")
    Then, use this to pass the selected values to the subreport's parameter (call it {?sr-parm}).  The SQL Command in the subreport can then use that (MS SQL):
    select *
    from table
    where charindex(table.field, '{?sr-parm}') > 0
    HTH,
    Carl

  • Execute an sql command other than an select statement

    hello,
    is it possible to execute an sql-command other than a
    select statement in a report ?
    something like execute ... ?
    i want ro execute a statement BEFORE the select ...
    or is the one and only possible statement in a report
    a "select ?"
    greetings
    Thorsten Lorenz

    Hi ,
    You can always use the Report triggers to execute any other SQL commands . If you need to execute them before the SELECT statement of you Data Model query , then You can use the Parameter Form triggers / before Report Trigger. Be sure to put in a commit statement as well, if the result of the Select statement you intend to do depends on these SQL commands.
    Thanks
    Oracle Reports Team.

  • How to view previously executed sql commands?

    Hi experts,
    I want to view the sql commands executed in Oracle 8i before 3 or 4 hrs.That is i am asking to view the command history.Can any one help me in this weird situation?Anytype of suggestion were welcme..
    Thanx in Advance,
    Senthil

    You can use LOG MINER utility to check the commands that has been executed.
    Use v$log_history view to check the exact log sequence number of the redo log file, and there by you can use that log file with log miner.
    Using this method you can't see the DQL commands that has been executed against the database, apart from this all other commands can be seen..
    cheers
    kumareshan

  • Howto: multiple sql-commands in oracle-xe

    Hi,
    just installed the oracle-xe. Now I want to create tables, indexes etc within the sql-command tool.
    For example:
    CREATE TABLE ZUSTAENDIGKEIT (
         INSTITUTION_ID      VARCHAR2(30) NOT NULL,
         FUNKTION_ID      NUMBER(4) NOT NULL,
         LIEGENSCHAFT_ID      VARCHAR2(30) NOT NULL);
    CREATE UNIQUE INDEX UX_ZUSTAENDIGKEIT
         ON ZUSTAENDIGKEIT (LIEGENSCHAFT_ID,FUNKTION_ID)
    Executing this as one command I receive an error ora-00911.
    Executing this in two parts it works?
    Thanks for any help.
    grassu

    Here is just a sample that should work as a script in the web interface:
    -- BVM
    -- Benoetigte Sequence numbers
    -- Globale Sequence
    DROP SEQUENCE bvm_seq;
    CREATE SEQUENCE bvm_seq
           MINVALUE         1
           MAXVALUE         999999999
           INCREMENT BY     1
           START WITH       1
           CACHE            20
           NOORDER
           NOCYCLE
    -- Log Sequence
    CREATE SEQUENCE BVM_LOG_SEQ 
           MINVALUE         1
           MAXVALUE         999999999
           INCREMENT BY     1
           START WITH       1
           CACHE            20
           NOORDER
           NOCYCLE
    ;Note: no "/" (you need these only after trigger, procedures, etc.)
    You need to execute this in the script section, not in the command section of the web interface.
    C.

  • Oracle sql commands use

    my question is will it possible to use oracle sql commands in toad and genterate the reprot like I have below.
    my second question is can I embede this oralc sql command in my apps. to have the out put I have below. I tried and got an error message. I am wondering if this is possible
    SQL> -- Multiple COMPUTEs are also allowable.
    SQL>
    SQL> SET echo off
    SQL> BREAK ON city skip1 ON start_date
    SQL> COMPUTE sum max min of salary ON city
    SQL> COMPUTE sum of salary ON start_date
    SQL> SET verify off
    SQL> SELECT id, first_name, salary, city FROM employee ORDER BY city
      2  /
    ID   FIRST_NAME     SALARY CITY
    07   David         7897.78 New York
    06   Linda         4322.78
                       4322.78 minimum
                       7897.78 maximum
                      12220.56 sum
    01   Jason         1234.56 Toronto
                       1234.56 minimum
                       1234.56 maximum
                       1234.56 sum
    05   Robert        2334.78 Vancouver
    08   James         1232.78
    03   James         6544.78
    02   Alison        6661.78
    04   Celia         2344.78
                       1232.78 minimum
                       6661.78 maximum
                       19118.9 sum

    Hi,
    All of theose SQL*Plus features can be duplicated in Oracle SQL. For example, "GROUP BY ... ROLLUP" can give you an minimum, maximum and total for each city.
    You can create a view that looks exactly like the SQL*Plus output (for example, the city column with values like 'New York', NULL, '**********', and 'minimum'), if you really need to. CASE is very useful for things like this, as are some analytic functions. (E.g., ROW_NUMBER can help in telling which is the first row for each city.)
    To make such a view, you may find it convenient to do a UNION of two queries:
    (1) One that produces one row per employee
    (2) One that produces a fixed number of rows (four, to get the results you posted) per city

  • How execute pl/sql command from Oracle ADF Business Components

    can't find examples for how execute pl/sql command from Oracle ADF Business Components and how call pl/sql package procedure from ADF Business Components.
    insert,update,delete rows in view object instance cache is good but if i must do some complex operations while insert,update,delete rows..it's more better for me to call
    pl/sql procedure from oracle db.Am i wrong ????

    Roman,
    this should be similar to how it worked in JDeveloper 9.0.3. hava a look at <JDev903 Home>\BC4J\samples\StoredProc for a code example.
    Frank

  • How to find GUI SQL*Plus command tool in Oracle 8i (version 8.1.7)

    I had installed Oracel 8i Enterprise Edition (version 8.1.7) on my server machine (Windows NT 4.0), I'd like to use Oracle Navigator (GUI SQL*PLUS command tool), but I can not find it from the menu. I know Oracle Navigator is available in Oracle 7. Can anyone tell me where and how to use GUI SQL*PLUS command tool in Oracle 8i Enterprise Edition (version 8.1.7) ?
    thanks a lot.
    David Zhu

    Hi
    Oracle Navigator is part of Personal Oracle7 and Oracle Lite. I don't know is it available in 8i Personal Edition but I am sure that it is not part of Standard and Enterprise Edition.
    Regards
    null

  • How to get the correct sql command in oracle?

    Hi sir,
    i am using this query in sql that is :
    SELECT C.*,ISNULL(P.Comp_Name,'') + ' (' + ISNULL(P.Comp_ID,'') + ')' Parent FROM Comp_Master C LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID Where C.Comp_ID='004'
    so i am getting in parent column value like this: "PARIS GROUP (001)"
    but the same command i converted in sql developer that is:
    SELECT C.* ,NVL(P.Comp_Name, ' ') || ' (' || NVL(P.Comp_ID, ' ') || ')' as Parent FROM Comp_Master C LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID WHERE C.Comp_ID ='004'
    but not getting in parent column value its coming only ( )
    help me.
    thanks

    Welcome to Oracle.
    It has manuals.
    http://tahiti.oracle.com/
    Choose your version, which you continue to keep a mystery
    E.g.
    http://www.oracle.com/pls/db112/homepage
    Including Oracle SQL syntax
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/toc.htm
    Which you will find useful since Oracle does not run Microsoft SQL as you continue to find over and over again.
    And there is a 2 day getting started as a developer guide, which you appear to desperately need,
    http://docs.oracle.com/cd/E11882_01/appdev.112/e10766/toc.htm
    If you have any specific questions about anything you read in there, come back in a couple of days after you have finished reading them.

  • How do I write this SQL command in Oracle

    Hi all
    I wriote this SQ L statement in Ms SQL Server. How do I write this sql command in Oracle?
    ALTER VIEW dbo.ConsumptionAS SELECT TOP 100 PERCENT ID,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200711' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Nov2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200712' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Dec2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200801' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jan2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200802' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Feb2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200803' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Mar2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200804' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Apr2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200805' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS May2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200806' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jun2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200807' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jul2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200808' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS Aug2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200809' AND NbrDaysUsed != 0 THEN (QtyUsed NbrDaysUsed) * 748.05 ELSE 0 END)) AS Sep2008
    FROM dbo.MasterConsumption WHERE YEAR_MONTH >= '200710' AND YEAR_MONTH <= '200809' GROUP BY ID ORDER BY ID
    I am very interested in this part:
    SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007
    thanks
    Edited by: user631364 on Oct 27, 2008 8:25 AM
    Edited by: user631364 on Oct 27, 2008 8:26 AM
    Edited by: user631364 on Oct 27, 2008 8:27 AM

    Thank you!!
    Now let me aslk the second part of my question.
    This sql command:
    ALTER VIEW dbo.ConsumptionAS SELECT TOP 100 PERCENT ID,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200711' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Nov2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200712' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Dec2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200801' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jan2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200802' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Feb2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200803' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Mar2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200804' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Apr2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200805' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS May2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200806' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jun2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200807' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jul2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200808' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS Aug2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200809' AND NbrDaysUsed != 0 THEN (QtyUsed NbrDaysUsed) * 748.05 ELSE 0 END)) AS Sep2008
    FROM dbo.MasterConsumption WHERE YEAR_MONTH >= '200710' AND YEAR_MONTH <= '200809' GROUP BY ID ORDER BY ID
    was created with this query in SQL Server and then I saved it in a store procedure, that I scheduled to run montlhy
    SET ANSI_NULLS ON
    DECLARE @SQLString NVARCHAR(4000)
    /* Build the SQL string once.*/
    SET @SQLString = 'ALTER VIEW dbo.Consumption AS SELECT TOP 100 PERCENT ID, CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = ' +
    "'" + dbo.CONLastMonth_fn(getdate(), month(getdate()) - 12) +
    "'" +
    ' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS ' +
    dbo.CONMonthInEnglish(getdate(), month(getdate()) - 12) +
    … (GOES FROM current month -12 to current month -1)
    , CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = ' +
    "'" + dbo.CONLastMonth_fn(getdate(), month(getdate()) - 1) +"'" +
    ' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS ' +
    dbo.CONMonthInEnglish(getdate(), month(getdate()) - 1) +
    ' FROM dbo.MasterConsumption WHERE YEAR_MONTH >= ' +
    "'" + dbo.CONLastMonth_fn (getdate(), month(getdate())-12 ) +"'" +
    ' AND YEAR_MONTH <= ' +
    "'" + dbo.CONLastMonth_fn (getdate(), month(getdate())-1 ) +"'" +
    ' GROUP BY ID ORDER BY ID '
    EXEC sp_executesql @SQLString
    Is that something that can be done in Oracle in the same way?
    Do you use another approach?
    please advice
    Edited by: user631364 on Oct 27, 2008 10:19 AM
    Edited by: user631364 on Oct 27, 2008 10:21 AM
    Edited by: user631364 on Oct 27, 2008 10:21 AM
    Edited by: user631364 on Oct 27, 2008 10:22 AM
    Edited by: user631364 on Oct 27, 2008 10:23 AM
    Edited by: user631364 on Oct 27, 2008 10:23 AM
    Edited by: user631364 on Oct 27, 2008 10:24 AM

  • Oracle Express 10g - a way to terminate in SQL Command Line interface

    I've downloaded Oracle Express 10g and use the SQL Command Line interface to execute SQL*Plus -- a really simple window / interface without hardly any smarts. In other Oracle installations' SQL*Plus, I'm used to be able to do a Ctrl C to terminate the current SQL that's being executed and the session is still active and I can keep using it. But with the Oracle Express 10g SQL Command Line interface, when I do a Ctrl C the currrent SQL is terminated -- but so is the whole dang session and the window goes away too. There must be a way in the Oracle Express 10g SQL Command Line interface to simply terminate th current SQL results without losing the whole dang session!!! This is so incredibly frustrating it's not even funny. HELP!!!!

    I think your answer is in this thread:
    Re: stopping a query
    Regards, Marc

  • Oracle SQL command

    I have read this statement on these forums many times:
    Just keep 1 thin in mind... CR will send any SQL statement, exactly as it is written, to the database. That means that if you can execute it from TOAD or the Oracle SQL Developer, you should be able to do it from CR as well.
    I have an SQL command that I have simplified so that it contains just a snippet from the original that populates a temporary table.
    Since there is a DECLARE there must be a BEGIN and END.  The required SELECT * to get the fields to show up in the field explorer will not work before the END statement.  If I put it after the END statement I get an ORA-06550 error.  "FOUND SELECT WHEN EXPECTING..." .   I got on the ORACLE website and they told me to put / before and after the SELECT.  When I try this in CR SQL command, I get ORA-06550 "ENCOUNTERED /".
    I have tried this in SQL Plus and don't get any errors.
    DECLARE Pallet  VARCHAR2(8);
            Box     VARCHAR2(8);
            ItemBox VARCHAR2(8);
            CODE    VARCHAR2(6);
    BEGIN   
        CODE := '20151';
        CODE := CONCAT(CODE, '%');
        DELETE LoadItems_temp;
       COMMIT;
    END;
    SELECT * FROM LOADITEMS_TEMP;

    Just keep 1 thin in mind... CR will send any SQL statement, exactly as it is written, to the database. That means that if you can execute it from TOAD or the Oracle SQL Developer, you should be able to do it from CR as well.
    Sounds like that may have come from me...
    99% of my reporting is done using SQL Server as a back end so I can't say if the rules change when using Oracle any of the Oracle drivers.
    That said, I can create and drop temp tables as well as declare and set variables without any issues in SQL Server... And do so regularly.
    Looking at your code... (and bear in mind that I don't know PL-SQL specific syntax...) I don't see where you are creating the temp table LoadItems_temp.
    I did a quick Google search on ORA-06550 and it appears to be syntax error. So if the code is executing in SQL-Plus without any issues but bombs in CR, my guess would be that you aren't using the right driver for your database.
    HTH,
    Jason

Maybe you are looking for

  • Browsers no longer able to read russian / cyrillic characters

    Ever since i upgrading to Snow Leopard just recently i noticed that my all browsers (safari, firefox, chrome etc) are unable to read russian / cyrillic characters. While i can type russian letters in the search bar or in pages / key notes for example

  • IOS apps continue to use CPU after iPad sleeps

    I've created several AIR -iOS apps for iPad and have noticed that after the iPad sets itself to sleep, these apps continue to use a % of CPU indefinately, (around 2%). I'm seeing this by using XCode Instruments Activity Monitor whilst the iPad is con

  • I lost my address book on my computer

    I am going on bed rest and willl be working from home... welll just now I some how lost my address book... I don't know how it happend but its gone... can I retrieve it... please help!!

  • I need to reload java

    It's not working, so I deleted it and am about to try again.  Any ideas? I had java 7 update 25, but it won't open the CTC bridge for my company. Should I try java 6, or is that not safe?

  • How can I tell if my X220 has IPS?

    Hi, everyone, I just got a new X220, and I'm trying to figure out what to look for in terms of appreciating the IPS. (I indeed ordered it for the machine). It seems bright and fairly easily viewable at an angle, but I was kinda expecting more. Anyone