How to return Varchar2(1) from function ?? Simple but annoying :(

Hi,
I have a function something like...
CREATE OR REPLACE FUNCTION Test ( id number) RETURN VARCHAR2 ...
Now I am using this function in a View as ...
select
test(123) as Test
In the View description, this column appears as Varchar 4000. whereas I want it as varchar2(1).
When i redefine the function return value
CREATE OR REPLACE FUNCTION Test (id1 number) RETURN VARCHAR2(1) ...
It gives error...
Please suggest.
Thanks in Advance.

SQL> CREATE OR REPLACE FUNCTION Test ( id number) RETURN VARCHAR2
  2  as
  3  begin
  4    return 'A';
  5  end;
  6  /
Functie is aangemaakt.
SQL> create view v_test as select test(123) as test from dual
  2  /
View is aangemaakt.
SQL> desc v_test
Naam                                                                      Null?    Type
TEST                                                                               VARCHAR2(4000)
SQL> create or replace view v_test as select cast(test(123) as varchar2(1)) as test from dual
  2  /
View is aangemaakt.
SQL> desc v_test
Naam                                                                      Null?    Type
TEST                                                                               VARCHAR2(1)Regards,
Rob.

Similar Messages

  • How to return a table from function

    Hi,
    I want to return a table from the function. But i'm unable to do it.
    can any one give me a peice of code.
    Thanks in advance.
    Regards,
    Alok

    Are you referring to a pipelined table function?
    Here is an example of such a function returning a "hailstone" sequence.. a number range that always end in 4,2,1. (see the [url http://en.wikipedia.org/wiki/Collatz_conjecture]Collatz Conjecture for more details on the maths used).
    SQL> create or replace type TNumbers is table of number;
    2 /
    Type created.
    SQL>
    SQL> create or replace function hailstone( nValue number ) return TNumbers pipelined is
    2 n number;
    3 begin
    4 n := nValue;
    5 loop
    6 PIPE ROW( n );
    7 exit when n = 1;
    8
    9 if MOD(n,2) != 0 then
    10 n := (n * 3) + 1;
    11 else
    12 n := n / 2;
    13
    14 end if;
    15 end loop;
    16 end;
    17 /
    Function created.
    SQL> show errors
    No errors.
    SQL>
    SQL>
    SQL> select * from TABLE( hailstone(10) );
    COLUMN_VALUE
    10
    5
    16
    8
    4
    2
    1
    7 rows selected.
    SQL> select * from TABLE( hailstone(1923413) );
    ..etc.

  • How to return more data from function

    Following is the scenario:
    CREATE OR REPLACE TYPE OBJ IS OBJECT
    TEST_ID NUMBER(9),
    TEST_DESC VARCHAR(30)
    CREATE OR REPLACE FUNCTION FN_MY_DATA
    RETURN OBJ
    AS
    OBJ1 OBJ;
    BEGIN
    OBJ1.TEST_ID := 444;
    OBJ1.TEST_DESC := 'FFF';
    RETURN OBJ;
    END;
    I WANT USED VALUE TEST_ID AND TEST_DESC THE EXISTING IN FUNCTION FN_MY_DATA WITH A VARIABLES :
    DECLARE
    X NUMBER(9);
    Y VARCHAR(30);
    BEGIN
    X := -- VALUE TEST_ID EXISTING IN FN_MY_DATA;
    Y := -- VALUE TEST_DESC EXISTING IN FN_MY_DATA;
    END;

    see can oracle  function return more than one value
    SQL> CREATE OR REPLACE TYPE OBJ IS OBJECT
      2  (
      3  TEST_ID NUMBER(9),
      4  TEST_DESC VARCHAR(30)
      5  )
      6  /
    Type created.
    SQL> create or replace
      2  FUNCTION FN_MY_DATA
      3  RETURN OBJ
      4  as
      5  --obj1 obj;
      6  begin
      7  --OBJ1.TEST_ID := 444;
      8  --obj1.test_desc := 'FFF';
      9  return obj(444,'FFF');
    10  end;
    11  /
    Function created.
    SQL> set serveroutput on
    SQL> DECLARE
      2  X NUMBER(9);
      3  y varchar(30);
      4  l OBJ;
      5  begin
      6  l := fn_my_data();
      7  dbms_output.put_line(l.test_id || ' ' || l.test_desc);
      8  END;
      9  /
    444 FFF
    PL/SQL procedure successfully completed.
    SQL>

  • [UIX] How To: Return multiple values from a LOV

    Hi gang
    I've been receiving a number of queries via email on how to return multiple items from a LOV using UIX thanks to earlier posts of mine on OTN. I'm unfortunately aware my previous posts on this are not that clear thanks to the nature of the forums Q&A type approach. So I thought I'd write one clear post, and then direct any queries to it from now on to save me time.
    Following is my solution to this problem. Please note it's just one method of many in skinning a cat. It's my understanding via chatting to Oracle employees that LOVs are to be changed in a future release of JDeveloper to be more like Oracle Forms LOVs, so my skinning skills may be rather bloody & crude very soon (already?).
    I'll base my example on the hr schema supplied with the standard RDBMS install.
    Say we have an UIX input-form screen to modify an employees record. The employees record has a department_id field and a fk to the departments table. Our requirement is to build a LOV for the department_id field such that we can link the employees record to any department_id in the database. In turn we want the department_name shown on the employees input form, so this must be returned via the LOV too.
    To meet this requirement follow these steps:
    1) In your ADF BC model project, create 2 EOs for employees and departments.
    2) Also in your model, create 2 VOs for the same EOs.
    3) Open your employees VO and create a new attribute DepartmentName. Check “selected in query”. In expressions type “(SELECT dept.department_name FROM departments dept WHERE dept.department_id = employees.department_id)”. Check Updateable “always”.
    4) Create a new empty UIX page in your ViewController project called editEmployees.uix.
    5) From the data control palette, drag and drop EmployeesView1 as an input-form. Notice that the new field DepartmentName is also included in the input-form.
    6) As the DepartmentName will be populated either from querying existing employees records, or via the LOV, disable the field as the user should not have the ability to edit it.
    7) Select the DepartmentId field and delete it. In the UI Model window delete the DepartmentId binding.
    8) From the data controls palette, drag and drop the DepartmentId field as a messageLovInput onto your page. Note in your application navigator a new UIX page lovWindow0.uix (or similar) has been created for you.
    9) While the lovWindow0.uix is still in italics (before you save it), rename the file to departmentsLov.uix.
    10) Back in your editEmployees.uix page, your messageLovInput source will look like the following:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="${bindings.DepartmentId.path}"
        destination="lovWindow0.uix"/>Change it to be:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="DepartmentId"
        destination="departmentsLov.uix"
        partialRenderMode="multiple"
        partialTargets="_uixState DepartmentName"/>11) Also change your DepartmentName source to look like the following:
    <messageTextInput
        id=”DepartmentName”
        model="${bindings.DepartmentName}"
        columns="10"
        disabled="true"/>12) Open your departmentsLov.uix page.
    13) In the data control palette, drag and drop the DepartmentId field of the DepartmentView1 as a LovTable into the Results area on your page.
    14) Notice in the UI Model window that the 3 binding controls have been created for you, an iterator, a range and a binding for DepartmentId.
    15) Right click on the DepartmentsLovUIModel node in the UI Model window, then create binding, display, and finally attribute. The attribute binding editor will pop up. In the select-an-iterator drop down select the DepartmentsView1Iterator. Now select DepartmentName in the attribute list and then the ok button.
    16) Note in the UI Model you now have a new binding called DCDefaultControl. Select this, and in the property palette change the Id to DepartmentName.
    17) View the LOV page’s source, and change the lovUpdate event as follows:
    <event name="lovSelect">
        <compound>
            <set value="${bindings.DepartmentId.inputValue}" target="${sessionScope}" property="MyAppDepartmentId" />
            <set value="${bindings.DepartmentName.inputValue}" target="${sessionScope}" property="MyAppDepartmentName" />
        </compound>
    </event>18) Return to editEmployees.uix source, and modify the lovUpdate event to look as follows:
    <event name="lovUpdate">
        <compound>
            <set value="${sessionScope.MyAppDepartmentId}" target="${bindings.DepartmentId}" property="inputValue"/>
            <set value="${sessionScope.MyAppDepartmentName}" target="${bindings.DepartmentName}" property="inputValue"/>     
        </compound>
    </event>That’s it. Now when you select a value in your LOV, it will return 2 (multiple!) values.
    A couple things to note:
    1) In the messageLovInput id field we don’t use the “.path” notation. This is mechanism for returning 1 value from the LOV and is useless for us.
    2) Again in the messageLovInput we supply “_uixState” as an entry in the partialTargets.
    3) We are relying on partial-page-refresh functionality to update multiple items on the screen.
    I’m not going to take the time out to explain these 3 points, but it’s worthwhile you learning more about them, especially the last 2, as a separate exercise.
    One other useful thing to do is, in your messageLovInput, include as a last entry in the partialTargets list “MessageBox”. In turn locate the messageBox control on your page (if any), and supply an id=”MessageBox”. This will allow the LOV to place any errors raised in the MessageBox and show them to the user.
    I hope this works for you :)
    Cheers,
    CM.

    Thanks Chris,
    It took me some time to find the information I needed, how to use return multiple values from a LOV popup window, then I found your post and all problems were solved. Its working perfectly, well, almost perfectly.
    Im always fighting with ADF-UIX, it never does the thing that I expect it to do, I guess its because I have a hard time letting go of the total control you have as a developer and let the framework take care of a few things.
    Anyway, I'm using your example to fill 5 fields at once, one of the fields being a messageChoice (a list with countries) with a LOV to a lookup table (id , country).
    I return the countryId from the popup LOV window, that works great, but it doesn't set the correct value in my messageChoice . I think its because its using the CountryId for the listbox index.
    So how can I select the correct value inside my messageChoice? Come to think of it, I dont realy think its LOV related...
    Can someone help me out out here?
    Kind regards
    Ido

  • I found how to delete a series from my ipad, but it still won't download the last episode of the new series I am trying to have.  What have I done wrong?

    I found how to delete a series from my ipad, but it still won't download the last episode of the new series I am trying to have.  What have I done wrong?

    What is the GarageBand version that your friend is using?
    If it is GarageBand '11, version 6.0.5, you can buy GarageBand '11 as a boxed retail version with the iLIfe '11 bundle, e.g. from Amazon.
    Then you can upgrade GarageBand '11 to 6.0.5, using this upgrader from the Support page:
                     GarageBand 6.0.5
    GarageBand 6.0.5 will work well with your system.  But if your friend is using the newest GarageBand 10, this will not help. Then ask your friend to send you audio files for each track, so you can recreate the project from the audio.  Or your friend could also use GarageBand '11 for the projects you want to share, that will run well in all newer MacOS X versions, even with GarageBand 10.0 installed on the same system.
    -- Leonie

  • How can I remove songs from my iphone but they still stay in my library

    I have set up my music to sync only checked items, however, all the songs are still on my iphone.  I only want certain songs on my phone, but it still shows several songs that I have not checked off.  How do I remove songs from my iphone but they still will stay in my library. 

    What you need to do is go to music, and slide your finger to the right on the song you want to remove from your device. The song will still show in the music app but will have a cloud with an arrow beside it and you would have to re-download the song to your device to be able to listen to it. And also, this will only take the song off your device and it won't be removed from your library on iTunes. I hope this helps!
    Ryan

  • How do I delete photos from camera roll but keep same photo in album

    how do I delete photos from camera roll but keep same photo in album

    You can't. The albums that you created on the iPad do not actually contain copies of the photos, but merely pointers to those photos. If you remove the photos from the camera roll, they will be removed from the iPad. Albums on the iPad are simply for your own organization on the device. Those albums cannot be imported to your computer either, since the photos do not exist in the albums.

  • How do I delete photos from my iPad but keep them on my mac?

    How do I delete photos from my iPad but keep them on my mac?

    Set iPhoto to automatically import photo stream photos to your iPhoto library:
    Once imported, deleting them from your photo stream will not delete them from your library.  If they aren't imported yet, contol-click on the photos and choose Import.

  • HT204382 i need to learn in how to down load music from u tobe.but i need to learn on how to star from the bottom.

    I need to leran in how to dawn load music from you tobe.but I need to start from the bottom can someone help?

    If there is no download button under the video you are looking at, then Youtube's terms forbid downloading someone else's property. Because they forbid it, we would be violating the terms of these forums if we were to try to help - sorry.

  • How to return custJava Object from Java Stored Function/Procedure to Java Application

    I WILL PAY $100 FOR SOLUTION.
    Oracle JDBC documentation gives step by step on how to return Oracle Type Object to Java Application. No question here.
    But is it possible to create Java Stored Function [getMyClass() ] which returns CUSTOM Java based object [MyClass] to Java application like:
    //java stored function
    class Foo
    public static MyClass getMyClass()
    return new MyClass();
    //java class I want to return to Java
    class MyClass
    public String getGreetings(String name)
    return "Hello " + name;
    I tried to do it using intermittent Oracle
    Type Object and OracleConnection map to make binding between Java->Oracle->Java. I could
    not get throgh meaningless run time ORA Errors. Any kind of help would be greatly
    appreciated. If you know the answer please
    post it or e-mail [email protected]
    null

    You don't say which version of the database you are on. There's an interesting looking article on OTN on handling CLOBs in JDBC in 10g. It may well be useful for earlier versions too (but no guarantees).
    Cheers, APC

  • How JAVA works with collection from function

    All,
    I have a DB function which returns object collection of values. Could someone please tell me how java talks with the function and get the value?
    Thanks

    This is database function. my question is how java get those values from the function.
    Could you please post some sample code also?
    CREATE OR REPLACE
    Type T_PREO_RoleINFO is Object
    ROLE_ID NUMBER(10),
    ROLE_NAME VARCHAR2(20))
    CREATE OR REPLACE
    TYPE T_RoleInfo IS TABLE OF PREORDER.
    T_PREO_RoleINFO
    Function F_GetUserRole(Userid in number)
    return T_RoleInfo as
    V_Role T_RoleInfo;
    begin
         select T_PREO_RoleINFO(PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME)
         BULK COLLECT INTO V_Role
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
         return V_Role;
    end;

  • How to return a value from sql plus activity

    Hi,
    I want to return a value from sqlplus activity to a processflow variable.
    SQL PLUS activity has a property :"RESULT_CODE", whenever i run the process flow this value is always reurned as 0.
    in sqlplus activity i have written some pl/sql block....
    for example
    begin
    end;
    exit
    i want to do something like
    begin
    if v=100 then
    return 1
    else
    return 0;
    end if;
    end;
    exit
    can some please tell me how can i return value from this pl/sql block to proessflow.
    Regards,
    RD_RBS

    table ==> function
    input param from table to function. ==> input mapping paramter to store the output from the mapping.
    Will this now work.

  • How to return 0 on max function when no rows found

    Hi everyone!
    I am using a max fuction, but I want that the function return 0 if there are not rows that match with the conditions.
    I was thinking in something like this
    SELECT nvl(max(salary),0)
    But it doesn't work, it doesn't show the value 0
    Please someone can give and idea
    Thanks a lot.

    Hi,
    Welcome to the forum!
    NVL (salary, 0) returns either salary or 0 on each row. It does not change number of rows.
    To make sure that rows exist, you can do an outer join, like this:
    SELECT  NVL ( MAX (t.salary)
                , 0
                )    AS max_salary
    FROM             dual
    LEFT OUTER JOIN  table_x  t  ON  1 = 1
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • How to return multiple values from dialog popup

    hi all
    I'm using ADF 10g. I have a requirement that I have to return multiple values from a dialog.
    I have a page containing a table with a button which calls the dialog. The dialog contains a multi-select table where i want to select multiple records and add them to the table in the calling page.
    In the backing bean of the calling page, I have the returnListener method.
    I am thinking that I have to store the selected rows from dialog in an array and return that array to the returnListener...but I don't know how to go about it with the code.
    Can someone help me out with it?
    thanks

    Hi Frank,
    I'm trying to implement your suggestion but getting comfused.
    AdfFacesContext.getCurrentInstance().returnFromDialog(null, hashMap) is called in ActionListener method, from what I understood.
    ReturnListener method already calls it, so no need to call explicitly.
    Okay here's what i'm doing.
    command button launches the dialog on the calling page.
    In the dialog page, there is a button "select", which when i click, closes the dialog and returns to calling page. I put a af:returnActionListener on this button, which logically should have a corresponding ReturnListener() in the calling page backing bean.
    Now I have 3 questions:
    1. do i have to use ActionListener or ReturnListener?
    2. where do I create the hashMap? Is it in the backing bean of the dialog or in the one of calling page?
    3. how do I retrieve the keys n values from hashmap?
    please help! thanks
    This is found in the backing bean of calling page:
    package mu.gcc.dms.view.bean.backing;
    import com.sun.java.util.collections.ArrayList;
    import com.sun.java.util.collections.HashMap;
    import com.sun.java.util.collections.List;
    import java.io.IOException;
    import java.util.Map;
    import javax.faces.application.Application;
    import javax.faces.application.ViewHandler;
    import javax.faces.component.UIViewRoot;
    import javax.faces.context.FacesContext;
    import javax.faces.el.ValueBinding;
    import javax.faces.event.ActionEvent;
    import mu.gcc.dms.model.services.DMSServiceImpl;
    import mu.gcc.dms.model.views.SiteCompaniesImpl;
    import mu.gcc.dms.model.views.SiteCompaniesRowImpl;
    import mu.gcc.dms.model.views.lookup.LkpGlobalCompaniesImpl;
    import mu.gcc.util.ADFUtils;
    import mu.gcc.util.JSFUtils;
    import oracle.adf.model.BindingContext;
    import oracle.adf.model.binding.DCBindingContainer;
    import oracle.adf.model.binding.DCIteratorBinding;
    import oracle.adf.view.faces.context.AdfFacesContext;
    import oracle.adf.view.faces.event.ReturnEvent;
    import oracle.adf.view.faces.model.RowKeySet;
    import oracle.binding.AttributeBinding;
    import oracle.binding.BindingContainer;
    import oracle.binding.OperationBinding;
    import oracle.jbo.AttributeDef;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.RowIterator;
    import oracle.jbo.RowSetIterator;
    import oracle.jbo.domain.Number;
    import oracle.jbo.server.java.util.Iterator;
    public class CompanyList {
    private BindingContainer bindings;
    private Map hashMap;
    DMSServiceImpl service =(DMSServiceImpl)ADFUtils.getDataControlApplicationModule("DMSServiceDataControl");
    SiteCompaniesImpl siteCompanyList = service.getSiteCompanies();
    LkpGlobalCompaniesImpl globalCompanyList = service.getLkpGlobalCompanies();
    public CompanyList() {
    public BindingContainer getBindings() {
    return this.bindings;
    public void setBindings(BindingContainer bindings) {
    this.bindings = bindings;
    *public void setHashMap(Map hashMap) {*
    *// hashMap = (Map)new HashMap();*
    this.hashMap = hashMap;
    *public Map getHashMap() {*
    return hashMap;
    public String searchCompanyButton_action() {
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding =
    bindings.getOperationBinding("Execute");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    return null;
    *public void addCompanyActionListener(ActionEvent actionEvent){*
    AdfFacesContext.getCurrentInstance().returnFromDialog(null, hashMap);
    public void addCompanyReturnListener(ReturnEvent returnEvent){
    //how to get hashmap from here??
    public String addCompanyButton_action() {
    return "dialog:globalLovCompanies";
    }

  • Newbie question on how to return java objects from java stored procedures

    Hi,
    As you may guess, i'm new to this.
    I have a stored procedure that does some calculations and creates a list of java objects as the result of the query.
    How would I return the list from the database to the client application?
    Would I have to create an Oracle type that maps to the java object?
    Please help.
    Jag

    Hi Jag,
    Your question is very vague (to me). Perhaps you could post what you have done so far? Have you tried looking through the Sample Code page of the Technet Web site, or tried searching the Ask tom Web site, or MetaLink?
    Good Luck,
    Avi.

Maybe you are looking for

  • Program times out while looping at internal table with huge records - Needs fine tuning suggestions

    Hi, I am trying to execute a report. It times out while looping at vbap internal table. This internal table has 140000  records and does the validation within this loop and geenrates data for the output. Due to this huge volume, the program times out

  • The lines I create with the pen tool are not showing up in After Effects.

    I'm working on a project where I need straight lines. I've added the lines using the pen tool on solid layers, but they are not showing up before or after rendering. I can see where they are supposed to be when I isolate the layer they are on. I have

  • Showing filter in dynamic list by default

    I have a form using the ADDT dynamic list behaviour. What I'd like to do is show the filter items automatically when that form opens rather than have the user click on the Filter button. Does anyone know how to do that? Thanks in advance for any advi

  • Importing Script Object

    Is it possible to make a Script Object part of the library in order for quick drag-and-drop additions to forms?

  • Why are the audio levels on a MBP so quiet?

    I'm a musician and the MBP's low audio output has been problematic. I've been using it as my main workstation at home in favor of my G5 desktop from 2003... and even as I'm running through my external audio hardware, my MBP's maximum volume is drasti