Using DBLINK in PL/SQL SQL Query

Hi
is it possible to use dblink in plsql cursor query.
are there any do's or dont's in this regard or any special things to take care of?
Basically what I need to do is access data from remote tables and put them in local tables after some proessing on data.
Any help !!

well, since all pl/sql does is to pass the SQL statement to the database to be run, it's not a pl/sql issue. it's a SQL question. so it's the same as running the query in sqlplus (or toad or frog or whatever you use). the fact that it's embedded in pl/sql doesn't change anything, so: yes, it's possible, and no there aren't any do/don'ts (other than what would already apply to native SQL.

Similar Messages

  • How to create a Matrix table using this data in SQL Query Analyzer

    Hello all,
    I have a problem while I am trying to represent my Sql Table namely table1 in Matrix form
    my table Format is
    city1 city2 Distance--------------------------------------------------------
    Mumbai Delhi 100
    Delhi Banaras 50
    Mumbai Rajasthan 70
    Banaras haryana 40
    Mumbai Mumbai 0
    784 entries
    there are 784 cities each having link to other
    Now i want my output as
    Mumbai Delhi Banaras haryana
    Mumbai 0 100 -- --
    Delhi 100 0 50 --
    Banaras
    haryana
    respective distance from one city to other should be shown
    final Matrix would be 784*784
    I am using SQL Query Analyser for this
    Please help me in this regard

    I'm pretty much certain that you don't want to do this in pure SQL. So that means that you want to do it with a reporting tool. I'm not familiar with SQL Query Analyzer, but if it is in fact a reporting tool you'll want to consult its documentation looking for the terms "pivot" or perhaps "cross tab."

  • How can I use the Rownum/Customized SQL query in a Mapping?

    Hi,
    * I need to use a Rownum for populating one of the target field? How to create a mapping with Rownum?
    * How can I use an Dual table in OWB mapping?
    * Can I write Customized SQL query in OWB? How can I achieve this in a Mapping?
    Thanks in Advance
    Kishan

    Hi Niels,
    As I'm sure you know, the conundrum is that Reports doesn't know how many total pages there will be in the report until it is all done formatting, which is too late for your needs. So, one classical solution to this problem is to run the report twice, storing the total number of pages in the database using a format trigger, and throwing away the output from the first run when you don't know the total number of pages.
    Alternatively, you could define a report layout so that the number of pages in the output is completely predictable based upon, say, the number of rows in the main query. E.g., set a limit of one, two, ... rows per page, and then you'll know how many pages there will be simply because you can count the rows in a separate query.
    Hope this helps...
    regards,
    Stewart

  • Using Exec on a SQL Query

    Hi.
    Why it doesn't work in the SQL Query of Crystal?
    EXEC ('USE ZZZ_'+{?Base})
    SELECT........................
    {?Base} is a string variable and its value is correct
    Thanks

    You probably can't use an expression for EXEC.  I know MS SQL doesn't allow it.  However, you don't need an expression if this is in an SQL Command data source.  Just use:
    USE ZZZ_{?Base}
    As long as {?Base} is a string parameter, its value will be substituted into the line - without quotes.  So if the parameter value is AAA, the resulting line would be
    USE ZZZ_AAA
    You can do the same thing with field names or other SQL text.  Obviously, you want to control the values that the parameter can be when you do such a thing...  (Do not allow the user to type what will be used in unquoted SQL!)
    HTH,
    Carl

  • Lookup creation and using this lookup in SQL query

    I Have two tables one table called T_KEY_VALUES (KEY_ID , VALUE) and other is my transition table T_TRANSACTIONS (VERSION_ID , COL_VENDOR , COL_PREFIX, COL_RECIPTID , COL_STATE , COL_COUNTRY ..)
    The data looks like below:
    T_KEY_VALUES:
    KEY_ID , VALUE,
    10, CA
    11, NY
    13, NJ
    20, USA
    21, CANADA
    101 , AMC
    102, REGAL
    1001, MOVIES
    1002, MALLS
    T_TRANSACTIONS:
    VERSION_ID , COL_VENDOR , COL_PREFIX , COL_RECIPTID , COL_SATE , COL_COUNTRY
    1, 101 , 1001 , 100001 , 10 , 20
    2, 102 , 1002  , 100002 , 11 ,20
    Generally, COL_VENDOR, COL_PREFIX , COL_STATE , COL_COUTRY field values exist in the T_KEY_VALUES table.
    So How can I use T_KEY_VALUES as Lookup and write the one SQL query to get the data like below:
    1, AMC , MOVIES , 100001 , CA ,USA
    2, REGAL , MALLS , 100002 , NY , USA

    Hi,
    One way is to join t_transactions to 4 copies of t_key_values:
    SELECT  t.version_id
    ,       v.value           AS vendor
    ,       p.value           AS prefix
    ,       t.col_reciptid
    ,       s.value           AS state
    ,       c.value           AS country
    FROM    t_transactions  t
    JOIN    t_key_values    v  ON  v.key_id  = t.col_vendor
    JOIN    t_key_values    p  ON  p.key_id  = t.col_prefix
    JOIN    t_key_values    s  ON  s.key_id  = t.col_state     -- or col_sate
    JOIN    t_key_values    c  ON  c.key_id  = t.col_country
    If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test this.
    The query above assumes all 4 coded columns in t_transactions have matching values in t_key_values, as they do in the sample data.  If that assumption is wrong, then use outer joins in some (or all) of the places where I used inner joins above.
    Another approach is to UNPIVOT t_transactions into 4 times as many rows, do a single join to t_key_values, and then PIVOT those results back to the original number of rows.

  • Ajax Autocomplete Tabular does not work using apex_item.text in SQL Query.

    Hello,
    Is it possible to use the search function which is used in, Dennis Kubicek example, ENAME topic Ajax Autocomplete Tabular
    in a sql query using apex_items?
    Query line :
    , apex_item.text(17,xp.part_nr,null,null,'onfocus="f_register(this);" autocomplete="off"') PART
    At first I followed the example by adding 'onfocus="f_register(this);" autocomplete="off" in the element attributes in the report field.
    This didn't work... so tried to add the it in the attirbutes parameter of the apex_item.
    But this still doesn't work. No errors are given, it does not respond.
    Could somebody please help me?
    Thx!
    Astrid

    Well, I'm trying to take this one step further, but I seem to be having some difficulty.
    I'm trying to make a Filter screen to create a dynamic where clause filter screen.
    This is a page I made with Popup LOVS, just to show you my goal (now trying to use autofilters)
    http://apex.oracle.com/pls/otn/f?p=29989:5
    I have a table on my system that tells you where the field is, and I'm using that to get the table (didn't want to change the javascript, so I pass in a static value).
    This is the javascript code I used
    <pre>
    <script language="JavaScript" type="text/javascript">
    function f_register(p_this,p_name)
    var p_registered = $x('P5_ITEM_ID').value;
         var p_this_name = $x(p_this).id;
    //alert(p_this_name);
    if (p_registered != p_this_name)
    register(p_this_name, "COSTING_M", p_name, "blue", "red");
    $x('P5_ITEM_ID').value = p_this_name;
    </script>
    </pre>
    This is my query
    <pre>
    select column_name || apex_item.hidden(1,column_name) Col_name,
    apex_item.SELECT_LIST_FROM_lov(2,'=','OPERATOR') OPERATOR,
    apex_item.text (3,
    NULL,
    20,
    200,
    'onfocus="f_register(this,''' || column_name || ''');" autocomplete="off"',
    'f3_' || '#ROWNUM#',
    NULL
    ) value,column_id
    from user_tab_cols
    where table_name = 'COSTING_M'
    ORDER BY ROWNUM
    </pre>
    and here is my on-demand process
    <pre>
    declare
    TYPE CurTyp IS REF CURSOR;
    v_row varchar2(4000);
    rec CurTyp;
    V_TABLENAME NKW.UTFIELD_M.TABLE_NAME%TYPE;
    begin
    BEGIN
    SELECT TABLENAME INTO V_TABLENAME
    FROM NKW.UTFIELD_M
    WHERE FIELD_NAME = :TF_SL_COLUMN;
    EXCEPTION WHEN NO_DATA_FOUND THEN RETURN; END;
    :TF_SL_SEARCH := replace(:TF_SL_SEARCH, '&amp;','&');
    :TF_SL_SEARCH := replace(:TF_SL_SEARCH, '&lt;','<');
    :TF_SL_SEARCH := replace(:TF_SL_SEARCH, '&gt;','>');
    :TF_SL_SEARCH := replace(:TF_SL_SEARCH, '&quot;','"');
    owa_util.mime_header('text/xml', FALSE);
    htp.p('Cache-Control: no-cache');
    htp.p('Pragma: no-cache');
    owa_util.http_header_close;
    htp.prn('<rowset>');
    open rec for
    'select distinct ' || :TF_SL_COLUMN || ' ' ||
    'from NKW.' || V_TABLE_NAME || ' ' ||
    'where '||:TF_SL_COLUMN||' like :1||''%'' ' ||
    'and rownum < 100 ' ||
    'order by '||:TF_SL_COLUMN
    using :TF_SL_SEARCH;
    loop
    fetch rec into v_row;
    exit when rec%NOTFOUND;
    htp.prn('<row>' || htf.escape_sc(v_row) || '</row>');
    end loop;
    htp.prn('</rowset>');
    end;
    </PRE>
    I made some slight mods to make the table dynamic from my source table (this is to grab master files when they exist and not to when they don't).
    I get my select list, but it's blank on all fields, any suggestions?
    thanks,
    Scott

  • Use of 'CAST' in SQL query

    I am using following objects.
    CREATE OR REPLACE TYPE t_assoc_agents_address AS OBJECT
    (V_CONTACT_NAME VARCHAR2(120),
    V_ADDRTYPE VARCHAR2(80),
    V_ADDRESS_LINE1 VARCHAR2(50),
    V_ADDRESS_LINE2 VARCHAR2(50),
    V_ADDRESS_LINE3 VARCHAR2(50),
    V_CITY_STATE_ZIP VARCHAR2(100),
    V_PHONE VARCHAR2(50),
    V_ADDRESS_FAX VARCHAR2(30),
    V_ADDRESS_EMAIL VARCHAR2(80)
    CREATE OR REPLACE TYPE nt_assoc_agents_address AS TABLE OF t_assoc_agents_address;
    Following SQL query is working fine.
    Sql:
    SELECT *
    FROM
    table(cast (lv_assoc_agents_add_out AS nt_assoc_agents_address));
    But, following Sql query doesn't work.
    SELECT V_ADDRESS_FAX,V_ADDRESS_EMAIL
    FROM
    table(cast (lv_assoc_agents_add_out AS nt_assoc_agents_address));
    Oracle Error: 'V_ADDRESS_EMAIL' invalid identifier.
    Would you please clarify this, and suggest appropriate solution to select specific columns instead of
    selecting all columns in above SQL query.

    OK, I have found your code in your previous post.
    It works in 9.2.0.1.0 and 8.1.7.0.0.
    SQL> CREATE OR REPLACE TYPE t_assoc_agents_address AS OBJECT
      2  (V_CONTACT_NAME VARCHAR2(120),
      3  V_ADDRTYPE VARCHAR2(80),
      4  V_ADDRESS_LINE1 VARCHAR2(50),
      5  V_ADDRESS_LINE2 VARCHAR2(50),
      6  V_ADDRESS_LINE3 VARCHAR2(50),
      7  V_CITY_STATE_ZIP VARCHAR2(100),
      8  V_PHONE VARCHAR2(50),
      9  V_ADDRESS_FAX VARCHAR2(30),
    10  V_ADDRESS_EMAIL VARCHAR2(80)
    11  )
    12  /
    &nbsp
    Type created.
    &nbsp
    SQL> CREATE OR REPLACE TYPE nt_assoc_agents_address AS TABLE OF t_assoc_agents_address
      2  /
    &nbsp
    Type created.
    &nbsp
    SQL> var c refcursor
    SQL> col v_address_fax format a15
    SQL> col v_address_email format a15
    SQL> declare
      2   lv_assoc_agents_add_out nt_assoc_agents_address
      3   := nt_assoc_agents_address(
      4     t_assoc_agents_address(null,null,null,null,null,null,null,
      5     'New Fax', 'New Mail')
      6   );
      7  begin
      8   open :c for select V_ADDRESS_FAX,V_ADDRESS_EMAIL from
      9   table(cast(lv_assoc_agents_add_out as nt_assoc_agents_address));
    10  end;
    11  /
    &nbsp
    PL/SQL procedure successfully completed.
    &nbsp
    SQL> print c
    &nbsp
    V_ADDRESS_FAX   V_ADDRESS_EMAIL
    New Fax         New MailWhat is your Oracle release and how are you using ref cursor (if I interpret your example right) ?
    Rgds.

  • Using Forumlas in (Command) SQL Query

    We're trying to optimize the record returns on some reports and recently discovered the ability to apply a Command to specify the SQL Query.
    One of the things we do with our reports is actually pass in some values so the user doesn't have to enter so many parameters.  So we define a couple of formula tags and then pass values into those during the oninitialization portion of the crystal subclass in our program.
    In our case these formula tags would be Jobcode and Division
    Prior to our discovering the Command option, we were using those formulas in the Record and Group selections in this manner:
    We would define two other formulas as thus:
    sMyJobCode
      ToText({@Jobcode})
    sMyDivision
      ToText({@Division})
    and then we would call those in the Record and Group selection
    example:
    SELECT * from TableA where TableA.date between {?StartDate} and {?EndDate} and TableA.job = {@sMyJobCode} and TableA.division = {@sMyDivision}
    My problem is that I can't figure out a way to include those formulas in the Command.  It lets me use parameters (the date ranges in this case).  But I need to get those two formula values (sMyJobCode and sMyDivision) pulled in as part of that initial SQL query because those values filter the record returns substantially.
    Is there a way to do this?  Any help on this would be greatly appreciated.

    An SQL Command can not use formula fields directly.  I would think that using parameters - with default values set - would be just as easy for the user, and they could be used in the SQL.
    Barring that, you could put the report into a subreport (if it is not already using subreports).  Calculate the formula in the main report, and use the formula to link to the subreport's parameters, which are added as parameters to the subreport's SQL Command.
    HTH,
    Carl

  • Error using Database addons with SQL query.

    I get a LabVIEW error when I provide the following SQL query to the NI database VI: ..vi.lib\addons\database\Connection.llb\Conn Execute.vi. 
    declare @SR_ID table ( script_result_id uniqueidentifier )
    insert into @SR_ID
    select script_result_id from SCRIPT_RESULT
    where script_result.software_name = '%s'
    SELECT distinct STEP_RESULT.STEP_TYPE
    FROM STEP_RESULT INNER JOIN @SR_ID s ON
    STEP_RESULT.SCRIPT_RESULT_ID = s.script_result_id
    The error is:
    Error -2146824584 occurred at NI_Database_API.lvlib:Rec Destroy - Connection.vi->Database_Query Database with flattened string reply.vi->ADUTS-RPT Query DB.vi->ADUTS-RPT Get Step Names.vi->ADUTS-RPT Top.vi
    Possible Reason(s): Exception occured in ADODB.Recordset: Operation is not allowed when the object is closed.
    The query works fine when given directly to my SQL server.
    Any ideas on this problem would be most appreciated.

    It looks like the bug is related to ADODB objects. I found a related KnowledgeBase article that was written about the same issue, but never published for some reason. Here's what it has to say about your error:
    "This error occurs when a query is run on the database that does not return any recordset data, such as a delete command.  In this case, when you encounter the DB Tools Fetch Recordset Data VI, the state of the recordset is "closed" and produces the error.
    To avoid the error, you can check for the state of the recordset and make sure that it isn't closed. To do this, use the DB Tools Get Properties VI and check the state from the properties cluster.  An additional, or alternate, check would be to check for the beginning of file and end of file properties.  If both BOF and EOF are both true, there is no data in the recordset.  
    If you open the example program, Database Fetching, you can see that they are using both of these checks.
    In versions of the toolset prior to version 1.0.2, these checks were built in.  This causes code without the checks to return this error if the toolset is updated from a previous version."
    Tim W.
    Applications Engineering
    National Instruments
    http://www.ni.com/support 

  • Using view as a sql query in odisqlunload

    Hi Expert,
    I tried sql query in osisqlunload but that query retrieving the data from a view,even operator log shows successful execution data,but data is not getting into text file......
    Is Odisqlunload supports views as sqlquery?
    cheers,
    surya
    Edited by: surya on Apr 6, 2012 4:34 PM

    Hi Bhabani,
    Thanks for your prompt replay, it showing successfully executions, but data is not populating....
    Do u have any links regarding this....
    Cheers,
    Surrya

  • Changing A Value Using If Statement in SQL Query

    Hello, I have a very rudimentary question that I'm stuck on.  I have a query that returns one of 3 different integers.  I want to have each integer translate to a string value depending on the number returned.  Unfortunately this is the SCCM
    database which cannot be changed to provide an additional table with the values.
    I have something like this but I'm not getting what I want out of the date - depending on what I do I either get an error, or nothing.
    Declare @NewValue nvarchar
    Declare @Value nvarchar
    If @Value = 1 Set @Value = 'String1'
    If @Value = 2 Set @Value = 'String2'
    If @Value = 3 Set @Value = 'String3'
    Select PrimaryKey,IntegerValue FROM db_Table WHERE @Value=IntegerValue
    I know this is a simple thing but I'm new to SQL and not exactly sure what terms I should even be using to search for this.  Thanks for the help!

    select PrimaryKey, IntegerValue, case IntegerValue when 1 then 'String1'
    when 2 then 'String 2' when 3 then 'String3' else 'Unknown Integer Value' end as [Description]
    from db_Table
    Take a look at
    CASE expression in BOL. You may also find the following article helpful
    http://social.technet.microsoft.com/wiki/contents/articles/21327.t-sql-simplified-case-expression.aspx
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Not right data when row_number used in inner-view sql query...

    Hi ,
    I use the below sql statement which displays the right data
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)The data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA ROW_NUMBER()OVER(PARTITIONBYCO
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5                              1
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30                              1
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45                              1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6                              1
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2                              2
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                        21                              1
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                         2                              2However , when i use the below statement , in order not to display the row_number (so i use row_number function in inner-view) the data are different--in different order... why is that????
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA from
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)
      )and its data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                        21
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                         2
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1NOTE :Sorry, I tried to pose some sample data using the "with" statement but i couldn't...the error ORA-32035 : unreferenced query name defined in WITH clause was displayed..
    Regards,
    Simon

    The optimizer has, well, optimized out the row_number because you never refer to its value in the outermost query.
    sql>select deptno, cnt, row_number() over (order by cnt desc) rn
      2    from (select deptno, count(*) cnt
      3            from emp
      4           group by deptno);
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- here because we include rn in the outermost query,
    -- the results are still ordered based on the analytical function result
    sql>select deptno, cnt, rn
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- but if we don't include rn in the outermost query,
    -- the optimizer leaves out the window sort and the results are in a different order
    sql>select deptno, cnt
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT
           10         3
           20         5
           30         6
    3 rows selected.This just reinforces the point that if you want your results in a particular order, you need to provide an ORDER BY clause - don't rely on execution plans to do your sorting for you.

  • How to use check box in SQL Query

    Hi
    I have a reagion with check boxes. Now I am creating another region which is
    PL/SQL function/block returning query.
    here' the block. When I save it give me error
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00900: invalid SQL statement
    Here is the code
    DECLARE
    p_str VARCHAR2(2000);
    p_col_name varchar2(100);
    p_flg char(1);
    BEGIN
    p_flg := 'N';
    for i in 1 .. htmldb_application.g_f01.count
    LOOP
    p_flg := 'Y';
    p_col_name := htmldb_application.g_f01(i);
    IF i = 1
    THEN
    p_str := 'SELECT ' || p_col_name;
    ELSE
    p_str := p_str || ', ' || p_col_name;
    END IF;
    END LOOP;
    p_str := p_str || ' FROM UALDBA_V';
    RETURN p_str;
    END;
    Please advice
    Sunil

    Sunil - The htmldb_application.g_fxx arrays are empty during page rendering. A query cannot be generated using them.
    Scott

  • Using "LIKE" in J2EE SQL Query Window

    Whats the syntax to define a finder method using the SQL "LIKE" clause in J2EE in the deployment settings of an CMP entity bean...for example lets say I have an entity bean with a primary ket called "PK" and a String data member called "Titile", I've tried:
    SELECT "PK" FROM "EntityBeanTable" WHERE "Title" LIKE
    %?1%
    but that doesn't work...any suggestions?

    I believe the solution may be vendor specific. i am using weblogic5.1 and i use CMP entity beans.
    Now the if i want a sql with like clause, then i give in the following entries in my
    weblogic-cmp-rdbms-jar.xml
    <finder>
    <method-name>findByPrimaryKey</method-name>
    <method-params>
    <method-param>java.lang.Long</method-param>
    </method-params>
    <finder-query><![CDATA[ (like acctCode $0)]]></finder-query>
    </finder>
    for more options please refer u r vendor documentations.
    regards
    rajesh

  • Using Interactive Report with SQL query accessing tables via db link

    Is there a known issue with using the interactive report in version 3.1.2.00.02 with SQL that is accessing tables via a database link? I get the error 'not all variables bound', I do not get this error when using the standard report for the same SQL?
    Thanks,
    Edited by: [email protected] on May 26, 2009 2:59 PM

    Varad,
    Good question, failed to check that. In fact there are errors. Dump file c:\oraclexe\app\oracle\admin\xe\bdump\xe_s002_3640.trc
    Mon Jun 15 08:48:11 2009
    ORACLE V10.2.0.1.0 - Production vsnsta=0
    vsnsql=14 vsnxtr=3
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    Windows XP Version V5.1 Service Pack 3
    CPU : 2 - type 586, 1 Physical Cores
    Process Affinity : 0x00000000
    Memory (Avail/Total): Ph:1051M/2038M, Ph+PgF:2273M/3934M, VA:1302M/2047M
    Instance name: xe
    Redo thread mounted by this instance: 1
    Oracle process number: 16
    Windows thread id: 3640, image: ORACLE.EXE (S002)
    *** ACTION NAME:(PAGE 2) 2009-06-15 08:48:11.743
    *** MODULE NAME:(APEX:APPLICATION 112) 2009-06-15 08:48:11.743
    *** SERVICE NAME:(SYS$USERS) 2009-06-15 08:48:11.743
    *** CLIENT ID:(ADMIN:232384011651572) 2009-06-15 08:48:11.743
    *** SESSION ID:(24.931) 2009-06-15 08:48:11.743
    *** 2009-06-15 08:48:11.743
    ksedmp: internal or fatal error
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_LdiDateFromArray+55] [PC:0x608B04F3] [ADDR:0x0] [UNABLE_TO_WRITE] []
    Current SQL statement for this session:
    select Stage,Procedure,Stp,FW,Reslt,MSG,date_run
    from bi_msg_VW@dwitnm
    order by 1
    ----- PL/SQL Call Stack -----
    object line object
    handle number name
    2FE1EA14 1207 package body SYS.DBMS_SYS_SQL
    2FE1F064 328 package body SYS.DBMS_SQL
    2ABDC520 5097 package body APEX_030200.WWV_RENDER_REPORT3
    2BD5E55C 1538 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
    2BD5E55C 366 package body APEX_030200.WWV_FLOW_DISP_PAGE_PLUGS
    335BDA88 11190 package body APEX_030200.WWV_FLOW
    2BDBD1C8 255 procedure APEX_030200.F
    2AB58D10 30 anonymous block
    ----- Call Stack Trace -----
    I didn't include the call stack, it is too large. Now I'm even more puzzled that the IR would work while a sql report would fail.
    Bob

Maybe you are looking for

  • HP PSC 2355 Blue screen of Death and Error message/ blinking lights.

    Hello, I have a HP PSC2355 that we recently moved, after we moved it started randomly locking up with the Blue Screen Of Death (BSOD), it would give an error:0X880529ec on the BSOD, further down the screen were the characters 1:H+x?+  The (ON) light

  • Performance tuning in CRM server

    Hi everyone,    My CRM server working very slow. Idont know the exact reason. My server configuration IBM Xeon processor 3 Ghz 3GB RAM.There are about 25 users. Is this problem with SAP or Hardware.If any one have performance tuning document plz post

  • Macbook to older tv

    Hi, Im sorry if this has been asked, but ive had a search and cant seem to find a post. I have an older tv that id like to be able to connect my macbook to so i cant watch my itunes and stuff on. The only ports my tv has are scart and the composite (

  • Oracle drivers not found by servlets after upgrade of JDK

    I am using jakarta-tomcat 4.0.1 with WIN2K. After a recent upgrade to jdk 1.4.0_02 from jdk1.3.1, servlets that try to use oracle crash with this error: java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver      at ProductLookup.loadJDBCDri

  • Some BPF questions

    Hi colleagues, A prospect is asking the following about BPF (they will probably install 7.5 MS): By default BPC does not provide complex timing and other management-related functionality such as task routing and escalation for BPFs. What might be the