12c - plsql function in with clause

Hi all
I'm mucking around with 12c:
SQL> select *
  2    from v$version;
BANNER                                                                               CON_ID
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0
PL/SQL Release 12.1.0.1.0 - Production                                                    0
CORE    12.1.0.1.0      Production                                                                0
TNS for Linux: Version 12.1.0.1.0 - Production                                            0
NLSRTL Version 12.1.0.1.0 - Production                                                    0
5 rows selected.
specifically I'm trying to use the new functionality of putting a pl/sql function in the WITH clause of an SQL statement:
docco here:
http://docs.oracle.com/cd/E16655_01/server.121/e17209/statements_10002.htm#BABJFIDC
the example they give is:
WITH
FUNCTION get_domain(url VARCHAR2) RETURN VARCHAR2 IS
  pos BINARY_INTEGER;
  len BINARY_INTEGER;
BEGIN
  pos := INSTR(url, 'www.');
  len := INSTR(SUBSTR(url, pos + 4), '.') - 1;
  RETURN SUBSTR(url, pos + 4, len);
END;
SELECT DISTINCT get_domain(catalog_url)
  FROM product_information;
and so I produced my own hello world version:
with function add_number(num1 number, num2 number) return number is
begin
   return num1 + num2;
end;
select add_number(1,2) from dual;
but this just doesn't compile in SQL developer or SQLPlus.   do I need to get an updated version or something perhaps?
output is:
SQL> with function add_number(num1 number, num2 number) return number is
  2  begin
  3     return num1 + num2;
with function add_number(num1 number, num2 number) return number is
ERROR at line 1:
ORA-06553: PLS-103: Encountered the symbol "end-of-file" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like like2
like4 likec between || member submultiset
SQL> end;
SP2-0042: unknown command "end" - rest of line ignored.
SQL> select add_number(1,2) from dual;
select add_number from dual
ERROR at line 1:
ORA-00904: "ADD_NUMBER": invalid identifier
SQL> /
select add_number from dual
ERROR at line 1:
ORA-00904: "ADD_NUMBER": invalid identifier

Hi,
does that mean that you still have the problem, even after fixing this? Because I don't:
SQL*Plus: Release 12.1.0.1.0 Production on Wed Jul 3 11:32:54 2013
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
SQL> with function add_number(num1 number, num2 number) return number is
  2  begin
  3    return num1+num2;
  4  end;
  5  select add_number(1,2) from dual;
  6  /
SP2-0640: Not connected
SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area  263090176 bytes
Fixed Size                  2359904 bytes
Variable Size             205524384 bytes
Database Buffers           50331648 bytes
Redo Buffers                4874240 bytes
Database mounted.
Database opened.
SQL> with function add_number( num1 number, num2 number) return number is
  2  begin
  3    return num1+num2;
  4  end;
  5  select add_number(1,2) from dual;
  6  /
ADD_NUMBER(1,2)
              3
SQL>
Best regards,
Nikolay

Similar Messages

  • ANy other option for WITH Clause

    Do we have any other clause in SQL which has similar functionality as WITH clause?
    Message was edited by:
    DEV

    Something like that one --
    SQL>
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL>
    SQL> with tt as (select empno,ename from emp)
      2  select empno,ename from tt
      3  union
      4  select empno,null from tt
      5  where empno>2314
      6  /
         EMPNO ENAME
          7369 SMITH
          7369
          7499 ALLEN
          7499
          7521 WARD
          7521
          7566 JONES
          7566
          7654 MARTIN
          7654
          7698 BLAKE
         EMPNO ENAME
          7698
          7782 CLARK
          7782
          7788 SCOTT
          7788
          7839 KING
          7839
          7844 TURNER
          7844
          7876 ADAMS
          7876
         EMPNO ENAME
          7900 JAMES
          7900
          7902 FORD
          7902
          7934 MILLER
          7934
    28 rows selected.
    SQL>
    SQL>
    SQL> ed
    Wrote file afiedt.buf
      1  select empno,ename
      2  from (select empno,ename
      3       from emp)
      4  union
      5  select empno,null
      6  from (select empno,ename
      7        from emp)
      8* where empno>2314
    SQL> /
         EMPNO ENAME
          7369 SMITH
          7369
          7499 ALLEN
          7499
          7521 WARD
          7521
          7566 JONES
          7566
          7654 MARTIN
          7654
          7698 BLAKE
         EMPNO ENAME
          7698
          7782 CLARK
          7782
          7788 SCOTT
          7788
          7839 KING
          7839
          7844 TURNER
          7844
          7876 ADAMS
          7876
         EMPNO ENAME
          7900 JAMES
          7900
          7902 FORD
          7902
          7934 MILLER
          7934
    28 rows selected.Hope you will get some idea.
    Regards.
    Satyaki De.

  • With Clause in a function

    Hi All,
    I'm using oracle 10gr2.
    I have a sql query which starts with a "WITH Clause".... Can is use this directly in a function?
    I tried copy pasting in the new function after the BEGIN.....but it errors out saying INTO clause expected in select...when I try including INTO clause...it gives different error...
    Appreciate your sugessions
    Thanks in advance
    H

    >
    pls put an additional select ,as shown below
    >
    Why???
    CREATE OR REPLACE FUNCTION with_test (p_empNo NUMBER)
    RETURN VARCHAR2 IS
    l_eName VARCHAR2(10);
      BEGIN
        WITH l_empTab AS
         SELECT *
         FROM   emp
        SELECT ename
        INTO   l_eName
        FROM   l_empTab
        WHERE  empno = p_empNo;
        RETURN l_eName;
      END;
    SELECT with_test(7369) ename
    FROM   dual;    Cheers
    Ben

  • Unexpected problem with authorization scheme of type plsql function

    Hi,
    I have created one authorization scheme of type plsql function returning boolean. Authorization scheme is for pages only. p2_user_priviledge is a textbox on home page which extract privilege (list of pagenos) for login user from database. Home page has no authorization required. AUTHORIZATION SCHEME always returns false. I am not able to trace problem in my code. same code works fine for a textbox's default returning 'c'.
    ----- CODE FOR AUTHORIZATION SCHEME------------------------------------------------------------
    declare
    pageid varchar2(10);
    privilege varchar2(300);
    c number(3);
    begin
    pageid := ':P'||to_char(:app_page_id)||':' ; ---Pageno get stored in format  *:P2:*
    privilege := trim(:p2_user_priviledge); ++------Contain list of privilege like    :P2:P13:P67:P23:  etc+++ select instr(privilege,pageid) into c from dual;
    if c>0 then
    return true;
    else
    return false;
    end if;
    end;
    One more problem is again related to authorization scheme.
    I created one application and one authorization scheme (auth_aug) which worked finely. Then after some days i added 10 more pages to same application, But now autho_aug was always returning false for new pages. So i copied code from 'autho_aug' to new scheme 'autho_sept', & it worked for new pages. I don't understand if code is same for both scheme, why required to use two different schemes.
    Now i have added few more pages to application, and facing problem mentioned earlier.
    any solution for both the problems.....

    Hi,
    Let me clear my problem once again.
    -->Home page i.e. P2 does not use authorization, So it is displayed along with text item :p2_user_privilege.
    -->Then user click on one of the links , Now page :P70: should get displayed.
    P70 is using authorization scheme.
    -->But :p2_user_priviledge value is not accessible at authorization scheme, I dont know why.
    I could not find out where to create Application item , as suggested by you.
    & not able to find Developer menu , session at home page as suggested earlier.
    And one more question, my application at runtime display
    X en us
    at bottom
    How to make it
    USER: X Language: en us
    Like in development environment.
    Hope I have cleared my problem, waiting for reply.
    Edited by: TEJU on Nov 17, 2008 9:25 AM

  • Using WITH clause in PLSQL

    Hi all,
    I am getting ORA-00928 error [missing SELECT statement] when running below statement.
    Is 'WITH' clause allow in PLSQL?
    -- Created on 26/12/2007
    declare
      -- Local variables here
      i integer;
    begin
      -- Test statements here
       WITH x AS (
                   SELECT /*+materialize*/ *
          FROM ALL_OBJECTS
                   WHERE LAST_DDL_TIME > SYSDATE-1
        INSERT INTO tmp1
              SELECT *
        FROM x;
    end;

    wrong syntax, you need this....
    ME_XE?create table tmp1 as select * from all_objects where 1=0;
    Table created.
    Elapsed: 00:00:00.21
    ME_XE?create table x as select * from all_objects where rownum < 10;
    Table created.
    Elapsed: 00:00:00.51
    ME_XE?declare
    2 -- Local variables here
    3 i integer;
    4 begin
    5 INSERT INTO tmp1
    6 WITH x AS (
    7 SELECT /*+materialize*/ *
    8 FROM ALL_OBJECTS
    9 WHERE LAST_DDL_TIME > SYSDATE-1
    10 )
    11 SELECT *
    12 FROM x;
    13 end;
    14 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.15
    ME_XE?

  • Updating large table using the WITH CLAUSE or PLSQL

    I tried to perform an update on a table with over 15million records using the merge statement below but it's very slow.
    Can someone help me re-writting this statement using the WITH CLAUSE or a PLSQL statement that will make it run faster?
    my merge statemet:
    MERGE INTO voter dst
    USING (
    SELECT voterid,
    pollingstation || CASE
    WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation
    ORDER BY surname, firstnames
    ) <= 1000
    THEN 'A'
    WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation
    ORDER BY surname, firstnames
    ) BETWEEN 1000 AND 2000
    THEN 'B'
    ELSE 'C'
    END AS new_pollingstation
    FROM voter
    ) src
    ON (src.voterid = dst.voterid)
    WHEN MATCHED THEN UPDATE
    SET dst.new_pollingstation = src.new_pollingstation
    the with clause approach:http://www.dba-oracle.com/t_with_clause.htm
    thanks.

    Well, here's your query formatted for people to read...
    MERGE INTO voter dst
    USING (SELECT voterid,
                  pollingstation || CASE WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation ORDER BY surname, firstnames) <= 1000
                                           THEN 'A'
                                         WHEN ROW_NUMBER () OVER ( PARTITION BY pollingstation ORDER BY surname, firstnames) BETWEEN 1000 AND 2000
                                           THEN 'B'
                                         ELSE 'C'
                                    END AS new_pollingstation
           FROM voter) src
    ON (src.voterid = dst.voterid)
    WHEN MATCHED THEN
    UPDATE SET dst.new_pollingstation = src.new_pollingstation
    ;In future, please read {message:id=9360002} and post relevant details.
    What do you mean when you say it's "slow"? How have you measured this? Have you examined the explain plan?
    Take a read of the threads linked to by the FAQ post: {message:id=9360003} for details of what you need to provide to get help with performance issues.

  • How to open an URL with PLSQL FUNCTION?

    Hi friends,
    I want to know if EBS has a package to open an URL like this xxpck.openhtml("http://www.oracle.com")

    Hi Ricky,
    So your question is more about discoverer calling a PL/SQL package to create data in temp table which is then reported on?
    There are a couple of posts on this issue already, where the solution is something like having two worksheets in the workbook, the first that executes the "setup" calling a PL/SQL function through calculation or similar logic, this function includes loading the tables (and could include parameters) the second that reports on the data.
    Rod West has posted solutions around this, check out posts like:
    Re: CALL PL/SQL Procedure in Discoverer 4i
    Re: Passing Parameters to a discoverer folder using Note 282249.1
    If you are not talking about this, but viewing some output from a concurrent program in the Oracle Apps Web Forms session, then you could create a page that submits a request, waits for it, then displays the output, but this is not recommended due to the concurrent manager queueing functionality.
    With regards to calling a web page in an OAF (or forms) page, then the responsibility lies with the OAF page or Forms page not a backend PL/SQL function (although you could code PL/SQL to get the page and pass back as a clob or something, but not or efficient).
    Gareth

  • Use of WITH clause

    Hi,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 .
    I am working in a procedure where I want to manipulate the data produced by a WITH AS clause.  But it is giving "PL/SQL: ORA-00942: table or view does not exist" error. A small example to illustrate my problem is given below. Here in the example am just trying to get a replaced string by using the out put of a WITH AS clause.
    SET SERVEROUTPUT ON;
    DECLARE
    CNT INTEGER;
    LETTER CHAR(1);
    REPLACED_STRING VARCHAR2(10);
    BEGIN
    REPLACED_STRING := 'ABC';
    WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT COUNT(*) INTO CNT FROM TMP,T ;
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
    END LOOP;
    END;
    I thought of declaring a cursor which will hold the data produced by WITH clause but it did not work. Can you please let me know what are the possible options to do this.
    Thanks

    I think, I can not use the WITH inside loop as, I want to manipulate on data resulted by WITH reading row by row from it. I have a complex procedure and I wont be able to explain that scenario here and thus i came up with a similar problem through a very simple example. I will try to explain my problem thru my example here.
    The WITH in my example give an out put as :
    SUBVAL
    AB
    BC
      WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT subval FROM TMP,T;
    and then by using this in the PLSQL block mentioned above
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
      END LOOP;
    I want to have an output like:
    XBC
    XXC
    Please note that nature of my original problem is that I want to manipulate the data given by WITH clause in the same procedure by passing it to other functions/procs to get the desired result. So please advice me following this approach only which would be helpful.
    Thanks

  • How can I call a plsql function from an attribute?

    I have an attribute defined in an element. I want execute a PLSQL function from the attribute, and display the returne value with an HTML template.
    I've defined the attribute's type like PLSQL, and I've put the called of the function in the value of the attribute, but it doesn't work. The only value I obtain is an URL (I think that is the URL of the function or someting like this).
    How can I call to my function from the attribute and display the returnes value in the page?
    Thanks.

    Thanks, but it doesn't work. I have an attribute called ID_BOL and I want to associate a sequence to that attribute. I've created a function, with the sequence. This function return de value of the sequence. I want taht the attribute takes the value of the sequenece dinamically.
    I've tried it, creating the type attribute like PLSQL, and calling the function from the attribute, but it doesn't work.
    How can I return the sequence value to my attribute?
    Thanks.

  • Using WITH clause in Pro*Cobol

    Hi!
    I am trying to improve the performance of a query by introducing WITH clause.
    The query is in Pro*Cobol Release 9.2.0.6.0 - Production.
    I got compilation error
    WITH DPTCOST AS (
    ...............1
    PCB-S-00400, Encountered the symbol "DPTCOST" when expecting one of the following:
    END-EXEC
    ....continued
    So I wonder if we could use that clause at all with Pro*Cobol
    Here is the excerp of the code
    EXEC SQL
    DECLARE INPUT_ACTUAL CURSOR FOR
    WITH DPTCOST AS (
    SELECT /*+ rule */
    A.CODE_COMBINATION_ID,
    A.SEGMENT1, A.SEGMENT2, A.SEGMENT3,
    A.SEGMENT6,
    D.COSTING, D.PROCESS,
    D.MTL_CODE, D.FACTOR
    FROM
    GL_CODE_COMBINATION A,
    ALCGL_DEPARTMENT_COSTINGS D
    WHERE
    A.TEMPLATE_ID IS NULL
    AND A.SUMMARY_FLAG <> 'Y'
    AND A.SEGMENT1 = D.PLANT_NUMBER
    AND A.SEGMENT3 <> '6999001'
    AND A.SEGMENT3 <> '6999002'
    AND SUBSTR(A.SEGMENT2,4,3) = D.DEPARTMENT
    AND D.ACTUAL_FLAG = 'A'
    ) ... continued

    Materialized views are basically stored query results. They offer advanced functionality like query rewrite, refresh on commit, and more;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm
    Unlike a view, they actually store the results of the query - not just the query;
    SQL> create table t (cid number primary key)
    Table created.
    SQL> insert into t select object_id from dba_objects where object_id is not null
    12791 rows created.
    SQL> create materialized view mv
       as select * from t
    Snapshot created.
    SQL> select object_name, object_type from user_objects where object_name ='MV'
    OBJECT_NAME                    OBJECT_TYPE       
    MV                             TABLE             
    MV                             MATERIALIZED VIEW 
    2 rows selected.
    SQL> select segment_name, bytes from user_segments where segment_name in ('T', 'MV')
    SEGMENT_NAME                        BYTES
    T                                  196608
    MV                                 196608
    2 rows selected.Temporary tables are simply tables that are created then dropped. GLOBAL TEMPORARY TABLES have the advantage (or disadvantage) of only existing until commit or the end of the session. They results are visible to the user that inserted the data - but only temporarily;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#sthref7483

  • WITH CLAUSE in SPARQL - Running SPARQL query using JENA

    Hi,
    Can anybody help me how to use WITH Clause in SPARQL. Below is my Query. I am using Jena 2.6.3 to Run my Query.
    "PREFIX assc: <http://www./.../> " +
    "WITH " +
         "( " +
                        " select ?associate" +
                        " where {?associate assc:belongsTo <http://www./../Relationship>} " +
                        " AS :associateList" +
         " )" +
                   " select ?client ?associate " +
                   " where { ?client assc:Sees ?associate . ?associate assc:belongsTo <http://www./../Relationship> ." +
                   " :associateList(?associate) }" ;
    Thanks and Regards,
    Manish Hardasmalani

    Hi Zhe,
    Actually i am looking for example say,
    I have a select query where i get id , name and mark this output as a relationshipName
    And then use this relationshipName as a function in second select query.
    Example:
    WITH
    SELECT ... WHERE {...} AS relationName
    SELECT ... FROM <graph> where {... :relationName(...) [FILTER(...)]}
    In the above pseudo code relationName is populated in first select and used in second select. I am searching something similar to this.

  • Can't have aggregate function in WHERE clause clause

    Dear all,
    I've created object in BO XI 3.1 Designer with following criterias:
    http://img4.imageshack.us/img4/833/20111201124314.th.jpg
    It is a simple number - 1,2,3,4,5.
    Now I need to use this object as a criteria for WHERE function in another object.
    http://img607.imageshack.us/img607/1543/20111201124717.th.jpg
    I receive an error "Can't have aggregate function in WHERE clause <clause>"
    How can I overcome this?
    P.S. I'm sorry in advance if such topic already exist - I didn't found one.
    Edited by: Ashot Antonyan on Dec 1, 2011 9:50 AM
    Edited by: Ashot Antonyan on Dec 1, 2011 9:51 AM

    Hi,
    You will have to use Sub query to achieve this. Give more details on what is available and what you need then i could help you out with the complete solution.
    Thanks,
    Ravichandra K

  • Help:alternate for calling function in where clause

    Hi ,
    In below query i'm calling function in where clause to avoid COMPLETE status records,due to this query taking 700 secs to return result.If i'm remove below function condition it's returning results with in 5 secs.Can you some one advice to any alternate idea for this?
    WHERE mark_status != 'COMPLETE'
    SELECT assessment_school,
      subject,
      subject_option,
      lvl,
      component,mark_status,
      mark_status
      NULL AS grade_status,
      NULL AS sample_status,
      :v_year,
      :v_month,
      :v_formated_date,
      :v_type,
      cand_lang
    FROM
      (SELECT assessment_school,
        subject,
        subject_option,
        lvl,
        programme,
        component,
        paper_code,
        cand_lang,
        mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) AS mark_status
      FROM
        (SELECT DISTINCT ccr.assessment_school,
          ccr.subject,
          ccr.subject_option,
          ccr.lvl,
          ccr.programme,
          ccr.language AS cand_lang,
          ccr.paper_code,
          ccr.component
        FROM candidate_component_reg ccr
        WHERE ccr.split_session_year = :v_year
        AND ccr.split_session_month  = :v_month
        AND EXISTS
          (SELECT 1
          FROM IBIS.subject_component sc
          WHERE sc.year          = ccr.split_session_year
          AND sc.month           = ccr.split_session_month
          AND sc.paper_code      = ccr.paper_code
          AND sc.assessment_type = 'INTERNAL'
          AND sc.subject_option NOT LIKE '%self taught%'
          AND sc.component NOT IN ('PERFORMANCE  PRODUCTION','PRESENTATION WORK','REFLECTIVE PROJECT','SPECIAL SYLLABUS INT. ASSESSMENT')
        AND NVL(ccr.withdrawn,'N') = 'N'
        AND ccr.mark_status       != 'COMPLETE'
        AND EXISTS
          (SELECT 1
          FROM school s
          WHERE s.school_code   = ccr.assessment_school
          AND s.training_school = 'N'
    WHERE mark_status != 'COMPLETE';

    One thing you can test quickly is to put the function call in it's own select ...from dual.
    This might make a difference.
    However, only you can check this, I don't have your tables or data.
    So, what happens if you use:
        paper_code,
        cand_lang,
      (select mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) from dual ) AS mark_status
      FROM
        (SELECT DISTINCT ccr.assessment_school,  --<< is the DISTINCT really needed?
          ccr.subject,
          ccr.subject_option,
    ...Also, try to find out the purpose of that above DISTINCT, is it really needed or is there some join missing?

  • Using round off function in where clause

    Hi All,
    I'm trying to use round off function in where clause, I seek help in completing this script.
    WITH CR_Details AS
    (Select
    request_id,
    parent_request_id,
    fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
    round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
    round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
    fu.User_Name Requestor,
    fcr.argument_text parameters,
    to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
    to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
    to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
    fcr.completion_text
    From
    apps.fnd_concurrent_requests fcr,
    apps.fnd_concurrent_programs fcp,
    apps.fnd_concurrent_programs_tl fcpt,
    apps.fnd_user fu
    Where 1=1
    and fcr.concurrent_program_id = fcp.concurrent_program_id
    and fcp.concurrent_program_id = fcpt.concurrent_program_id
    and fcr.program_application_id = fcp.application_id
    and fcp.application_id = fcpt.application_id
    and fcr.requested_by = fu.user_id
    and fcpt.language = 'US'
    and fcr.actual_start_date like sysdate )
         select crd.*
         from CR_Details crd
         where Run_time <> '0'
         AND wait_time <> '0'
    GROUP BY
    crd.request_id,
    crd.parent_request_id,
    crd.fcpt.user_concurrent_program_name,
    crd.requested_start_date,
    crd.User_Name,
    crd.argument_text,
    crd.actual_completion_date,
    crd.actual_start_date,
    crd.phase_code,
    crd.status_code,
    crd.resubmit_interval,
    crd.completion_text,
    crd.resubmit_interval,
    crd.resubmit_interval_unit_code,
    crd.description
    Not sure about the GROUPBY function referencing the "crd." .

    Hi,
    The best thing for you to do is start over. Start as small as possible, then take baby steps.
    Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
    SELECT    *
    FROM       apps.fnd_concurrent_requests     fcr
    WHERE       fcr.actual_start_date          >= TRUNC (SYSDATE)
    AND       fcr.actual_start_dt          <  TRUNC (SYSDATE) + 1
    ;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
    Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
    If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
    When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
    When you post any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
    If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
    I know this is a lot of work.  I'm sorry.  If there was an easier way, I wouldn't ask you to do all this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Case function in where clause

    i insert the below rows in a table cash_book.
    PRJ_CODE PRJ_NAME
    1203 SHIFA
    1203 SHIFA
    1203 SHIFA
    1202 FATIMA
    1202 FATIMA
    1203 SHIFA
    if i select 1202 code then return 1202 code rows, if i select 1203 then returns 1203 code rows, if i select other than both values then returns all rows. how can i define in one query with use (case or decode function) in where clause ??

    perhaps something like this:
    create table test
    as
    select 1200 + rownum prj_code
      from dual
    connect by level <= 10;
    select * from test;
      PRJ_CODE
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    var v_PRJ_CODE number
    exec :v_PRJ_CODE := 1200;
    select *
      from test
    where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
      PRJ_CODE
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    exec :v_PRJ_CODE := 1203;
    select *
      from test
    where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
      PRJ_CODE
          1203Regards
    Martin

Maybe you are looking for