Query SQL or function...

Hi everyone,


  Please help me to clarify this question
I have a "patient" table and a "address" table.And each patient has differnt types of addresses
like PMI,Mailing and default address i need to pick patient address in the order of preference
(PMI,Mailing ,Default)

I have two options to get the address of a patient.Either write a SQL query to get the address of a 
patient(according to preference)
or write a function which checks

 if there is PMI,Mailing and default
  take PMI
 or
 If there is mailing and Default
 take mailing
 or
 take default.

which one is the best method to get the address of a patient?  SQL query or function..
Definitely everyone will say that it should be direct SQL query instead of multiple function calls.

But in my organization there are many developers which will get "patient address" in their application 
or SQL code or PL/SQL code or from some
'X' Business intelligence tool.
At this scenario is it best to have a function which every one will call and get a standardized output
 for every one.

Question:

In my scenario which one is the best to have "SQL query or function"?
if i choose "function" i have to sacrifice the performance 
if i choose "SQL query" i am not sure whether each and every developer querying the same way as it would be


Sorry if it is a dumb question to ask.

Thanks in advance
phani

hoek question: what happens if I have to choose between the SQL and function? (Assume that they do not accept to create views)

If views are not accepted (which is very strange IMO), but you need some "standard object" which anyone can use, then you would choose to use a function instead of everyone having "their own motion.
It is a compromise between maintaining standards and performance (call PL/SQL in SQL is generally to be avoided because of context switching, the other way around is OK).
One of the advantages of a view: no problems with the settings you must enter but never going to use, you just choose the columns you need and there you go.
Other: it is simple, plain and simple.
It is easier to maintain.
But everything depends on what your function returns.
Maybe a REF CURSOR?

Your question reminds me of this interesting discussion:

http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:672724700346558185

Published by: hoek on July 1st, 2009 16:39 tyop

Tags: Database

Similar Questions

  • query SQL max function need help

    Hi all

    Its simple, but I'm not able to identify the problem.

    In our HRMS EBS R12, 11g database we seeded table per_all_people_f and the column employee_number (varchar2).

    case 1: normal employees whose employee_number starts with the numerical value. (for example: 9213,9214,9999,10000,10001)

    case 2: employee_number starts with tank like 'P' - (for example: "P-1245', ' P-1246'" ")

    I am writing as a small query to get the Max (employee_number) for case 1.

    Select max (employee_number) in per_all_people_f

    where employee_number not like 'P-% '.

    Output: 9999 (didn't come out desired)

    where I employee_number 10000 and 10001.

    Select * from per_all_people_f where employee_number = "10000"

    Returns the values of the table...

    Please let me know why (employee_number) max is coming "9999"...

    Thank you and best regards,

    Afzal.

    then try to do this:

    Select employee_number

    of per_all_people_f

    where employee_number not like 'P-% '.

    and translate(employee_number,'x0123456789','x') is not null;

    to find out what other non-digital employee_numbers you next to the P - prefix ones.

    HTH

  • What is the best way to optimize a SQL query: call a function or doing a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?

    It depends on.  Could be a.  Could be the other.  Could be no difference.  You would need to compare with your tables in your environment with your settings.

    If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective.  In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.

    Justin

  • PL/SQL function body return query sql, no problem found data

    Hi all
    We are trying to build a dynamic report based on the selection of the item by the user. We use the SQL query (body of function from PL/SQL returning SQL query). However when a user change the item and submit the page. The following error is displayed.
    ORA-01403: no data is found.

    our request is simple
    declare
    l_query varchar2 (30000) default 'select id from chw.
    Start
    if(:P11_PARA=1) then
    l_query: = "select name from chw.
    end if;
    Return l_query;
    end;

    any quick help please.

    Hello

    I managed to recreate the error

    To remove the error to change the area and choose "use generic Column Names (analysis of query runtime only).

    Concerning

    Paul

  • Validation of a region defined as a QUERY SQL type (updated report)

    Hello

    I am trying to perform validation on a region defined as type of QUERY SQL (editable report). The report has two columns.
    One of the columns is a Select list and I want to make sure that the user can select the same value twice
    in the report. For example, if the selection list has 5 values A, B, C, D, E, I don't want a user to be able to select
    B twice in the report. Will it use javascript to perform validation? If Yes, could someone provide some guidance on
    where to embed the javascript? Are there other alternatives than javascript? I create an element that came from a sql query
    counts the number of lines where the value of the column is the same. I then used the item in my validation logic. The problem with this logic
    is that a user can enter the same value and it is not until the 3rd attempt to select the same value that the validation works using the number of lines which is why I think that I need to somehow capture the value of the selection list when a user selects and then compare it to what is already in the database column Select.

    I hope that my question and explanations are clear.

    Thanks in advance for your help,

    Michael

    Hello

    This can be managed using javascript or a validation of the page. Here is an example of use of javascript: [http://htmldb.oracle.com/pls/otn/f?p=267:7]

    To do this, I have:

    1 - a model of button which does not send the page but just runs javascript. The model will depend on your theme, but should include:

    <a href="#BUTTON_ATTRIBUTES#">#LABEL#</a>
    

    If #BUTTON_ATTRIBUTES # appears on the template, delete it as we need it only once. You must create a new button model based on a copy of your existing across models, shared components. Normally, he would show href = "" #LINK # "-we do not want that this would become doSubmit('buttonname')." If your model does not use tags for buttons, you might need to create one from scratch.

    2 - I have updated the button on my page to use this template and then assign the setting button attributes:

    javascript:check();
    

    3. in the header of the HTML page, I added:

    <script type="text/javascript">
    function check()
    {
     var e = 0;
     var f = document.getElementsByName("f02");
     var k1;
     var k2;
     var v1;
     var v2;
     if (f)
     {
      for (k1 = 0; k1 < (f.length - 1); k1++)
      {
       v1 = f[k1].value;
       for (k2 = (k1 + 1); k2 < f.length; k2++)
       {
        v2 = f[k2].value;
        if (v1 == v2)
        {
         e = 1;
        }
       }
      }
     }
     if (e > 0)
     {
      alert("Duplicates found!");
     }
     else
     {
      doSubmit("SUBMIT");
     }
    }
    </script>
    

    In this example, SUBMIT is the name of the button and "f02" is the name attribute of the select list items that we want to check - change these needs by your page.

    Now, when the Submit button is clicked, instead of directly submit the page, the javascript function is called. This function loops through each selection list and gets its value. Then, he compared it to the remaining items. If there is a match, the e flag is set to 1. After all the items have been verified, if e is not 0, then a message appears. Otherwise, the page is sent.

    Andy

  • Please, help me to query SQL Construct.


    Hi Experts,

    Could you please help me to query SQL Construct.  Please find the details

    HOSTNAME HOSTTYPE DEM R1 R2
    RS123 P ABC 24.5 265,5

    RS123 P CYC 24.5 265,5

    RS123 P ADDS 24.5 265,5

    RS123 P ADE 24.5 265,5

    RS123 P SRC 24.5 265,5

    EXPECTED RESULTS

    HOSTNAME      HOSTTYPE                              MNE                                                                      R1          R2
    RS123 P ABC, CYC, ADD, ADE, CBC 24.5 265,5

    Concerning

    See you soon

    with t as)

    Select "RS123' hostname 'P' hosttype, 'ABC' dem, 24.5 r1, r2 265,5 Union double all the

    Select 'RS123', 'P', "CYC", 24.5, 265,5 double Union all

    Select 'RS123', 'P', 'ADD', 24.5, 265,5 double Union all

    Select "RS123', 'P', 'ADE', 24.5, 265,5 double Union all

    Select 'RS123', 'P', 'SRC', 24.5, 265,5 double

    )

    Select the host name,

    HostType,

    RTrim (XMLAGG (XmlElement(e,MNE,','). (Extract ('//Text ()')), ',') DEM,.

    R1,

    R2

    t

    Group hostname,

    HostType,

    R1,

    R2

    /

    HOSTN H DEM R1 R2
    ----- - -------------------- ---------- ----------
    RS123 P ABC, CBC, ADE, ADD, CYC 24.5 265,5

    SQL >

    SY.

  • How to configure the settings of sql stored function

    Hello

    I use jdeveloper 11.1.2.3.0

    I have the below sql stored function
    function get_data(p_id     in number,
                      p_date   in date,
                      p_msg    out varchar) return number is
     .......
    
    end get_data;
    I would like to know how exactlly I should call this function of my AppModuleImpl.
    I tried several ways to set the parameters, but I'm getting java.sql.SQLException: Error invalid column index.

    Could you give me the correct code for this case?

    Thank you very much!

    check the docs [url http://docs.oracle.com/cd/E16162_01/web.1112/e16182/bcadvgen.htm#insertedID6] calling stored procedures and functions

  • Create a simple query (SQL)

    Hi experts,

    I have a table with data as follows:

    Database version: 10.2.0.4
    Table name: TRANSACTION_HIST_TAB
    TRANS_ID      LOT_NO    PART_NO    QTY    TRANSACTION         LOCATION_NO    ROWVERSION
    ---------     -------   --------   ----   -----------------   ------------   ----------------------
    T00000X1      L001     ABC         10     CHANGE LOCATION     WRH_1          01/01/13 08:00:00 AM
    T00000X2      L001     ABC        10     CHANGE LOCATION     WRH_2          01/02/13 10:00:00 AM
    T00000X3      L002     XYZ        20     CHANGE LOCATION     WRH_3          01/03/13 11:00:00 AM
    and I want to create a single query (SQL) which can get data grouped by LOT_NO and only the first transaction by LOT_NO

    Expected results:
    TRANS_ID      LOT_NO    PART_NO    QTY    TRANSACTION         LOCATION_NO    ROWVERSION
    ---------     -------   --------   ----   -----------------   ------------   ----------------------
    T00000X1      L001     ABC         10     CHANGE LOCATION     WRH_1          01/01/13 08:00:00 AM
    T00000X3      L002     XYZ        20     CHANGE LOCATION     WRH_3          01/03/13 11:00:00 AM
    Someone has an idea?

    Kind regards

    Rob

    Hi, Rob.

    Here's one way:

    WITH     got_r_num     AS
    (
         SELECT     t.*     -- or list columns you want
         ,     ROW_NUMBER () OVER ( PARTITION BY  lot_no
                                   ORDER BY          rowversion
                           )  AS r_num
         FROM    transaction_hist_tab  t
    )
    SELECT       *     -- or list all columns except r_num
    FROM       got_r_num
    WHERE       r_num     = 1
    ;
    

    Depending on your data and your needs, match Sub like Manik suggested, might work. I think that you want to GROUP BY lot_no only, no transid.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • query sql delicate... date of the created object.

    friends...
    I am trying to solve this query sql delicate for some time, but unable to progress when it comes to this day...

    Q.
    Query dba_objects and list all tables created yesterday ' sysdate - 1' and in another column of the list all the tables created ' sysdate - 7'.

    -query below gives me to yesterday, but don't know how to have 'Last_week' column filled... maybe I join?
    select owner, object_name, to_char(created, 'MM-DD-YYYY HH24:MI:SS') "Yesterday", to_char(created, 'MM-DD-YYYY HH24:MI:SS') "Last_Week"
    from dba_objects
    where object_type = 'TABLE'
    and created >=trunc(sysdate - 1)
    and created < trunc(sysdate)
    appreciate your time and effort in looking at this...

    Thank you

    Published by: khallas301 on March 19, 2013 09:27
    typo edited... Thanks to frank

    khallas301 wrote:
    Query dba_objects and list all tables created yesterday ' sysdate - 1' and in another column of the list all the tables created ' sysdate - 7'.

    Well, sysdate - 7 ways months ago, not last week. If this is what you want, then:

    select  owner,
            object_name,
            case
              when trunc(created) = trunc(sysdate - 1) then to_char(created,'MM-DD-YYYY HH24:MI:SS')
            end "Yesterday",
            case
              when trunc(created) = trunc(sysdate - 7) then to_char(created, 'MM-DD-YYYY HH24:MI:SS')
            end "Week Ago"
      from  dba_objects
      where object_type = 'TABLE'
        and (
                trunc(created) = trunc(sysdate - 1)
             or
                trunc(created) = trunc(sysdate - 7)
            )
    /
    

    SY.

  • query not given function function index in oracle 11g

    I have a query that uses function based indexes when run in oracle 9i, but when I run the same query
    without any change, it does not consider the index. This is the query:

    SELECT distinct patient_role.domain_key, patient_role.patient_role_key,
    patient_role.emergency_contact_name,
    patient_role.emergency_contact_phone, patient_role.emergency_contact_note,
    patient_role.emergency_contact_relation_id,
    patient_role.financial_class_desc_id, no_known_allergies, patient_role. CREATED_BY,
    patient_role. CREATED_TIMESTAMP,
    patient_role. CREATED_TIMESTAMP_TZ, patient_role. UPDATED_BY, patient_role. UPDATED_TIMESTAMP,
    patient_role. UPDATED_TIMESTAMP_TZ,
    patient_role.discontinued_date
    MEETING, patient_role
    WHERE patient_role.patient_role_key = encounter.patient_role_key
    AND SUPERIOR (TRIM (main: encounter.account_number SYS_B_0)) = UPPER (TRIM (main: SYS_B_1 of))
    ((: SYS_B_2))
    AND patient_role.discontinued_date IS null
    AND encounter.discontinued_date IS null;

    Definition of the index:

    CREATE INDEX "user1". "' IX_TRIM_ACCOUNT_NUMBER ' ON 'user1 '. MEETING"(AT THE TOP (TRIM (LEADING))
    ('0' TO 'ACCOUNT_NUMBER')), 'PATIENT_ROLE_KEY', 'DOMAIN_KEY', 'DISCONTINUED_DATE')
    PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    DEFAULT USER_TABLES)
    TABLESPACE "user1".

    Database: Oracle 11g (11.2.0.3)
    O / s: 64-bit Linux (the query does not consider the index even on the windows operating system)

    Any suggestions?

    -Onkar

    Published by: onkar.nath on July 2, 2012 15:32

    Onkar,

    I don't appreciate posting you this issue in several forums at the same time.
    If I know you also posted this on Asktom, I wouldn't even bother.
    As for your "problem":
    First of all: some kind cursor_sharing MUST have been implemented. Oracle is a predictable system, not a fruitmachine.
    Anyway, your statement that '0' is replaced by a variable binding is simply false. If you really believe this isn't fake, SUBMIT an SR.

    But your real problem isn't Oracle: it is your 'application', which is a mess anyway. Allowing for alphanumeric numbers is a very bad idea.
    Now, you already put workaround on workaround on workaround on workaround.
    Question is this: it is terminal, and you must either to kill him or to replace it.

    -------------
    Sybrand Bakker
    Senior Oracle DBA

  • SQL Group function

    --General Employee table
    -- Version:  oracle 11g Rel 2
    
    create table employee (ID varchar2(100),first_name varcha2(200),last_name varchar2(200),start_date date,end_date date,city varchar2(100))
    
    select listagg(First_name,',') within group (order by first_name) from employee  group by city ;
    op:
    1. XXX,YYy,ZZZ
    2. AAA,SSS
    
    Excepted OP:
    
    1. 1.XXX,2.YYY,3.ZZZ
    2. 1.AAA,2.SSS
    Need a query sql for obtaining the planned op, please notify

    Thanks in advance
    Carole Kumar

    Edited by: 876377 may 1, 2012 22:04

    876377 wrote:

    --General Employee table
    -- Version:  oracle 11g Rel 2
    
    select listagg(First_name,',') within group (order by first_name) from employee;
    op:
    1. XXX,YYy,ZZZ
    2. AAA,SSS
    
    Excepted OP:
    
    1. 1.XXX,2.YYY,3.ZZZ
    2. 1.AAA,2.SSS
    

    Need a query sql for obtaining the planned op, please notify

    Thanks in advance
    Carole Kumar

    Try to use

    row_number over (partition by ID_COLUMN order by first_name) as RN
    

    And then

    listagg( rn || first_name)
    

    Since you don't validate your description of table we do not know what are the columns, etc... I guessed that the ID column is named ID_COLUMN, adjust accordingly.

  • Query SQL Report with condition (multiple settings) at the point of the apex?

    Hi all

    I have a small problem and cannot find a solution.

    I need to create reports based on a query, SQL or I.R. Nothing hard here.
    I need to add the WHERE clause dynamically with javascript to an element of the Apex.
    Even once is not very difficult. I set the agenda of the Summit, put my query like this "SELECT * FROM MYTAB WHERE COL1 =: P1_SEARCH" then I call the page by setting the P1_SEARCH value. For example, COL1 is rowid. It works very well.

    But here's my problem. Consider that P1_SEARCH contains several ROWID, and I don't know the number of these values,
    (no I don't create a large number of items and create a query with so much GOLD!), I would sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (: P1_SEARCH) with something like: ROWID1, ROWID2 in P1_SEARCH."

    I also tried: 'ROWID1, ROWID2' and 'ROWID1', 'ROWID2 '.
    but I can't get anything else than the mistake of filter. It works with a value, but as soon as there are two values or more, it seems that the Apex is unable to read the string.


    How can I do it please?

    Thanks for your help.

    Max

    mnoscars wrote:

    But here's my problem. Consider that P1_SEARCH contains several ROWID, and I don't know the number of these values,
    (no I don't create a large number of items and create a query with so much GOLD!), I would sotheming like "SELECT * FROM MYTAB WHERE ROWID IN (: P1_SEARCH) with something like: ROWID1, ROWID2 in P1_SEARCH."

    I also tried: 'ROWID1, ROWID2' and 'ROWID1', 'ROWID2 '.
    but I can't get anything else than the mistake of filter. It works with a value, but as soon as there are two values or more, it seems that the Apex is unable to read the string.

    For a standard report, see + {message identifier: = 9609120} +.

    For an IR - and improve safety by avoiding the risk of SQL Injection, use a collection containing the values in a column instead of a CSV list:
    {code}
    SELECT * FROM MYTAB WHERE ROWID IN (SELECT c001 FROM apex_collections WHERE collection_name = "P1_SEARCH")
    {code}
    (Please close duplicate threads spawned by your original question.)

  • Logical operations in SQL decode function?

    Hello
    Is it possible to perform logical operations in SQL decode function

    as
    ' > '
    ' < '
    ' > ='
    ' < ='
    '<>'.
    not in
    in
    non-null
    a null value

    for example...

    Select col1, order_by, decode (col1, > 10, 0, 1)
    tab;

    Select col1, order_by, decode (col1, <>0, 10, 1)
    tab;

    Select col1, order_by, decode (col1, not in (10,11,12), 0, 1)
    tab;

    Select col1, order_by, decode (col1, is set to null, 0, 1).
    tab;




    Kind regards

    infantry

    Published by: user780731 on April 30, 2009 12:07 AM

    Published by: user780731 on April 30, 2009 12:07 AM

    Published by: user780731 on April 30, 2009 12:08 AM

    Published by: user780731 on April 30, 2009 12:08 AM

    Published by: user780731 on April 30, 2009 12:09 AM

    example:

    select col1 ,order_by,case when col1 > 10 then 0 else 1 end
    from tab;
    
    select col1 ,order_by,case when col1 <> 10 then 0 else 1 end
    from tab;
    
    select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
    from tab;
    

    Regarding testing for null, decode the handles which, by default, anyway, so that you can get decode or case easily...

    select col1 ,order_by,decode (col1, null , 0 , 1)
    from tab;
    
    select col1 ,order_by,case when col1 is null then 0 else 1 end
    from tab;
    
  • Need help with query SQL Inline views + Group

    Hello gurus,

    I would really appreciate your time and effort on this application. I have the following data set.

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
    1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19

    Please ignore '-' added for clarity

    I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.

    The query should return the following data set

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
    Here's my query. I'm a little lost.

    Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    de)
    Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
    of the INVOICE
    Sequence_id group check_date, check_number, invoice_number, vendor_number
    ) A, B OF INVOICE
    where A.sequence_id = B.sequence_id


    Thank you
    Nick

    It seems that this is a duplicate thread - correct me if I am wrong in this case->

    Need help with query SQL Inline views + Group

    Kind regards.

    LOULOU.

  • Use of the function of group in orcl:query sql - database - urgent

    All,

    Version: 10.1.3.4
    Two requirements for me:
    1. I want to use the sum function in orcl:query - database. How to use it?

    For ex: I tried the following

    < xsl: value-of select ='orcl:query - database ("select sum of emp", false (), false (), "jdbc/DB1")'/ >
    I got the following error
    oracle.xml.sql.OracleXMLSQLException: character ')' is not allowed in an XML tag name.
    When I tried without the sum function, it works fine
    2. I used the same table, but without the sum works as below

    < xsl: value-of select ='orcl:query - database ("select emp salary", false (), false (), "jdbc/DB1")'/ >
    This time, it returns the first salary employees! I don't understand this logic. I expected, either the query returns all rows, otherwise it throws the error, but none of them were real!

    Can pls someone explain what behavior? I want your answer to both queries!

    I am currently in a project where I work in the same scenario, so guru of let me know as soon as POSSIBLE.

    Thank you
    Sen

    Hello

    have you tried to put an alias something like select Sum Total emp

Maybe you are looking for