How to run a single sql statement

I want to run a simple sql statement to get some data in my Controller or AM.
Is there some way, other than creating a VO with the SQL statement, to get some data from the database. My sql query will always return a single row.

Hi,
here you have an example I use to call a function in a package (note how you can pass parameters and read results):
Connection conn = this.getOADBTransaction().getJdbcConnection();
OracleCallableStatement ocs = null;
String param = null;
try {
        String stmt = "BEGIN :1 := <PkgName>.<FunctionName>(:2); end;";
        ocs = (OracleCallableStatement)conn.prepareCall(stmt);
        ocs.registerOutParameter(1, OracleTypes.CHAR);
        ocs.setString(2, <param>);
        ocs.execute();
        param = ocs.getString(1);
     } catch(SQLException se) {
         throw OAException.wrapperException(se);
     finally {
         try {
                ocs.close();
                return(param);
         } catch(Exception e) {
                throw OAException.wrapperException(e);
     }Hope this helps you
Bye
Raffy

Similar Messages

  • Running Multiple SQL in a Single Worksheet: Can I Selectively Run a Single SQL and Append Output?

    In any release of SD, if I have a single worksheet containing 10 sqls. Is it possible to place the cursor on any of the sql and run only that sql, yet, append its output to existing output window. I can then select another sql and execute it and keep appending output. In other words, do not clear existing output or start a new output tab.
    As it exists today (in any release), I can either 'run script' which does append, but it executes all the sql (non-selective). Alternately, I can 'run statement' to selectively run a single sql, but it will clear the output window (or if pinned), start a new one. None of this is what I want.
    Thank you.

    Select the query you want to run. Execute it via F5. Then highlight the next query and repeat.
    The output will append to the Script Output panel.
    There's no way to get 2 queries to share a grid, unless you were to run them as a single query a la UNION.

  • How to tune the following sql statements which has two unions in oracle 10g

    It takes a long time to run the following sql statement in 10g. Each select brings back about 4 million rows and there will be about 12 million rows. When I run each select statements seprately in sqlplus I can see the data immedaitely but when I run it as whole with two unions in the select it just takes very very long time? I want to know how to make this run faster? Can we add hints? or is it because of any table space? Any help is appreciated.
    select
    D.EMPLID
    ,D.COMPANY
    ,'CY'
    ,D.CALENDAR_YEAR
    ,D.QTRCD
    ,D.ERNCD
    ,D.MONTHCD
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,D.GRS_YTD
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,D.HRS_YTD
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FY'
    ,(case when D.MONTHCD > '06' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD) + decode(sign(3-to_number(D.QTRCD)),1,2,-2),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '07' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '07' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD) + decode(sign(7-to_number(F.MONTHCD)),1,6,-6)
    <= to_number(D.MONTHCD) + decode(sign(7-to_number(D.MONTHCD)),1,6,-6))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    union
    select
    D.EMPLID
    ,D.COMPANY
    ,'FF'
    ,(case when D.MONTHCD > '09' then D.CALENDAR_YEAR + 1 else D.CALENDAR_YEAR end)
    ,ltrim(to_char(to_number(D.QTRCD)+decode(sign(4-to_number(D.QTRCD)),1,1,-3),'9'))
    ,D.ERNCD
    ,ltrim(to_char(to_number(D.MONTHCD)+decode(sign(10-to_number(D.MONTHCD)),1,3,-9),'09'))
    ,D.MONTHCD
    ,D.GRS_MTD
    ,D.GRS_QTD
    ,(select sum(F.GRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    ,D.HRS_MTD
    ,D.HRS_QTD
    ,(select sum(F.HRS_MTD) from PS_EARNINGS_BAL F where
    F.EMPLID = D.EMPLID and
    F.COMPANY = D.COMPANY and
    F.ERNCD = D.ERNCD and
    F.SPCL_BALANCE = D.SPCL_BALANCE and
    (case when F.MONTHCD < '10' then F.CALENDAR_YEAR -1 else F.CALENDAR_YEAR end)
    = (case when D.MONTHCD < '10' then D.CALENDAR_YEAR -1 else D.CALENDAR_YEAR end)
    and to_number(F.MONTHCD)+decode(sign(4-to_number(F.MONTHCD)),1,9,-3)
    <= to_number(D.MONTHCD)+decode(sign(4-to_number(D.MONTHCD)),1,9,-3))
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'
    Edited by: user5846372 on Mar 11, 2009 8:55 AM

    Hi,
    What i observed is that your table name and where clause is same in all the thress SELECTs whereas columns having some manipulations that is not going to be unique. I guess you can easily replace UNION with UNION ALL.
    from PS_EARNINGS_BAL D
    where D.SPCL_BALANCE = 'N'Note: I am not aware of your data and business requirement. Please test the result before removing. It is just a suggetion
    Cheers,
    Avinash

  • How could I find the SQL statement who get this message ?

    ORA-01555 caused by SQL statement below (Query Duration=11191 sec, SCN: 0x0854.723b9c32)
    ... How could I find the SQL statement who got this message ?
    Thanks, Paul

    ORA-01555 means that the UNDO/ROLLBACK space is not large enough.
    This occurs because the SELECT statement is attempting to read the UNDO, but the UNDO has been released (transactions have committed or rolled back) and reused.
    The following are SOME of the reasons I have seen this to occur:
    1) Updates in a loop, with commits happening in the same loop
    - this will mark the UNDO available quickly and quickly reuse it. Then when the SELECT wants to rebuild a block, the UNDO used to rebuild the block has been reused (solution, make the UNDO bigger)
    2) A SELECT cursor used to control a loop in which updates are performed, and a 'done' flag is marked against the current cursor record, and commits are performed at the end of each loop, prior to fetching the next record
    - same problem as above, but it hits the current process. Same solution
    3) A 'month end' activity spike occurs, and all sorts of transactions create updates. There is a report that reports the activity - amusingly it needs to start at the beginning of all the work and updates periodically by doing a huge SELECT up front. This is then used to drive a loop which attempts to get information from the various transactions that have been updated and committed. After a while, the SELECT gets an ORA-01555
    - same problem as above and same solution. Get a bigger UNDO segment.
    You say this only happens once a month. That should give a hint.
    I wouldn't bother with which SELECT statement, as much as which APPLICATIONs are being run when it happens.
    One way around this - use 10g and set the guaranteed retention period. All sorts of other things will break, by no more 1555. <g>

  • How can i use one SQL statement to solve problem?

    How can i use one SQL statement to solve the question below?
    For a Table named A, there is a column named F(char type).
    Now select all the records where F like '%00' and update their F value to '%01'
    Just one SQL statement.Do not use PL/SQL block.
    How to do that?
    Thanks.

    What is the data volume for this table?
    Do you expect lots of rows to have '%00' as their value?
    Following two statements come to mind. Other experts would be able to provide better alternatives:
    If you have index on SUBSTR(f, 2):
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) || '01'
    WHERE  substr(f,
                  -2) = '00';If most of the rows have pattern '%00':
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) ||
               DECODE(SUBSTR(f,
                             -2),
                      '00',
                      '01',
                      SUBSTR(f,
                             -2));

  • Produce report NOT based on a single sql statement

    I want to produce a tabular report based on a series of sql statments. Specifically, a report of managers that wil include counts of employees that are in other tables using differing criterias.
    Name Count Count
    using using
    criteria 1 criteria 2
    Manager1 35 242
    I would expect to write an anonymous pl/sql block with a driving cursor determining the managers to report on. Within that cursor, I would execute a number of other queries to derive the count for each of the two columns.
    I have tried creating a report region based on a sql statement, but that requires a single sql statement. I also tried creating a report region based on plsql, but it required an into statement of defined items. This option looks like it can provide multiple rows, but since it selected 'INTO' named fields, it only creates a report with the last row of data.
    I must be missing something. Any suggestions are greatly appreciated!!!

    If you want a wizard to create the form and report for you then yes you need to have a table. One thing that you can do is define a view that contains the data you need and define an Instead Of trigger on that view so the automatic fetch and dml will work but you can have the data stored into the different objects. basically the view and the trigger work as a router/dispatcher for the data.
    *edit*
    I should also add that you can write a pl/sql package which does the fetch and the dml operations with the form items as input. This is the solution I would typically use for any form that was not a simple CRUD form for a table. One thing to note is for the fetch I prefer to use out parameters for the form items so it requires the developer to map the item to the param in the app so it will show up when you are searching through the app. I highly discourage hiding item references inside of packaged code.
    Good Luck!
    Tyson
    Message was edited by: TysonJouglet

  • Run a PL/SQL statement in an Oracle Alert action?

    Hello
    did anyone know is it possible to run a PL/SQL statement in an Oracle Alert action?
    I can run an SQL like “UPDATE Table SET alert_run = 'ok' where id = 10;” but if I run instead of this the following
    “Select XXKN_TEST.UPDATE_XXX_TEST('&USER_NAME') From dual;”
    I get the following error log:
    Alert: Version : 11.5.0
    Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
    ALECDC module: Check Periodic Alert
    PL/SQL procedure successfully completed.
    XXKN_TEST.UPDATE_XXX_TEST('GROSS2')
    ERROR at line 2:
    ORA-00904: "XXKN_TEST"."UPDATE_XXX_TEST": invalid identifier
    APP-ALR-04020: Oracle Alert was unable to execute "&VALUE". Check that this file exists and that its read protection is set correctly.
    Many thanks for your help,
    Alois

    Hello Suresh,
    I tried your suggestion but it doesn't work.
    The PL/SQL procedure was successfully completed but no data was modified.
    Are you sure that running a PL/SQL is possible in an alert action?
    Kind Regards,
    Alois

  • How to examine the generated SQL statement in Receiver JDBC Adapter

    I have been searching this forum how to display te generated sql statement (by the jdbc receiver adapter).
    The only suggestion is to use RWB, but I was unable to find any details about how to do so.
    Any help is appreciated

    Hi,
    To add, u can see the SQL Statements in Audit log of RWB.
    Select Message Monitoring-> Adapter Engine. choose ur entry and click on Details option button, u can see the SQL Statements in Audit Log.
    Regards,
    Sudharshan
    Message was edited by:
            Sudharshan Aravamudan

  • Can we Run a simple SQL statement from OBIEE Middle Tier node

    Hi
    i am working in OBIEE 11g environment. Database is installed on one node and Middle tier (BI services ) in other node,
    Can i use any utility to run a simple SQL statement from Middle tier ?
    Thanks
    Reddy

    Any utility means?
    We can create an ODBC connection on the BI server and run the sql.
    Mark if helps.

  • How can I write a SQL statement which checks if a table exists?

    How can I write a SQL statement which tells me whether a table exists?

    execute an sql query: select * from <tablename>
    catch the exception n check whether the erroe code
    matches the one that occurs for table doesn't exist
    that's itHow is your answer any different from the one given in the first reply?
    It isn't.
    As WorkForFood says DatabaseMetaData has a bunch of methods for getting information about tables but this is more useful when you don't know the names of any of the tables.. it sounds like you do so I would concur SELECT from table is probably the quickest way to go. If it helps the Xopen error should be either S1000 or 42S01 (I think) but I would try and see if there is a specific vendor code for table not found/not exists error and check for that.

  • How do i see the sql statements that are run ?

    i want to see (in a log file) what are the sql statements that oracle had ran.
    how do i do it ? what configurations should i do ? how ?
    please help ... thanks

    Current SQL statements are viewed in dynamic tables:
    SELECT SCHEMANAME, SQL_ADDRESS, SQL_TEXT, last_call_et
    FROM V$SESSION, V$SQLAREA
    WHERE V$SESSION.SQL_ADDRESS=V$SQLAREA.ADDRESS
    A historical log of all SQL statements is recorded in Oracle Archived Logs, and can be viewed using the Oracle Logminer approach. This process requires your database to be in ARCHIVELOG mode, and that Logminer be configured to read the archived logs.

  • How should I pass complicated sql statements to a function ?

    Hello
    Some built-in functions, such as dbms_advisor.quicktune accepts sql statements as in parameters. Those parameters are treated as varchar2, but if the sql statement is complicated and contain " ' " characters then its hard to pass those params, Sometimes they arent parsed correctly.
    How should I pass a complicated statement (with subqueries, strings and so) to a function ?
    Thanks
    Guy

    user11973359 wrote:
    Hello
    Some built-in functions, such as dbms_advisor.quicktune accepts sql statements as in parameters. Those parameters are treated as varchar2, but if the sql statement is complicated and contain " ' " characters then its hard to pass those params, Sometimes they arent parsed correctly.
    How should I pass a complicated statement (with subqueries, strings and so) to a function ?
    Thanks
    GuyWhats your db verzion. To over come the single quotes issue in string you can use q'[]' representation of string.
    select q'[Karthick's]' from dual

  • Single SQL statement that does multiple column checks

    I have multiple sql statements (see below) that do value and format checking on different columns within the same table. I am trying to condense these checks into one SQL statement, anyone know how to do this?
    select colx, coly, col1 from table1 where col1 not in ('A','B','C')
    select colx, coly, col2 from table1 where col2 not in ('X','Y','Z')
    etc
    Note that I am looking for the value of the offending column (e,g col1 or col2) as the last of the three columns outputted,
    Thanks in advance

    Perhaps;
    SQL> create table t (colx number, coly number, col1 varchar2(1),
       col2 varchar2(1), col3 varchar2(1), col4 varchar2(1))
    Table created.
    SQL> insert all
       into t values(1,1,'A','D','G','J')
       into t values(1,2,'*','D','G','J')
       into t values(1,3,'A','D','G','J')
       into t values(1,4,'A','*','G','J')
       into t values(1,5,'A','D','G','J')
       into t values(1,6,'A','D','*','J')
       into t values(1,7,'A','D','G','J')
       into t values(1,8,'_','-','/','*')
    select * from dual
    8 rows created.
    SQL> select colx, coly,
       trim(regexp_replace('Col1' || col1,'(Col1)([^A|B|C])|(Col1)([A|B|C])', '\1 ') ||
            regexp_replace('Col2' || col2,'(Col2)([^D|E|F])|(Col2)([D|E|F])', '\1 ') ||
            regexp_replace('Col3' || col3,'(Col3)([^G|H|I])|(Col3)([G|H|I])', '\1 ') ||
            regexp_replace('Col4' || col4,'(Col4)([^J|K|L])|(Col4)([J|K|L])', '\1')) offending_column,
       trim(regexp_replace(col1,'([^A|B|C])|([A|B|C])', '\1 ') ||
            regexp_replace(col2,'([^D|E|F])|([D|E|F])', '\1 ') ||
            regexp_replace(col3,'([^G|H|I])|([G|H|I])', '\1 ') ||
            regexp_replace(col4,'([^J|K|L])|([J|K|L])', '\1')) offending_value
    from t
    where regexp_replace(col1||col2||col3||col4,
          '(A|B|C)(D|E|F)(G|H|I)(J|K|L)') is not null
          COLX       COLY OFFENDING_COLUMN     OFFENDING_VALUE    
             1          2 Col1                 *                  
             1          4 Col2                 *                  
             1          6 Col3                 *                  
             1          8 Col1 Col2 Col3 Col4  _ - / *            
    4 rows selected.Message was edited by:
    MScallion
    Added offending_value
    NOTE* this query only works on single character columns and requires modification for multi character columns

  • How to set client within SQL statement without using another pl/sql stmt.

    I have a following select statement
    SELECT SUM (w.prior_forecasted_costs + w.prior_committed_costs)
    FROM xxsuf.job_cost_summary_table w,
    apps.pa_periods p,
    pa.pa_resources bz,
    pa.pa_resource_list_members cz,
    pa.pa_tasks dz
    WHERE w.project_id = z.project_id
    AND w.task_id = dz.task_id
    AND dz.task_number '98000'
    AND w.resource_list_member_id = cz.resource_list_member_id
    AND cz.resource_id = bz.resource_id
    AND NOT EXISTS (SELECT NULL
    FROM pa.pa_tasks zz
    WHERE zz.parent_task_id = dz.task_id)
    AND w.resource_list_member_id != 1000
    AND p.period_name = w.pa_period
    AND p.current_pa_period_flag = 'Y'
    Above select statement uses pa_periods view which only works when I set my client using "exec DBMS_Application_Info.set_client_info(83);" in Toad or SQL*Plus session.
    I was wondering how can I achieve it within select statement. so that I don't have to use another PL/SQL statement to set my client. Is there anyway to set client with my org id within above select statement ?
    Please advise.
    --Rakesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You can simply create a function which calls dbms_application_info and use that in your sql statement as in
    SQL> create or replace function set_client_info (i_info varchar2)
       return varchar2
    as
    begin
       dbms_application_info.set_client_info (i_info);
       return i_info;
    end set_client_info;
    Function created.
    SQL> create or replace view v_emp
    as
      select * from emp where empno = to_number(sys_context('userenv','client_info'))
    View created.
    SQL> select ename from v_emp where set_client_info(7788) is not null
    ENAME    
    SCOTT    
    1 row selected.
    SQL> select ename from v_emp where set_client_info(7900) is not null
    ENAME    
    JAMES    
    1 row selected.

  • How to run a EXECUTE IMMEDIATE statement in a Interactive Report

    Hello all!!
    I need to make a dinamic construction of a query to execute in a Interactive Report, but the Region Source only allows simple SELECT statements. There is any way to run a EXECUTE IMMEDIATE statement in a Interactive Report Region Source?
    Regards Pedro.

    Thank you Andy for your reply.
    I have been testing for a while the use of a collection in the interactive report but i am unable to load data in the interactive report.
    I created the collection successfully in the SQL Commands with the code:
    declare
    v_sql varchar2(32000);
    begin
    v_sql:='select ename, job from emp';
    APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('coleccao_emp',v_sql,'NO' );
    end;
    I tested successfully the creation of the collection with the query:
    SELECT c001, c002
    FROM APEX_collections
    WHERE collection_name = 'COLECCAO_EMP'
    My problem is: the data of the collection are returned in the SQL Commands but when i run the query statament in an interactive report, report or even a Pl/Sql region in my application the data aren't displayed, only the message (No data found).
    Can someone explain why, besides the collection is populated the interactive can not print the results.
    Regards Pedro.

Maybe you are looking for

  • Display does not work mac pro

    I tried connected 4 27" LG 1080p monitors to the mac pro (Late 2013), only two come on at a time no matter what ports i use. All the monitors have come on at least once but not all at the same time. Is there something I need to do? Also under system

  • Is there a way to access remote login and screen sharing logs?

    I have a very high suspicion that my macbook air has been accessed through remote login. Here's what happened. I closed my macbook air, letting it sleep, and left my house. After coming back I found it logged into the Guest account (which I didn't kn

  • ITunes sharing just NOT working!  Please help!

    I can't seem to get iTunes to find shared music on the network, or share my music. -I'm using iTunes version 6.0.1.3 and Windows XP with SP2 -I have tried adding the ports 3689 and 5353 to the firewall port exceptions -After researching for awhile on

  • How to erase an SSD drive

    How do I erase and SSD drive from a Macbook Air so it can be sold?

  • I POD HAS BEEN DETECTED BUT CANNOT BE IDENTIFIED PROPERLY

    my 6th generation nano shuffle when plugged in responds with the message:  "i pod has been detected but could not be identified properly" then i am prompted to reinstall itunes. have done this but the problem remains. i cannot sync from my itunes. he