PL/SQL function/Expression in a default value

Hi,
I want to generate a sequence number using oracle sequence and populate a field when user hits create button. I tried using PL/SQL expression in the default value of a field. What is the exact syntax for this. I tried this
:P18_PROJECT_NUMBER := MNT_PROJECTS_NUMBER_S.NEXTVAL;
Did not work.
select MNT_PROJECTS_NUMBER_S.NEXTVAL into :P18_PROJECT_NUMBER
from dual;
Did not work. Can anyone help me with this ?
Thanks
Naresh

Naresh - You should never say something "did not work" without saying what happened. It is useless otherwise.
See Re: Returning PK before insert row and use PL/SQL Function type.
Scott

Similar Messages

  • User defined function to set a default value of a column

    Hi All
    Can we use user defined function to set a default value of a column ??
    for example:
    create or replace  function test1  return number is
    begin
    return 10;
    end;
    create table testt
    (id  as test1,
      name varchar2(20));
    error:
    ORA-02000: missing ( keywordThanks
    Ashwani

    174313 wrote:
    MichaelS for showing example to use function in table ddl , otherwise i was thinking we cannot use function in table ddl as per error I received.That was an example of a virtual column.
    ORA-04044: procedure, function, package, or type is not allowed hereUsing PL/SQL code like that raises 2 basic problems. If that PL/SQL code for the calculating the column default breaks, what happens to the SQL insert statements against that table. These will need to fail as the table definition depends on the PL/SQL code. This is problematic as this dependency simply increases the complexity of the SQL object.
    The 2nd issue is performance. PL/SQL code needs to be executed by the PL/SQL engine. This means a context switch from the SQL engine to the PL/SQL engine in order to determine the default value for that column. Context switching is a performance overhead.
    So even if it was possible to use a PL/SQL function as parameter for the SQL default clause, I would not be that keen to use it.

  • IW31 how to set functional area as a default value?

    Dear all:
    Can anyone guide me, is any way to set "functional area" as a default value (t-code iw31 Additional Data -> Functional area)?
    Thanks in advance.

    Hello ,
    The standard funtionality is set to default the Functional Area from the Order Type.  I believe it is possible to change the default value for the Functional Area in Transaction KOT2. The PM order types should be selectable in this transaction.
    I hope this information has been helpful.
    Best Regards,
    Frank

  • SQL Loader, nested tables and default values

    Is there a way to specify a default value for a nested table entry when SQL*Loader encounters a 'null' value?
    I want to avoid this:
    Record 5: Rejected - Error on table LEVEL_DESC, column LEVELS.
    NULL nested table element is not allowed

    Use the NULLIF parameter in your control file for the nested table objects.
    e.g
    LOAD DATA
    INFILE 'level_data.dat'
    INTO TABLE LEVEL
    (LEVEL_ID POSITION (01:05) CHAR
    LEVEL_NAME POSITION (07:20)
    LEVEL_DESC COLUMN OBJECT
    (LEVELS POSITION (22:25) CHAR NULLIF LEVEL_DESC.LEVELS=BLNAKS,
    ... ))

  • LAG Function not accepting a default value

    Hi,
    I'm trying to create a calculation using the LAG function and it won't allow me to enter a default value. Currently the condition is LAG(Work Order Headers WOI.Service Dt,1) OVER(PARTITION BY Work Order Headers WOI.Equipment Ident ORDER BY Work Order Headers WOI.Service Dt ) but I want/need it to be LAG(Work Order Headers WOI.Service Dt,1,trunc(sysdate)) OVER(PARTITION BY Work Order Headers WOI.Equipment Ident ORDER BY Work Order Headers WOI.Service Dt ).. so adding the 'default' value of trunc(sysdate). I have tried other examples not using dates and I get the same problem. It gives a Too many arguments supplied to function LAG error.
    We are using Discoverer 10.1.2.45.46c.
    Is this a known problem with our version ?

    Further. I did try to create a custom folder in the Admin layer and it allows the 'default' value.

  • Bypassing function argument without changing default value

    Hi there
    I’m having some problems understanding how I can bypass function arguments without changing its default value. Here are some examples:
     function myFunction ( arg1:Boolean, arg2:String="default string", arg3:Number=3 ):Array
        return new Array (arg1, arg2, arg3);
    trace(myFunction(true, "new string", 5));
    // true,new string,5
    trace(myFunction(true, undefined, 5));
    // true,,5
    trace(myFunction(true, null, 5));
    // true,,5
    trace(myFunction(true));
    // true,default string,3
    trace(myFunction(true, null));
    // true,,3
    My question is: Shouldn't I be able to call a function bypass the second argument (that has a default value), change third argument and on result second argument maintains its default value?
    Example:
    trace(myFunction(true, null, 5));
    // not desired: true,,5
    // desired: true,default string,5
    I know that applying a defult value to the argument allows one to bypass it. But it will always be redefined or to null or to undefined. At the moment I only see one solution.
    function myFunction ( arg1:Boolean, arg2:String="default string", arg3:Number=3 ):Array
         if (!arg2)arg2 = "deafult string";
         return new Array (arg1, arg2, arg3);
    It just seems like too much code repeated
    Regards

    Hi dmennenoh,
    Yup, this was just an example to show that the use of a default value only helps you to bypass the need to simulate a MouseEvent Object for an onRollOver MouseEvent argument. Other than that you can never bypass it without changing its value. You must always apply a null or undefined value and work with that.
    Thanks anyway

  • SQL Loader needs to load default value instead of null

    I am loading data from the flat file into the table. The table primary key consists of 5 fields. One of these fields might be empty in the text file, so on the load I need to substitute it with some default value like "***", for instance. Is there any way to make some conditions in the control file?

    You can either make use of the suggession given by Warren Tollentino or alter table by adding default constraint for the column.

  • Forms: sql with bind variable as default value to form field?

    I am using a form as a way to show details of already entered rows in a table. A report passes an id parameter to the form to get it to show the right data. No insert or update is possible. (I am using a form rather than a report because I need to display BLOBs, something reports can't do.)
    I need to execute sql statements based on the passed id to fill certain fields in the form with data from other tables. For example: The table the form is based on includes a category_id, whereas I want to display the category name which resides in another table.
    How would I best achieve this?

    Hi,
    You do this in the additional plsql code section of the form by getting the value of the category_id from the session variables and then getting its name from the cateogory table and assigning it to the category name column.
    Sample Code
    declare
    catid number;
    catnm varchar2(30);
    blk varchar2(10) := 'DEFAULT';
    begin
    catid := p_session.get_value_as_varchar2(
    p_block_name => blk,
    p_attribute_name => 'A_CATEGORY_ID');
    select category_name
    into catnm
    from cat_table
    where category_id = cat_id;
    p_session.set_value(
    p_block_name => blk,
    p_attribute_name => 'A_CATEGORY_NAME',
    p_value => catnm
    end;
    Thanks,
    Sharmila

  • Pl/sql expression for default value

    I'm trying to run this simple script as a default value using pl/sql expression, but I keep getting this error. THe select statement itself works fine as a sql statement source value, but will not work as a pl/sql exression as a default value. This (:P33_SYSUSERID_CREATED_BY ) is the field name on the form. Any ideas?
    begin
    select a.id || ', ' || A.NAME_LAST into :P33_SYSUSERID_CREATED_BY from S_USERSV a where a.name_last = 'HAMMAKER';
    end;
    Error ERR-9132 Error in PLSQL expression for item default code, item=P33_SYSUSERID_CREATED_BY
    OK
    ORA-06550: line 1, column 27: PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: ( - + case mod new not null avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe

    Sudha,
    For a default value type of PL/SQL Expression, you could create a function that accepts an input and returns a value. If the function (not a procedure) is named GET_REFNO, you would call it using an expression in the default value field like:
    get_refno(:P3_REFTYPE)
    For a default value type of PL/SQL Function Body, you could call your existing procedure with a default value like:declare
        l_value varchar2(32767);
    begin
        get_refno(:P3_REFTYPE, l_value);
        return l_value;
    end;Scott

  • SSRS Cascading Parameter Setting Default Value of Parameter by Expression

    Hi All,
    I need some help on an issue I am running into in SQL server 2008 report parameters. I have the following Report Parameters defined:
    1) @PredefinedDateSelection - Boolean (User Selectable True/False, Default Value - 'False')
    2) @StartDate - Text (User input text box)
    If @PredefinedDateSelection = TRUE, then I would like to provide a particular default value to the StartDate textbox (i.e. @StartDate Default Value), If @PredefinedDateSelection = FALSE, then I would like to provide a different default value.
    I have the following code for the Expression for the Default value of @StartDate: =code.GetStartDate(Parameters!PreDefinedTimeSelection.Value)
    where GetStartDate is a very simple VB function defined as :
    Public Function GetStartDate(x as boolean ) As String
    Dim a as string
    Dim b as string
    a = "Report Uses Predefined Values"
    b = "Please Input Value"
    If (x) then
    Return a
    else
    Return b
    end if
    end function.
    Now the default value of @StartDate stays set as "Please Input Value", and does not change when I toggle @PredefinedDateSelection from False to True and vice versa. I was expecting to see the Default value to change between the two messages depending on my selection in the report preview.
    Another parameter which is a dropdown and uses a dataset to display two different set of selectable items depending on the value of @PredefinedDateSelection is working just fine. I am not sure if I am missing something or I am doing something wrong.
    Instead of using the VB code I also tried : =iif(Parameters!PreDefinedTimeSelection.Value = True,"Report Uses Predefined Values","Please Input Value")
    I also tried changing the default value using a dataset with SQL query and the available value set to NONE, so that the user could input. But the Default value does not refresh or change values.
     I hope I have explained my question clearly. I would really appreciate any thoughts and comments.
    Thanks,
    Arunesh

    Thank you much for your response.
    I tried that and it did work. But my requirement is to have a user input the date. The basic idea is if the user decides on a predefined time range like Day Shift Today or Yesterday and so on... then the report would automatically calculate the values based on predefined date time values. On the other hand, if the intent is to run the report for an arbitrary period then the user supplies the date and time limits.
    What I am trying to achieve is have the same parameter available for user input , but when the User decides he wants Predefined then the "textbox" populates with date and time as per his choice of predefind range.
    I understand that by this the user can still overwrite the date and time on the text box, but the report will run the predefined values as long as he has the @PredefinedDateSelection Set to true.
    Is there a way I can impement this?
    Once again I thank you and appreciate  your input.

  • Page item default value using PL/SQL

    Hello,
    I'm trying to set a default value for a text field page item in a form.
    I'm using this PL/SQL Function Body in the Default section:
    begin
    select ("DEPT_CODE"|| ' ' || DEPT_NAME) from MyView where UserID = :G_USER_ID;
    end;
    I get the following error:
    PLS-00428: an INTO clause is expected in this SELECT statement
    Any help is appreciated!
    thanks,
    Matt

    Matt
    I'm using this PL/SQL Function Body in the Default section:
    begin
    select ("DEPT_CODE"|| ' ' || DEPT_NAME) from MyView where UserID = :G_USER_ID;
    end;Well, that's not a PL/SQL function body. This is:
    declare
      x varchar2(4000);
    begin
      select ("DEPT_CODE"|| ' ' || DEPT_NAME) into x from MyView where UserID = :G_USER_ID;
      return x;
    exception others then
      return null;
    end;Scott

  • Using return value of a pl/sql function in the "where" coarse in a

    Hi,
    I have a question,
    if I have a pl/sql function that returns a boolean value, how can I use
    it directly in a select statement?
    I can easily do this if the function returns a number value , e.g.
    select * from my_table where my_package.function('abc') = 1;
    But I can't figure out how to do this if the function return a boolean.
    Any idea other than creating another function?
    Please reply to me directly as I'm not in the email list. Thanks.

    BOOLEAN is not a SQL datatype - you can only reference Boolean values in PL/SQL.

  • Report parameter default value do not default correctly

    Hello Experts, I have a cascading parameters in my report.
    The first parameter called "Project" will allow to select a single Project Name from the list and based on the Project Name, the second parameters which is a "Date" parameter will give out list Months and Year in the Format 'Nov-14'. 
    For this Second parameter I defaulted the parameter to show First Month in the retrieved list of Months. But the problem is it will display the default Date correctly only certain times (there is a refresh problem). If i select a different project and it
    has a month that was retrieved in the first project it will still show the that Month but not the actual default month (Start Month) for that particular Project.
    Example: If I select Brisk from Project parameter, It will give me 18 months of Dates in the Date parameter. In that 18 month range first month is Sep-13 it will default to Sep-13 correctly. Then if I select a different project like "Creek" (example)
    as Project , the Date parameter retrieves some dates corresponding to Creek Project and in the retrieved months if  Date parameter has Sep-13 it will still show Sep-13 even though the
    Start Date for Creek project is Jun-12.
    1. Project Brisk: Defaulted correctly to Sep-13
    2. Creek Project : Should default to Jul-12 but still shows Sep-13
    Just for default value I created a separate dataset and used it to populate the default value and the SQL I used just for default value is as below:
    SELECT DISTINCT TRUNC(DATE_KY, 'MM') AS DEFUALT_DATE
    FROM            DATE_D D
    WHERE        (DATE_KY = ADD_MONTHS(:PROJECT_DT, - 6))
    Date parameter datatype is Date/Time,
    Available Values Tab: label field is a String but the Value field and the default field (Default Values tab) are Dates 
    Thanks in advance

    Thanks Vicky for reply.
    Yes you are right but I did not use First function as the query above retrieves only one date.
    I used your suggestion but it did not fix it.
    In this report I have three parameters.
    1. Project Code (Visible)
    SELECT DISTINCT PROJECT_CODE
    FROM      DIM.PROJECT     
    ORDER BY PROJECT_CODE
    2. Project Date (Invisible)
    SELECT
    MAX(CASENA.MILESTONE
    WHEN'ABCD'THENTRUNC(PROJECT_DATE,'MM')ELSENULLEND)PROJECT_DATE
    FROM
    DIM.PROJECTNA
    WHERE(NA.PROJECT_CODE
    =:PROJECT_CODE
    or'ALL'=:PROJECT_CODE)
    3. Start Date (Visible):
    Available Values Query:
    SELECT DISTINCT
    --DER_DATE is "Value Field"
    TRUNC(D.DATE_KY, 'MM') DER_DATE 
    --Display_date is "Label Field"
    , TO_CHAR(D.DATE_KY, 'Mon-YY')   Display_Date
    FROM DATE_D D
    WHERE DATE_KY BETWEEN ADD_MONTHS(:PROJECT_DATE, -6)  AND ADD_MONTHS(:PROJECT_DATE, 6)
    ORDER BY 1
    Default Values Query:
    SELECT DISTINCT TRUNC(DATE_KY, 'MM') AS DEFUALT_DATE
    FROM            DATE_D D
    WHERE        (DATE_KY = ADD_MONTHS(:PROJECT_DATE, - 6))
    When you select a Project from "Project Code", it will give a "Project Date" and based on the "Project Date" it will give a date range in "Start Date". That is why I am using "Project Date" parameter in my
    query. I even tried using Project code as you suggested but I still got the same result.
    Thanks a lot for your reply.

  • How to set the default value in dashboard prompt?

    Hi there,
    In my Dashboard prompt I'm getting values like:
    Mar 2010
    Apr 2010
    May 2010
    Jun 2010
    How to set the default value to the current month (Jun 2010). I don't want to use "specific value". I want to use the "SQL Result" for populating the default value.
    Appreciate your help

    hi,
    you can create a Repository variable current_month with the expression as
    select to_char(trunc(sysdate),'Mon')from dual
    and use this in the prompt "Default to" Server variable and use this repository variable.
    hope this helps.
    cheers,
    vineeth

  • How to process validations using PL/SQL function

    Hi.
    I created a page with a form to process DML operations against a database table. Also created a validation using PL/SQL function that returns a boolean value:
    declare
    v_dummy varchar2(1)
    begin
    select 'X'
    into v_dummy
    from s_customer
    where id = :p2_id;
    return (TRUE);
    exception
    when no_data_found then
    return (FALSE);
    when others
    return (TRUE);
    end;
    In this case i want to send a message to the user indicating that an certain row (the one with :p2_id value) already exists in the database. The piece of code above will do the job. If this function returns true, it means the row is in the DB already.
    The problem is that i don´t know what do to or how to tell htmldb that a TRUE value should issue a message or be processed as en error, whilst a FALSE means OK.
    How do i tell htmldb what to do?
    Suppose must do something with "expression 1" , "expression 2", etc.
    Any ideas???

    Hóla LuÃs,
    when you pick the PL/SQL function body returning a boolean, it implicitly means that TRUE means OK, while FALSE means error, always.
    In order to associate such error to a given form field, you have to go back to the page definiton / validations and specify the name of the item in the corresponding field.
    When you first create the validation rule, this value is not present even if you ask for the error message inline with the field.
    The error message text can be specified in the validation definition, if I am not wrong.
    When you need to return special error messages, including dynamic content for instance, you can use the Function Returning Error Message type, which reports an error when the string returned by the function is not null. This comes in handy when you want to display an item's code, for example, rather than generic text.
    Even in this case, you must go back to the validation and specify the name of the field if you want to see it inline.
    Hope it helps,
    Flavio

Maybe you are looking for

  • When typing an 'L' followed by forward slash '/' I get a weird character

    I can't figure this out. whenever I type a string of text that requires an L and forward slash together I get some weird character that resembles an 'f' like for designating a 'function' in an equation only its backwards. this occurs in terminal, lik

  • Can't get iphoto to work after tampering with library in Finder

    I think I made a big mistake when I tampered with the iphoto library in Pictures in Finder. Now I can't get iphoto to work. All the pictures are gone in iphoto, the spaces are there but they are blank. When I open iphoto it goes into the mode (little

  • FCPX Event Library

    Hello, I have a project up in the Timeline right now.  When I click on the Film Strip at the bottom left access the Event Library, it automatically goes to Loading... and then the name of a project that I don't want to access.  I can't even get into

  • Logitech z5300e and Audigy 2 Zs h

    When I try to play music or anything, the only channel that seems to be "working" is the center channel, and that is just pure static. Any ideas on the problem?

  • DPM 2012 service crashes when creating a protection group

    DPM Server Setup: Windows Server 2012 Datacenter DPM 2012 SP1 RU3 (Version 4.1.3417.0) SQL Server Setup: Windows Server 2012 Datacenter SQL Server 2012 Standard (11.0.3128.0) DPM database is on a named instance on a custom port Windows firewall is co