Select clause with where part is needs 600 times longer to complete

Hello.
I have two select clauses one with where, which needs 120 seconds to complete and one without where, which completes in 0,3 seconds. I want to know why is that.
120 seconds
SELECT B.* FROM
(SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM  (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B WHERE B.ALLOWED = '1' ORDER BY OLOG;0,3 seconds
SELECT B.* FROM
(SELECT A.OLOG, MCL_ISPROTOCOLALLOWED('LMOD', 'MCLI', A.OPRG) ALLOWED FROM  (SELECT DISTINCT OLOG, OPRG FROM FLOG WHERE FIRM = '001') A) B ORDER BY OLOG;Table FLOG has arround 270000 records, but only 40 of them are distinct.
IsProtocolAllowed checks if user has a permision to view the record.
Thank you for your help.
Regards,
Borut Ojcinger
Edited by: 993896 on 14.3.2013 7:24

Hi,
welcome to the forum.
Please read SQL and PL/SQL FAQ
If you have a performance issue have a look at SQL and PL/SQL FAQ
Additionally when you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Regards.
Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • Select sdo_nn with where-clause on large table

    Hi spatial-experts,
    I've following problem. I use a table with more than 2.500.000 dataset. Every dataset represents one point (SDO_GEOMETRY, SDO_POINT_TYPE) and have further (text) information. (PI (point of interest) table from TeleAtlas mn_pi)
    Following Select works fine:
    SELECT /*+ ORDERED NO_INDEX(pi IX_PI_FEATTYP) */
    sdo_nn_distance(1) distance,
    id, feattyp, arnamelc, name, stname, stnamelc, hsnum, postcode
    FROM multinet.mn_pi pi
    WHERE
    pi.feattyp IN ( 9373,9374)
    AND
    SDO_NN(
    pi.geom,
    SDO_GEOMETRY( 2001, 8307, SDO_POINT_TYPE(613.86865234375/60, 3002.94677734375/60, NULL), NULL, NULL),
    'sdo_batch_size=0', 1) = 'TRUE'
    AND rownum = 1
    ORDER BY distance
    (P.S. IX_PI_FEATTYP is an index on column feattyp, here not used. When I'm using it the select do not work (it last very long...))
    When I now modify the where clause to an pi which feat type that does not exists (no entry in table) the select lasts very long (I canceled the select after 5 minutes).
    for example: pi.feattyp = 9756
    Otherwise I add a further where clause like
    AND arnamelc = 'ITA'
    the select also works very long. The point are now in italy. refrence point is in germany and is more than 500km away.
    Are there some solutions to solve this problems
    (should I use for every feat type a own table)?
    Why is the select so slow?
    Thanks for all helpfully answers,
    Matthias

    Hi Matthias,
    When you use nearest neighbor, Oracle will use the spatial index to find the nearest neighbor that meets the query criteria. It probes into the index, calculates distances, and returns data in distance order.
    Using SDO_BATCH_SIZE, it keeps going back to the database, returning more and more records in distance order until the other predicates are satisfied (in your case, pi.feattyp IN ( 9373,9374).
    When you specified pi.feattyp = 9756 (which doesn't exist), you told Oracle to keep going and calculating distances for each of the more than 2.500.000 records in the the data set (you killed it after 5 minutes).
    I don't know why adding: AND arnamelc = 'ITA' caused Oracle to take extra time. Sometimes I will do a: set autotrace trace exp
    then compare plans for something that runs quickly vs. something that runs slowly. If you want to post the plans for the fast and slow versions it might be interesting to look at.
    My guess is you may want to look at a solution that incorporates various possibilities. For instance, if there are only a few of some feattyp values, you may want to select those using the non-spatial index then use sdo_geom.sdo_distance to find the closest point rather than risk having to look through a few million values for a match.
    I'm sure other people have thoughts as well...
    Kind regards,
    Dan

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Select-options with where condition

    Hello ABAPers,
    I want to create a select-options like s_operid for vbpa-kunnr but with a condition specified is VBPA-KUNNR where VBPA-PARVW = 'WE'.
    Thanks in advance. Pls reply asap. Points will definitely be rewarded.
    Ritu

    hi,
    use this
    PARAMETERS : TAB_ID TYPE ZALOAD_PROD_COMB-TAB_ID OBLIGATORY.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR TAB_ID.
    DATA : BEGIN OF INT_TAB_ID OCCURS 0,
                TAB_ID TYPE ZALOAD_PROD_COMB-TAB_ID,
             END OF INT_TAB_ID.
      DATA : LOC_MAX TYPE ZALOAD_PROD_COMB-TAB_ID.
      CLEAR INT_TAB_ID.
      REFRESH INT_TAB_ID.
      SELECT MAX( TAB_ID) INTO (LOC_MAX) FROM ZALOAD_PROD_COMB.
      COUNT = LOC_MAX + 1.
      DO 10 TIMES.
        MOVE COUNT TO INT_TAB_ID-TAB_ID.
        APPEND INT_TAB_ID.
        COUNT = COUNT + 1.
      ENDDO.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
         RETFIELD            = 'TAB_ID'                        u201C Internal table field name
         DYNPPROG         = 'PROG_NAME                  u201C Program name
         DYNPNR              = SY-DYNNR
         DYNPROFIELD   =  'TAB_ID'                        u201C Field where u need F4 help
         VALUE_ORG       = 'S'
       WINDOW_TITLE  = u2018Any descriptionu2019
        TABLES
          VALUE_TAB      = INT_TAB_ID.                   u201C Internal table name
    Mark the post answered once ur problem is solved ....

  • No records selected - SELECT clause with IN

    Hello ABAP Experts
    1st CASE:
    When I execute program below and leave selection screen for S_VBELN and S_ERDAT blank and leave P_AUART to 'PR00", it returns SY-SUBRC = 4. 
    I get no lines returned.
    2nd CASE:
    If I comment out the last 2 lines in my "WHERE" clause of my SELECT, so now my select statement is like this:
            select vbeln erdat auart knumv from vbak into table gt_vbak
                  where vbeln in S_VBELN.
    and leave selection screen for S_VBELN and S_ERDAT blank and leave P_AUART to 'PR00",
    I get lines.  I can even enter a specific order and it will only return that one.
    Can someone explain why my SELECT statement in CASE 1 is not working?
    REPORT  YTEST4.
    tables: vbak.
    SELECT-OPTIONS: S_VBELN for VBAK-VBELN,
                                     S_ERDAT for VBAK-ERDAT.
    PARAMETERS:      P_AUART like vbak-auart default 'PR00' obligatory.
    data: begin of gt_vbak occurs 0,
             vbeln like vbak-vbeln,
             erdat like vbak-erdat,
             auart like vbak-auart,
             knumv like vbak-knumv.
    data: end of gt_vbak.
    START-OF-SELECTION.
      select vbeln erdat auart knumv from vbak into table gt_vbak
            where vbeln in S_VBELN
               and erdat in S_ERDAT
               and auart  = P_AUART.
      loop at gt_vbak.
        write:/ gt_vbak-vbeln, gt_vbak-erdat, gt_vbak-auart, gt_vbak-knumv.
      endloop.

    HI,
    The data format in p_auart may be wrong..
    try this way
    REPORT YTEST4.
    tables: vbak.
    SELECT-OPTIONS: S_VBELN for VBAK-VBELN,
    S_ERDAT for VBAK-ERDAT,
    <b>s _AUART for vbak-auart obligatory no-extension no intervals</b>.
    data: begin of gt_vbak occurs 0,
    vbeln like vbak-vbeln,
    erdat like vbak-erdat,
    auart like vbak-auart,
    knumv like vbak-knumv.
    data: end of gt_vbak.
    initialization.
    s_auart-low = 'PA00'.
    s_auart-opt  = 'I'.
    s_auart-sign = 'EQ'.
    append s_auart.
    START-OF-SELECTION.
    select vbeln erdat auart knumv from vbak into table gt_vbak
    where vbeln in S_VBELN
    and erdat in S_ERDAT
    <b>and auart in s_AUART.</b>
    loop at gt_vbak.
    write:/ gt_vbak-vbeln, gt_vbak-erdat, gt_vbak-auart, gt_vbak-knumv.
    endloop.
    Thanks
    mahesh

  • I need help with motion control. I am programming in Visual Basic. I will need help with what parts I need to purchase from NI, along with help on the code.

    I am using a Papst servo motor and I need to know where to start and what to purchase to get this motor to spin. I am using visual basic and in my program I calculate the direction and RPM's needed from the motor. It will spin anywhere from 1 to 10000 RPM's. It seems rather easy, but I have no idea on how to spin the motor at the specific RPM, and stop it with a command stop in the program. Please help.

    We really should know a little more about your intended uses for this system, but assuming you want to do relatively simple (or even not so simple!) motion, you'll need a few components...
    A motion controller, such as the PCI-7342, can take your VB commands and turn them into the commands needed to "run" the motor. Next you'll need a drive, such as the MID-7342. This includes the servo amplifier that actually powers the motor. It also has connections to "pass through" the encoder signals from the motor back to the motion controller.
    The above-named pieces assume one or two axes of motion. You'll also need a cable to connect the two (can't remember the model right now). You can use MAX to configure the motion controller, and there are just a few VB calls you
    'll need to make using NI-Motion functions to define the motion and get it going.
    Hope this helps!

  • RETURNING clause with WHERE

    Hi friends,
    Is there any way to restrict the values fetched using RETURNING caluse after an UPDATE?
    For example, the following RETURNING caluse will fetch the new SALs of the DEPTs 10 and 20:
    UPDATE EMP
    SET SAL = SAL+100
    WHERE DEPT IN (10,20)
    RETURNING SAL BULK COLLECT INTO ARRAY_NEW_SAL;
    Is it possible to fetch the new SALs of only DEPT 10? Anything like:
    UPDATE EMP
    SET SAL = SAL+100
    WHERE DEPT IN (10,20)
    RETURNING SAL BULK COLLECT INTO ARRAY_NEW_SAL WHERE DEPT = 10;
    Edited by: 964559 on 30-May-2013 03:41

    No, you can't.
    The returning clause is used to return data from all the effected rows of the update. It's a part of PL/SQL, not SQL, so you cannot apply an SQL WHERE clause to it.
    The RETURNING clause and the way you can use it are detailed in the documentation (what a surprise!)...
    http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/returninginto_clause.htm#LNPLS01354

  • Select query with primary key on RESB taking too long

    Hello All,
    The below Select query is taking about 1 Hour to run on production. I have done some analysis and the correct index is being selected.
    The query is :
    IF it_aufnr[] IS NOT INITIAL.                             
        SELECT rsnum
               rspos
               matnr
               werks
            lgort
               shkzg
               aufnr
               bdmng
               enmng                      
               FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
               WHERE rsnum EQ it_aufnr-rsnum
               AND   xloek NE 'X'
               AND   postp NE 'X'
               AND   resb~bdmng GE resb~enmng.
      ENDIF.
    Database Table RESB: 40,000,000 Records (40 Million)
    Internal Table   it_aufnr:  20,000 Entries
    Entries selected from RESB: 150,000.
    Any ideas on how I could improve the performance ?
    Thanks,
    Shruthi

    >     SELECT rsnum
    >            rspos
    >            matnr
    >            werks
    >         lgort
    >            shkzg
    >            aufnr
    >            bdmng
    >            enmng                      
    >            FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
    >            WHERE rsnum EQ it_aufnr-rsnum
    >            AND   xloek NE 'X'
    >            AND   postp NE 'X'
    >            AND   resbbdmng GE resbenmng.
    >   ENDIF.
    >
    > Database Table RESB: 40,000,000 Records (40 Million)
    > Internal Table   it_aufnr:  20,000 Entries
    > Entries selected from RESB: 150,000.
    >
    Hi,
    the problem is the big for all entries table.
    Your 20.000 records FAE will be split into SEVERAL sql statements depending on the size of the table.
    Where do you get the it_auftrn from?
    If it's another transparent table try to JOIN this table to your big table.
    SELECT rsnum
                rspos
                matnr
                werks
            lgort
                shkzg
                aufnr
                bdmng
                enmng                      
                FROM  resb JOIN tab_auftrn  on  resbrsnum = tab_auftrnauftrn
                AND   xloek NE 'X'
                AND   postp NE 'X'
                AND   resbbdmng GE resbenmng.
    Make sure that your WHERE filter and the JOIN keys on both tables are supported by indexes.
    150.000 records about of 40 Mio. can definitly be serviced by an appropriate index:
    i.e. Index fields (check your PK or secondary indexes):
    rsnum
    enmng                      
    aufnr
    bye
    yk

  • Filter Criteria with where condition in graph api query

    Hi
    Filter criteria in  graph api is  working fine  through this api
    https://graph.windows.net/adummydirectory.onmicrosoft.com/users?$filter=displayName eq 'Ashok'&api-version=1.5
    Select criteria is also working fine through this api
    https://graph.windows.net/ adummydirectory.onmicrosoft.com/users?api-version=1.5&deltaLink=&$select=displayName,accountEnabled
    But when I am combining both query that means, I want that select criteria should also apply with filter clause like
    https://graph.windows.net/adummydirectory.onmicrosoft.com/users?$filter=displayName
    eq 'Ashok'&api-version=1.5&deltaLink=&$select=displayName,accountEnabled
    But its generating error
        "odata.error": {
            "code": "Request_UnsupportedQuery",
            "message": {
                "lang": "en",
                "value": "Unsupported expression node type 'Equal' for Where expression."
    So please suggest how we can use select clause with filter criteria. our requirement is that we don’t need all attributes .we want selected attributes for filtered users.

    Greetings!
    The differential query syntax does not allow for a filter other than $filter=isof(<directory entry type>).  You are not able to use any other query string for this type of query.  Please see the following MSDN link for details:
    http://msdn.microsoft.com/en-us/library/azure/jj836245.aspx
    I will need to do a bit more research to see if it is possible to request specific attributes for an object query and post back to this thread when I have a response.
    Regards,
    MaxV ( MSFT )

  • Subcontracting with discontinued parts

    We use discontinuations all the time but now we are fully subcontracting some products and the discontinuation is not being planned for either the old part or the new part. SAP help clearly says that subreq discontinuation is not planned but with several parts at any one time on boms of over 200 parts, we just can't manually manage this.
    I don't believe we are the only one with this problem but I am unable to find any solution - please help!
    Thanks

    Hi Krishna,
    Thanks for your reply but I don't understand how safety stock would work. Are you suggesting loading safety stock against the new part?
    We have 12+ weeks lead times and constantly changing forecasts. The discontinuation worked very well in managing the old part down to zero stock with all the variables involved but safety stock is a fixed figure?
    Please advise.
    Donna

  • Where clause with inner select ...

    I want to create a view similar to the following:
    CREATE VIEW VXRAY AS
    (SELECT a.modex, b.action_date
    FROM itac a, xray b
    WHERE a.item_id = b.item_id
    AND b.action_date =
    (SELECT max(c.action_date)
    FROM xray c
         WHERE c.item_id = b.item_id
    AND To_Char(c.action_date,'yymmdd') <= '980825'));
    Unfortunately, I cannot hardcode the date value as shown in the above example.
    So my question really is: "How can I construct the view without using a harcoded value ('980825' in above example)?".
    Since this view will be accessed by a reporting tool (Safari Reports), there will be no intelligence in the actual SQL query statement other than for example:
    "select * from vxray where item_id = 'IID001' and action_date <= '25 Aug 1998' "
    I've had some suggestions about using a "GROUP BY" function. (this doesn't work for me since the above example is just a very simplified version of what I'm selecting)
    I've also had suggestions about using the "&" paremeter prompt in the inner select (for the date value). Again, won't work (as mentioned earlier with the view being accessed from a Reporting Tool).
    If I had the following data in the 2 tables:
    ================ ==========================
    ITAC XRAY
    ================ ==========================
    ITEM_ID MODEX ITEM_ID ACTION_DATE
    IID001 1535 IID001 10-DEC-97
         IID001 24-AUG-98
    IID001 05-OCT-98
    SELECT * FROM vxray WHERE item_id = 'IID001' AND to_char(action_date,'yymmdd) <= '980825';
    MODEX ACTION_DATE
    1535 24 Aug 98

    Warren, thanx for the prompt reply ... unfortunately that won't work since the problem is not really accessing the view, but the SQL construction of the view itself.
    Here's what the real query looks like:
    CREATE VIEW vaaarpt AS (
    SELECT DISTINCT
    a.modex MODEX ,
    b.buno BEREAU_NUMBER ,
    b.action_date LATEST_ACTION_DATE,
    b.status_code STATUS_CODE ,
    b.model MODEL ,
    c.activity_code ACTIVITY_CODE ,
    c.curr_count CURR_COUNT ,
    d.item_id ITEM_ID ,
    d.sc SC ,
    (SELECT Sum(f.new_count)
    FROM vusage f
    WHERE f.interval_type = c.interval_type
    AND f.item_id = c.item_id
    AND f.end_datetime > b.action_date) FH_USAGE
    FROM itac a, xray b, act1 c, item d
    WHERE a.item_id = b.item_id
    AND b.item_id = c.item_id
    AND c.item_id = d.item_id
    AND b.action_date =
    (SELECT max (f.action_date)
    FROM xray f
    WHERE f.item_id = b.item_id
    AND To_Char(f.action_date,'yyyy/mm/dd') <= 'xxx') );
    Above view construction is incorrect since I don't have the value of xxx at the time when I defined the view.

  • Urgent: Performance problem with where clause using IN and an OR condition

    Select statement is:
    select fl.feed_line_id
    from ap_expense_feed_lines_all fl
    where ((:1 is not null and
    fl.feed_line_id in (select distinct r2.object_id
    from xxdl_pcard_wf_routing_lists r2,
         per_people_f hr2
    where upper(hr2.full_name) like upper(:1||'%')
              and hr2.person_id = r2.person_id
    and r2.fyi_list is null
              and r2.sequence_number <> 0))
    or
    (:1 is null))
    If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
    Explain plan for the whole statement is:
    (1) SELECT STATEMENT CHOOSE
    Est. Rows: 10,960 Cost: 212
    FILTER
    (2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
    (2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
    Tablespace: APD
    (6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
    (6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
    Tablespace: HRD
    (5) NESTED LOOPS
    Est. Rows: 1 Cost: 4
    (3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
    (3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
    Tablespace: XXDLD
    (4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
    Est. Rows: 1 Cost: 1
    Thanks in advance,
    Peter

    Thanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
    Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
    My sql is:
    select a_column
    from a_table
    where ((:1 is not null) and a_column in (sub-select statement)
    or
    (:1 is null))
    The :1 bind variable is set to a varchar2 entered on the screen of an application.
    If I execute either part of the sql without the OR condition, performance is good.
    If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
    If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
    As an example:
    where (('wa' is not null) and a_column in (sub-select statement)) -- fast
    where (('wa' is null)) -- fast
    where (('' is not null) and a_column in (sub-select statement) -- fast
    or
    ('' is null))
    where (('wa' is not null) and a_column in (sub-select statement) -- slow
    or
    ('wa' is null))

  • Need to know the column names in my dynamic select clause

    Dear All,
    Please go through the following code. While executing the following code i am getting an error saying that dbms_sql.describe_columns overflow, col_name_len=35. Use describe_columns2.
    Please guide me how to proceed further. Or please help me, how can i get the column names when i issue a dynamic select clause.
    DECLARE
    CUR INTEGER;
    COL_CNT INTEGER ;
    A INTEGER;
    SEL_CLAUSE VARCHAR2(2000);
    DESC_T DBMS_SQL.DESC_TAB;
    REC DBMS_SQL.DESC_REC;
    b number;
    BEGIN
    SEL_CLAUSE := 'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'',3,''THREE'') FROM DUAL';
    --'SELECT ROWID,PARA_SUB_CODE,DECODE('||''''||'ENG'||''''||','||''''||'ENG'||''''||',PARA_NAME,PARA_BL_NAME),NULL,NULL FROM PCOM_APP_PARAMETER';
    --'SELECT 1,2,DECODE(1,1,''ONE'',2,''TWO'') FROM DUAL';
    DBMS_OUTPUT.PUT_LINE( SEL_CLAUSE );
    CUR := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(CUR,SEL_CLAUSE,DBMS_SQL.NATIVE);
    DBMS_SQL.DESCRIBE_COLUMNS(CUR,COL_CNT,DESC_T);
    B := desc_t.first;
    FOR J IN 1..COL_CNT
    LOOP
    DBMS_OUTPUT.PUT_LINE('J := '||J || ' COL CNT ' || COL_CNT);
    END LOOP;
    BEGIN
    A := DBMS_SQL.EXECUTE(CUR);
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    END;
    Regards,
    Balaji

    Is there any way can i have it directly??It does not work with static SQL either. Dynamic SQL is no different.
    SQL> select 1 x from dual where x = 1 ;
    select 1 x from dual where x = 1
    ERROR at line 1:
    ORA-00904: "X": invalid identifier
    SQL>As suggested already, you will need to use alias if you want your select expression to be referred in the where clause.
    SQL> BEGIN
      2      FOR rec IN (SELECT *
      3                  FROM   (SELECT 1,
      4                                 2,
      5                                 DECODE(1, 1, 'ONE', 2, 'TWO', 3, 'THREE') "DECODE(1, 1, 'ONE', 2, 'TWO', "
      6                          FROM   DUAL)
      7                  WHERE  "DECODE(1, 1, 'ONE', 2, 'TWO', " = 'ONE')
      8      LOOP
      9          NULL;
    10      END LOOP;
    11  END;
    12  /
    PL/SQL procedure successfully completed.
    SQL>Message was edited by:
    Kamal Kishore

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

Maybe you are looking for