Oracle 9i function to perform data manipulation

Hi everyone,
I have two scenarios. I would like to write one Oracle 9i function that can accommodate both these scenarios, using PL/SQL developer. I intend passing a varchar2 parameter to this function. Within the function, I perform a select on a table and see if this value sent has a parent record.
If it does not have a parent record (null or blank) then I take this value, join with another table, perform some processing and return one varchar2 value.
If it has a parent record (not null or not blank) then I need to retrieve all the other children records associated with this same parent record, take this value, join with another table,perform some processing and return one varchar2 value.
I have two simple queries that I wrote: one for record with null/blank parent, and the other for record with same parent and other children. These two queries work individually, when I combine them is where I run into problems. Sample table:
TABLE XYZ data: (note: if there is a parent, parent shows up in both parent and child field in the table)
child parent
1234
5107 3167
6259 3652
5678 9754
3167 3167
3652 3652
1649
2306 9754
4657 3652
9754 9754
8753 3652
passing record 1234 into the function.
SELECT A.child, A.parent, C.field1
FROM OTHERTABLE C,
(SELECT TableA.child, TableA.parent
FROM XYZ TableA
WHERE TableA.child ='1234')A
WHERE A.child = C.field2
----(output of this query is 1 record with 3 fields 1234 and null/blank and 987654321. I place this output into a cursor and then take 987654321 and place into a variable and return this value)
passing record 4657 into the function
SELECT c.CHILDfield, c.PARENTfield, TableOther.field1
FROM OTHERTABLE TableOther,(
(SELECT B.CHILDfield, B.PARENTfield FROM
(SELECT A.PARENTfield, i.CHILDfield FROM TableB,
(SELECT TableA.CHILDfield, TableA.PARENTfield
FROM XYZ TableA
WHERE TableA.CHILDfield ('4657' ))A
-- pass 4657 and then get the parent
WHERE A.PARENTfield = TableB.PARENTfield)B
-- gets associated children with the parent from previous query.
-- note: parent can exist in the parent and child fields
WHERE B.CHILDfield <> B.PARENTfield))C
--strips off the parent and gets child/children only as I don't need
--the parent when it is also a child
WHERE C.CHILDfield = TableOther.field1
--(output of this query is 3 records
4657 3652 912345671
6259 3652 945362798
8753 3652 934274857)
I place this output into a cursor and then have a CASE statement that goes thru each record, and appends the third value into a variable, the ultimate return value of this will be as follows:
912345671;945362798;934274857)
The dilemma is writing a generic query to accommodate both these situations. My current function can handle each of these situations individually, but not both. For testing purposes, I change the select statement depending on whether I have a record that has a parent on not!
Any help is greatly appreciated.

You want one function to handle two cases? This is the best opportunity to use the IF STATEMENT.
FUNCTION MyFunc (p_input IN VARCHAR2) RETURN VARCHAR2 IS
ReturnValue VARCHAR2;
BEGIN
IF <blank or null test> THEN
SELECT ... -- Blank or null select statement
... -- Blank or null data processing
RETURN ReturnValue;
ELSE
SELECT ... -- Other select statement
... -- Other data processing
RETURN ReturnValue;
END IF;
END MyFunc;

Similar Messages

  • Data Manipulation using Cubes

    Dear Experts
    My question: are BI cubes all about quering and reports? can perform data manipulation process, e.g. payroll, to the cube OLAP database directly, something like stored procedures in ordinary relational databases?????
    thanks in advance

    Hi Khidir,
    According to your description, you want to know if we can manipulation data in SQL Server Analysis Services database, right.
    As Reeves said, SSAS provide Writeback feature which is used for budgeting, forecasting or any other scenario in which you need enter data into your structure. Please refer to the link below to wee how to enable/disable writeback feature for a cube.
    http://msdn.microsoft.com/en-us/library/ms178845.aspx
    However, OLAP designed for storing and retrieving large amounts of data to be used for ad-hoc reporting and analytics. And helps users to make more informed business decisions by enabling them to analyze information accumulated during a company’s day to
    day operations.
    http://www.informit.com/articles/article.aspx?p=1313996
    http://www.nenit.net/pages/ssas.aspx
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Oracle sql function to find VARCHAR2 data is numeric

    Hi Everyone,
    Is there oracle sql function to find whether the VARCHAR2 data is numeric?
    Thanks

    hi,
    see the below example .
    with t as
    (select '12'  as col from dual union all
    select '1 2'  as col from dual union all
    select '2 1 3'  as col from dual union all
    select 'abcde'  as col from dual union all
    select '12345'  as col from dual union all
    select '1a4A5'  as col from dual union all
    select '12a45'  as col from dual union all
    select '12aBC'  as col from dual union all
    select '12abc'  as col from dual union all
    select '12ab5'  as col from dual union all
    select '12aa5'  as col from dual union all
    select '12AB5'  as col from dual union all
    select 'ABCDE'  as col from dual union all
    select '123-5'  as col from dual union all
    select '12.45'  as col from dual union all
    select '1a4b5'  as col from dual union all
    select '1 3 5'  as col from dual union all
    select '1  45'  as col from dual union all
    select '1   5'  as col from dual union all
    select 'a  b  c  d'  as col from dual union all
    select 'a b  c   d    e'  as col from dual union all
    select 'a              e'  as col from dual union all
    select 'Steven'  as col from dual union all
    select 'Stephen'  as col from dual union all
    select '111.222.3333'  as col from dual union all
    select '222.333.4444'  as col from dual union all
    select '333.444.5555'  as col from dual union all
    select 'abcdefabcdefabcxyz'  as col from dual union all
    select 'aaa'  as col from dual union all
    select 'ddd'  as col from dual union all
    select 'ccc'  as col from dual union all
    select 'aaaaa'  as col from dual union all
    select 'aaaaaaaa'  as col from dual
    select * from t where regexp_like(col,'[1-9]')
    Result
    COL
    12
    1 2
    2 1 3
    12345
    1a4A5
    12a45
    12aBC
    12abc
    12ab5
    12aa5
    12AB5
    123-5
    12.45
    1a4b5
    1 3 5
    1  45
    1   5
    111.222.3333
    222.333.4444
    333.444.5555Thanks,
    P Prakash

  • SQL User Defined Functions for performing statistical calculations

    Hi!
       I hope you can help.  I just wasn’t sure where to go with this question, so I’m hoping you can at least point me in the right direction.
       I’m writing a SQL Server stored procedure that returns information for a facility-wide scorecard-type report.  The row and columns are going to be displayed in a SQL Server Reporting Services report. 
       Each row of information contains “Current Month” and “Previous Month” numbers and a variance column.  Some rows may compare percentages, others whole numbers, others ratios, depending on the metric they’re measuring.  For each row/metric the company has specified whether they want to see a t-test or a chi-squared statistical test to determine whether or not there was a statistically significant difference between the current month and the previous month. 
       My question is this:  Do you know where I can find a set of already-written user defined functions to perform statistical calculations beyond the basic ones provided in SQL Server 2005?  I’m not using Analysis Services, so what I’m looking for are real SQL User Defined Functions where I can just pass my data to the function and have it return the result within a stored procedure. 
       I’m aware that there may be some third-party statistical packages out there we could purchase, but that’s not what I’m looking for.   And I’m not able to do anything like call Excel’s analysis pack functions from within my stored procedure.   I’ve asked.   They won’t let me do that.   I just need to perform the calculation within the stored procedure and return the result.
       Any suggestions?  Is there a site where people are posting their SQL Server UDF’s to perform statistical functions?  Or are you perhaps aware of something like a free add-in for SQL that will add statistical functions to those available in SQL?   I just don’t want to have to write my own t-test function or my own chi-squared function if someone has already done it.
     Thanks for your help in advance!  Oh, and please let me know if this should have been posted in the TSQL forum instead.  I wasn't entirely sure.
    Karen Grube

    STATS_T_TEST_
    docs.oracle.com/cd/B19306_01/server.102/b14200/functions157.htm 
    STATS_T_TEST_ONE: A one-sample t-test
    STATS_T_TEST_PAIRED: A two-sample, paired t-test (also known as a crossed t-test)
    STATS_T_TEST_INDEP: A t-test of two independent groups with the same variance (pooled variances)
    STATS_T_TEST_INDEPU: A t-test of two independent groups with unequal variance (unpooled variances)

  • Oracle Legacy System to SAP Data Migration

    Hi Experts,
    New to data migration:
    Can you guide me in how oracle staging is useful for data migration:
    Here is my few doubts:
    1. What is Oracle Staging?
    2. How Oracle staging is useful for data migration?
    3. I see few ETL tools for data migration such as Informatica, Ascential Datastage etc. but our requirement is how can we use oracle staging for data migration?
    4. What are the benefits in using oracle staging for data migration?
    Expecting your response of above queries.
    Thanks,
    --Kishore                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Here is my few doubts:
    1. What is Oracle Staging?It is where ODI creates temporary tables. It does the transformation and if required cleans the data aswell.
    2. How Oracle staging is useful for data migration?ODI loads source data into temporary tables(staging) and applying all the required mappings, staging filters, joins and constraints. The staging area is a separate area in the RDBMS (a user/database) where Oracle Data Integrator creates its temporary objects and executes some of the rules (mapping, joins, final filters, aggregations etc.). When performing the operations this way, Oracle Data Integrator behaves like an E-LT as it first extracts and loads the temporary tables and then finishes the transformations in the target RDBMS.
    3. I see few ETL tools for data migration such as Informatica, Ascential Datastage etc. but our requirement is how can we use oracle staging for data migration?
    4. What are the benefits in using oracle staging for data migration?You can refer https://blogs.oracle.com/dataintegration/entry/designing_and_loading_your_own
    http://docs.oracle.com/cd/E21764_01/integrate.1111/e12643/intro.htm#autoId10
    Expecting your response of above queries.
    Thanks,
    --Kishore                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Frm-40505:ORACLE error: unable to perform query in oracle forms 10g

    Hi,
    I get error frm-40505:ORACLE error: unable to perform query on oracle form in 10g environment, but the same form works properly in 6i.
    Please let me know what do i need to do to correct this problem.
    Regards,
    Priya

    Hi everyone,
    I have block created on view V_LE_USID_1L (which gives the error frm-40505) . We don't need any updation on this block, so the property 'updateallowed' is set to 'NO'.
    To fix this error I modified 'Keymode' property, set it to 'updatable' from 'automatic'. This change solved the problem with frm-40505 but it leads one more problem.
    The datablock v_le_usid_1l allows user to enter the text (i.e. updated the field), when the data is saved, no message is shown. When the data is refreshed on the screen, the change done previously on the block will not be seen (this is because the block updateallowed is set to NO), how do we stop the fields of the block being editable?
    We don't want to go ahead with this solution as, we might find several similar screens nad its diff to modify each one of them individually. When they work properly in 6i, what it doesn't in 10g? does it require any registry setting?
    Regards,
    Priya

  • Oracle Spatial functionality with WFS

    Hi all
    My first post here so be gentle on me ;-)
    This may be an obvious question but here goes ...
    When using a WFS client can you access the full SDO_... SQL functions within Oracle Spatial? I've had a read of the WFS spec and it is all a bit vague on how the queries get passed through to the data store.
    Also with the WFS locking, is this done at the web server level? If so how would that impact on any direct access to the database? A bit dangerous??
    Appreciate any advice on WFS implemtations with a 9i back end. I want to retain the full native Oracle functionality and still deploy via WFS ... a pipe dream??
    Thanks
    Richard

    Thanks for your response Andreas
    Sorry, perhaps I wasn't clear, I realise the WFS client will never directly access the data source, that it is the WFS server that makes the request to the data store, not the client, but can the call be passed through to Oracle as native SQL?
    I think I found the answer in the OGC Filter Encoding Imp Spec where it desribes in great detail the optional filter component of a WFS request. It desribes the CQL filter operators that include some spatial operators. These could, I understand, be translated from CGL and Feature based schema to SQL (in GML?) and relational based schema.
    While I don't think at first glance that the spatial operators in CQL match all the Oracle SDO_ functions they probably go far enough for most normal users.
    Am I on the right track?
    Does anyone know of any work that has been done in this filter translation to SQL and if it has been implemented successfully anywhere.
    I think the locks would still pose a problem, but that's for another day :-)
    Thanks
    Richard

  • Using Oracle BI Server as a Data Source for Third Party Tools

    I have been researching how to use the Oracle BI Server as a data source for two days now. I have not yet found a solution to my problem.
    We have a remote user who is pulling data from one of our Oracle databases using automated tools. This data base is essentially being replaced by Oracle Analytics. However, we do not want this user to get at the physical tables of Analytics, rather, we want the user to be able to connect to the Oracle BI Server itself, and issue Logical SQL to pull data.
    Here are the requirements which I need to be fulfilled:
    1) The ability for a remote user to connect to the BI Server as a data source.
    2) The remote user must be able to do this on a Unix box.
    3) The remote user must be able to automate the process of issuing SQL to the BI Server. (Command line interface is preferable)
    4) The solution needs to be easily implementable, that is, this solution will be implemented many times over.
    I found many articles explaining how to set up a Windows box to connect to the BI Server in this way. However, these articles outline how to use tools like Excel and Microsoft Query to pull data from the BI Server. Our current user is using SQLplus.
    If possible, I would like the user to continue using SQLplus as the tool for connecting to and retriving information from our BI Server. I have tested using SQLplus many different ways to no avail. I have also tried using other tools, such as Oracle SQL Developer.
    Is there a program out there that will fulfill the needs I have outlined above? Or, does someone know of a way to use SQLplus to connect to the Oracle BI Server as a data source? Or, is there a series of solutions which will fulfill the needs outlined above?
    Edited by: user11177366 on Jun 11, 2009 11:46 AM

    I agree it would be inefficient but only because you are using OBIEE for something it was not designed to do. You are basically asking for a "DB feed" and that should designed using PL/SQL, DB Links, Web Services or whatever is your entreprise standard to send data from one system to another. Using OBIEE for this seems a bad architecture decision to me.You are correct, the BI Server is not really intended to be queried like another Oracle Database remotely. However, the reason we are trying to do it this way is twofold:
    1) We want to enforce data level security.
    2) The BI Server has been fine tuned for high performance.
    Forcing the end users to go through the BI Server rather than directly to the physical tables or other sorts of systems built on top solves both of these issues.
    I think you are wrong. I don't see why SQLPlus should be able to query the BI Server. The BI Server can sit on top of many different DBs not just Oracle, even flat files etc. So you can't really expect the BI Server to able to translate all that into Oracle SQL output so you can query it using SQLPlus. The BI Server is not an Oracle RDBMS.You're right again. The BI Server isn't an Oracle RDBMS, and I have been wanting to treat it like one. From the data I have gathered SQLPlus can't query the BI Server.
    However, my research has led me to realize that the BI Server supports the JDBC API. Therefore, (I should have went down this route in the first place) one can use the JDBC driver provided by Oracle (bijdbc14.jar) to interface with the BI Server. There are many programs and applications out there that support the JDBC API and let us connect to BI Server the way we want to. Furthermore, these programs are mostly platform independent, as they are mostly written in Java.
    Lastly, from what I understand the NQCMD program can be installed on any platform as well (provided by Oracle). This is another option to connect to the BI Server as well.
    Thanks for your help and your comments as I went through this process of discovery.

  • How to Oracle Database Function in OBIEE Administration Tool

    Hi All,
    I want to use a Oracle Database Function in as a column in OBIEE (BM, Presentation Model). Can anybody has done this inOBIEE. Any pointers to this is much appreicated.
    Thanks,

    Hi user7417334,
    You cannot use any formulas in the presentation layer (not that I know of). But you can definitely use oracle database functions in the BMM layer.
    You want to use the EVALUATE function. It works like this:
    e.x. EVALUATE( 'TO_DATE(%1,%2)' AS DATE, '12/31/2009', 'MM/DD/YYYY')
    Generic Version: EVALUATE( '<FUNC>' AS <DATATYPE>, VALUE1,VALUE2,etc)
    FUNC) Is the syntax for the function you are calling. Any parameters have to be replaced by %<number>, where number refers to the order in which you specify your parameters.
    DATATYPE) The datatype that the function will evaluate to. In this case, DATE.
    VALUE1) The latter part of the formula is a comma separated list of all the parameters used in the function. In this case, it's the date I want to cast
    VALUE2) This is the second parameter. You need as many as you referenced in your function. In this case, it's the date format.
    Good luck and if you found this post useful, please award points!
    best regards,
    -Joe

  • Function Modules for Date

    Hi ALL,
    I would like to know the various function modules that can be used for calculating dates.Like first day of month,last day.....etc etc.
    Please give me a list of the FM's and not the F4 help option info.
    Cheers

    Hi ,
    Here are a few FM used for date manipulation
    <b>DATE_IN_FUTURE  </b>                   Add / Substract days from a given date
    <b>HR_SGPBS_ADD_TIME_TO_DATE</b>     Find the next date based on input date , addition / sub and month , year ,date
    <b>CONVERT_DATE_TO_EXTERNAL</b>     Convert date to External format
    <b>SG_PS_ADD_MONTH_TO_DATE</b>     Find the next date based on input date , addition / sub and month , year ,date
    <b>DATE_COMPUTE_DATE</b>     For a input date gives the day of the week
    <b>DATE_GET_WEEK</b>For an input date ,gives the week as output
    <b>WEEK_GET_FIRST_DAY</b>     Input year and week output is the first day of the week
    <b>WEEKDAY_GET</b>     Gives the day range , Monday , Tuesday ,…..
    <b>RP_CALC_DATE_IN_INTERVAL</b>     Calculate Future Date
    <b>CALCULATE_DATE</b>     Calculate Future Date
    <b>FIMA_DAYS_AND_MONTHS_AND_YEARS</b>     Difference between two dates
    <b>CONVERSION_EXIT_PDATE_INPUT</b>     It checks if the date is in future , if yes an error is displayed
    Reagrds
    Arun

  • Oracle Asset (Functional) Practichttps:/e Questions for Interviews and Exam

    https://www.createspace.com/3495382
    http://www.amazon.com/Functional-Questions-Interviews-Certification-Examination/dp/1456311581/ref=sr_1_4?ie=UTF8&s=books&qid=1289178586&sr=8-4
    List Price: $29.99
    Add to Cart
    Oracle Asset (Functional) Practice Questions for Interviews and Certification Examination (Release 11i and 12)
    Functional Consultant
    Authored by Erp Gold
    This book contains 150 Oracle Asset Practice Questions for functional consultants. Very useful for interviews and certification examinations.
    Publication Date:
    Oct 26 2010
    ISBN/EAN13:
    1456311581 / 9781456311582
    Page Count:
    94
    Binding Type:
    US Trade Paper
    Trim Size:
    6" x 9"
    Language:
    English
    Color:
    Black and White
    Related Categories:
    Computers / General

    Reported as spam!

  • Oracle Asset (Functional) Practice Questions for Interviews and Exam

    https://www.createspace.com/3495382
    http://www.amazon.com/Functional-Questions-Interviews-Certification-Examination/dp/1456311581/ref=sr_1_4?ie=UTF8&s=books&qid=1289178586&sr=8-4
    List Price: $29.99
    Add to Cart
    Oracle Asset (Functional) Practice Questions for Interviews and Certification Examination (Release 11i and 12)
    Functional Consultant
    Authored by Erp Gold
    This book contains 150 Oracle Asset Practice Questions for functional consultants. Very useful for interviews and certification examinations.
    Publication Date:
    Oct 26 2010
    ISBN/EAN13:
    1456311581 / 9781456311582
    Page Count:
    94
    Binding Type:
    US Trade Paper
    Trim Size:
    6" x 9"
    Language:
    English
    Color:
    Black and White
    Related Categories:
    Computers / General

    Reported as spam!

  • Oracle Asset (Functional) Practice Questions for Interviews and Certificati

    https://www.createspace.com/3495382
    List Price: $29.99
    Add to Cart
    Oracle Asset (Functional) Practice Questions for Interviews and Certification Examination (Release 11i and 12)
    Functional Consultant
    Authored by Erp Gold
    This book contains 150 Oracle Asset Practice Questions for functional consultants. Very useful for interviews and certification examinations.
    Publication Date:
    Oct 26 2010
    ISBN/EAN13:
    1456311581 / 9781456311582
    Page Count:
    94
    Binding Type:
    US Trade Paper
    Trim Size:
    6" x 9"
    Language:
    English
    Color:
    Black and White
    Related Categories:
    Computers / General

    Reported as spam!

  • Using of Oracle Text functions not working in JDev

    Hi,
    I'm confused about using Oracle Text functions in JDeveloper.
    It's not possible for me to pass the sql syntax test while creating a view object with a custom query:
    SELECT score (1) myScore,
    dokumente.titel,
    ctx_doc.snippet ('idx_dokumente_titel',
    TO_CHAR (dokumente.dkt_id),
    'searchstring'
    ) snippet
    FROM dokumente
    WHERE contains (titel, 'searchstring', 1) > 0;
    I retrieve "ORA-00911:     invalid character" for the contains-function.
    (Using this statement in sql-worksheet works.)
    Any ideas?

    Hi william,
       Yes you need code abap to maintein your data. look at <a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/2f/696d360856e808e10000009b38f839/frameset.htm">Business Data Toolset</a>, in the part of Dialog.
    Regards.
    Manuel

  • Oracle declare function in shell script

    Please tell me oracle declare function now able to run in shell script?
    I am calling in shell script like @/myscript.sql it is not working properly, reset update and other oracle command is working fine in shell script.

    I am running below code.
    #!/bin/sh
    sqlplus system/manager@prod_db <<ENDOFSQL
    update apps.fnd_concurrent_queues set node_name = 'host1', target_node ='host1' where node_name='host3';
    update apps.fnd_concurrent_queues set node_name = 'host2', target_node ='host2' where node_name='host4';
    commit;
    DECLARE
    VALUE BOOLEAN;
    l_node_id number;
    BEGIN
    select node_id into l_node_id from fnd_nodes where NODE_NAME = 'host5';
    VALUE := fnd_profile.save ('NODE_TRUST_LEVEL', 3, 'SERVER',l_node_id,null,null);
    END;
    ENDOFSQL
    Below ERROR i am getting after running above code via shell script with oracle user
    SQL>
    0 rows updated.
    SQL>
    0 rows updated.
    SQL>
    Commit complete.
    SQL> SQL> DECLARE
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 5

Maybe you are looking for

  • WebService in JDeveloper 10.1.3

    I have developed document/literal web services in JDeveloper 10.1.2 and running it on Oracle Application Server 10.1.2. In JDeveloper 10.1.3, web services is based on JAX-RPC. Can I run web services developed with a previous version work in the emebd

  • View Criteria in ADF Query Panel with Table-Class Cast Exception

    Hi, I am getting Class Cast Exception when using view criteria for ADF Query Panel with Table. The version I am using is 11g Release 1(11.1.1.2.0) Here is what I did: 1. created a view criteria on a view object 2. all are optional 3. all are Strings

  • Error on vendor open item

    Hi, One of the vendor in my company code has open item and invoice was created last month and we have closed that period. One of the user here wants to reverse the open item doc using FB08 but she is getting an error posting period not open. Could an

  • Why can't I save a home page in Yosemite?

    I have tried several times to save a home page in the preferences folder, but Yosemite reverts to its own search engine.

  • Cannot download apps from App Store using iPhone 6

    Cannot download applications from App Store using my iPhone 6, and when I made a sign out, I cannot sign in, even I asked to reset my Apple ID account by e-mail, but I did not receive any feedback by mails yet, while I can access the App Store, and d