Auto generate the column in function

Hi all

I'm using oracle 11g on windows.

I have a table with two columns purch_id and item_code.

name of the table PURCHASE

Column name PURCH_ID number

Column name ITEM_CODE number

This composite primary key for the table (purch_id and item_code).

Item_code is autogenearted with Purch_id for example.

PURCH_ID ITEM_CODE

1080 1

1070 1

1285 1

1070-2

1 1495

I'm writing a function but not doing so to increment the ITEM_CODE 1

When the PURCH_ID are in the table.

The user will be entered only purch_id and if purch_id exists in the item_code table should then be increment of 1.

and if purch_id does not exist in the table, then item_code must be 1.

Could someone please help me fill out this complex function.

Rgds and thanks in advance

Saaz

Something like that?

CREATE OR REPLACE

FUNCTION get_item (i_purch_id in NUMBER)

RETURN NUMBER

IS

cnumber NUMBER: = 1;

v_item_number NUMBER;

v_cnt NUMBER;

BEGIN

SELECT COUNT (*) IN v_cnt

Purchase

WHERE purch_id = i_purch_id;

IF v_cnt > = 1 THEN

SELECT MAX (item_number) + 1

IN v_item_number

Purchase

WHERE purch_id = i_purch_id;

ON THE OTHER

v_item_number: = 1;

END IF;

RETURN v_item_number;

EXCEPTION

WHILE OTHERS THEN

raise_application_error (-20001,' an error has occurred - ' |) SQLCODE |' - ERROR - ' | SQLERRM);

END;

Tags: Database

Similar Questions

  • Disable the column key functional for an individual of forms

    Hi all

    I have a block of multiple registration details in my form with fields (type, point, wt, vehicle number etc.). Keys are already scheduled for functional use as f3 to copy.

    In my form, I want to use the copy function to get to the fields as type, point, wt, but not for the vehicle number column. IE type, point, maybe same wt columns but number of vehicle may not be same (according to customer requirement). They will not accidentally copying the same number of vehicle.

    For this I need to disable the copy (F3) function for this vehicle only number column.

    Is there a workaround for this...

    My version of the form is 10g

    Thanks in advance

    Concerning

    JaKes

    the KEY-F3-trigger has nothing to do with the F3 function key. In client-server F3 is associated with the DUPLICATE_ITEM function, so you should use the KEY-DUPITM-trigger.

    Also, if you implement a release BUTTON, it replaces the functionality by default, so you must manage the service for yourself.

    As for the OP functionality should just be deleted at one, the simplest solution is to create KEY-DUPITM-relaxation so precise and simple insert a value that is NULL. inside.

  • create indexes on the upper part of the column - reminders function is not deterministic

    Hi all

    I'm having a problem on a database. When you create an index on an existing table on the upper part of a column, Oracle triggers an ORA-30553. I've done this 40 index other databases, with the same and different versions, without problem. When you create the index on a copy of the table, it is created with success...

    Here is the code:

    SQL > select * from v version $;

    BANNER

    --------------------------------------------------------------------------------

    Oracle Database 11 g Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for 64-bit Windows: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    SQL > CREATE INDEX IDX_SRE_E_MAIL_UPPER on fsynrelatie (upper (sre_e_mail)) tablespace idx;

    CREATE the INDEX IDX_SRE_E_MAIL_UPPER on idx tablespace fsynrelatie (upper (sre_e_mail))

    *

    ERROR on line 1:

    ORA-30553: the function is not deterministic

    SQL > create table fsynrelatie2 in select * from fsynrelatie;

    Table created.

    SQL > CREATE INDEX IDX_SRE_E_MAIL_UPPER on fsynrelatie2 (upper (sre_e_mail)) tablespace idx;

    The index is created.

    SQL > drop table fsynrelatie2;

    Deleted table.

    SQL > show parameter query_rewrite_enabled

    VALUE OF TYPE NAME

    ------------------------------------ ----------- ------------------------------

    query_rewrite_enabled string TRUE

    Hi all

    Thank you for the answers. I found the problem:

    On the table, there are 54 index:

    Select index_type, uniqueness, count (*) from user_indexes where table_name = 'FSYNRELATIE '.

    Index_type group, uniqueness

    INDEX_TYPE SINGLE CHARACTER COUNT (*)
    FIELD ARE NOT UNIQUE 1
    BASED ON A NORMAL FUNCTION ARE NOT UNIQUE 4
    NORMAL UNIQUE 3
    NORMAL ARE NOT UNIQUE 46

    3 unique indexes are the primary key and 2 another witch number field contains unique identifiers for rows in other systems. The domain index is an index of Oracle text on a couple of fields. There are 3 indices of function based on a high on a field and 1 on an individual function. This last clue has caused the problem. Apparently, on the creation, this function is deterministic, but when rolling a new version of the software. It became a non-deterministic function. When I delete the index, my original index on upper (sre_e_mail) has been created successfully! Now, I did the deterministic function again and could recreate the function without problem.

    Thanks for your comments!

  • Auto generate the data field item2

    I have fields in my application

    If I select the Item1 number it will automatically give me the value in Item2 refers to this item1 can you please answer on that

    Hello

    It is necessary to a column of data for the updated item in the record.

    As long as you set the value everytime the page loads, you can change the value of the Source used for: only when the current value in session state is zero

    Then create a calculation for your page, your page that runs "before the header" that executes your SQL code

    Andy

  • Dynamically by passing the values in the columns

    Hi all

    I'm trying a pl/sql block that take a string and execute it dynamically. Suppose that here is the string

    M_COL: = Q' [(Code_P = > ': DEPTNO', P_CODE_TYPE = > "ÉTAT")]';

    Now try to run. using below

    M_STR: = 'SELECT CHK_DEPT ' | M_COL | ' FROM EMP WHERE EMPNO = "7499" ';


    RUN IMMEDIATELY M_STR

    IN M_DATE;

    Now what I want is M_STR vairable executed as

    SELECT CHK_DEPT (Code_P = > DEPTNO, P_CODE_TYPE = > 'STATE') FROM EMP WHERE EMPNO = '7499'

    Instead of

    SELECT CHK_DEPT (Code_P = > 'DEPTNO', P_CODE_TYPE = > 'STATE') FROM EMP WHERE EMPNO = '7499'

    another other way in the Code_P column DEPTNO value parameter must be passed. Also note that the DEPTNO column in the M_COL string is Dynamic.i.e

    M_COL: = Q' [(Code_P = > ': DEPTID', P_CODE_TYPE = > "ÉTAT")]'; OR

    M_COL: = Q' [(Code_P = > ': EMP_ID', P_CODE_TYPE = > "ÉTAT")]';

    Any suggestions, please share with me.

    And also, please don't bother much about the data and the output of function. If I get a way to pass the value of the column in function, my problem is solved.

  • What is the JS/jQuery function should I call to sort a column in an IR?

    Hi guys,.

    Given that this no longer works in APEX 5.0: how you trigger sort column of the item page APEX interactive report?

    I'm looking for the function that is called when you press the button to sort on a column to place the call in a dynamic Action.

    What function is called and how when you press the button in the image below?

    Thank you

    Digital

    I don't know why you (or someone else) so go out of your way to disassemble the main features of the IR. Literally everything you have (or had) to do was to tell users how to use the controls that is given to them. What is the punishment by clicking on a column header to sort something out or use the format > dialogue sort? I don't understand. Here are the easy commands that work in singles. What you (or they) win by this control in duplicate?  Why is it important if he doesn't "Executive"? Does this mean that if something is or was bad, you should keep just bad? They shouldn't have to learn to work well with their tools?

    Look, I'm all in favour of offering more control over widgets (API and) such as IR and I have provided my share of hackery. I don't see much justification here.

    Then gReport using was quite clear and the markup was simpler, at apex 5, is more complex. The principle is much the same, a lastcolumnid is defined and a direction, then the sortorder is called in the _columnOrder. You cannot use _columnOrder unless you set lastColumnId on the widget and I wouldn't do that as I do not change the internal state. So I just use the call syntax used in turn. Your selection list will select the columns of ir apex for this (since you need the id)

    var irw = apex.jQuery("#myReport_ir").data("apex-interactiveReport"); -- retrieve widget instance
    -- trigger the action
    -- f01: column id. In apex 5 these are by default generated ids, f02: desc/asc
    irw._action("COLUMN_ORDER", {f01: irw.lastColumnId, f02: "DESC" });
    

    Do with what you want and use at your own risk. It is not supported and could very well break flat-out more down the line. Not to mention that you (or someone else) have to maintain it and still understand it later.

  • I want to auto generate a word from a PDF document. Firstly, the OCR must identify the document. Then I want to be able to select the character 'areas' where the text will be different by document according to the document. Again, I want this automated pr

    I want to auto generate a word from a PDF document. Firstly, the OCR must identify the document. Then I want to be able to select the character 'areas' where the text will be different by document according to the document. Again, I want this automated process.

    We have many forms in our records. From these forms, we generate a list of documents that fully represents what is in the file. To create a list of accurate documentation of a specific file, I have to manually go page-by-page, extract specific information (they are in the same place) and the list of documents manually. I want to automate this process.

    The function of OCR in Acrobat does not 'zone' OCR.

    Server as "automation" is not supported by Acrobat (by license and by design). Acrobat is a desktop application, and so many activities can be "automated" via Acrobat JavaScript and Acrobat Actions (a feature of the 'Pro' version) a hot body will have to be available to keep things moving along.

    From what write you it's maybe that your specific needs would be better served by a category Server product. To research these remember Bing / Google is your friend.

    Be well...

  • generate the value of the column according to the conditions

    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE     11.2.0.3.0     Production
    TNS for HPUX: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    statement to generate the selection inputs
    WITH t
         AS (    SELECT 1 job_request_id,
                        1 original_job_request_id,
                        mod(level,3) +1  sequence_cd,
                        CHR (LEVEL + 100) value_txt,
                        NULL new_sequence_cd
                   FROM DUAL
             CONNECT BY LEVEL < 6),
         t1
         AS (    SELECT 2 job_request_id,
                        1 original_job_request_id,
                        mod(LEVEL,2) + 1 sequence_cd,
                        CHR (LEVEL + 110) value_txt,
                        NULL
                   FROM DUAL
             CONNECT BY LEVEL < 10),
         t2
         AS (    SELECT 3 job_request_id,
                        3 original_job_request_id,
                        mod(LEVEL,3) + 7 sequence_cd,
                        CHR (LEVEL + 95) value_txt,
                        NULL
                   FROM DUAL
             CONNECT BY LEVEL < 9),
         t3
         AS (    SELECT 4 job_request_id,
                        3 original_job_request_id,
                        mod(LEVEL,2) + 1 sequence_cd,
                        CHR (LEVEL + 95) value_txt,
                        NULL
                   FROM DUAL
             CONNECT BY LEVEL < 7),
         t4
         AS (    SELECT 7 job_request_id,
                        3 original_job_request_id,
                        mod(LEVEL,2) + 1 sequence_cd,
                        CHR (LEVEL + 92) value_txt,
                        NULL
                   FROM DUAL
             CONNECT BY LEVEL < 4),
             
         mytable
         AS (SELECT * FROM t
             UNION ALL
             SELECT * FROM t1
             UNION ALL
             SELECT * FROM t2
             UNION ALL
             SELECT * FROM t3
             UNION ALL
             SELECT * FROM t4)
    SELECT *
      FROM mytable
      order by job_request_id, original_job_request_id, sequence_cd;
    entry
    JOB_REQUEST_ID     ORIGINAL_JOB_REQUEST_ID     SEQUENCE_CD     VALUE_TXT     NEW_SEQUENCE_CD
    1     1     1     g     
    1     1     2     h     
    1     1     2     e     
    1     1     3     i     
    1     1     3     f     
    2     1     1     v     
    2     1     1     p     
    2     1     1     r     
    2     1     1     t     
    2     1     2     u     
    2     1     2     q     
    2     1     2     o     
    2     1     2     s     
    2     1     2     w     
    3     3     7     b     
    3     3     7     e     
    3     3     8     `     
    3     3     8     f     
    3     3     8     c     
    3     3     9     d     
    3     3     9     a     
    3     3     9     g     
    4     3     1     e     
    4     3     1     c     
    4     3     1     a     
    4     3     2     b     
    4     3     2     `     
    4     3     2     d     
    7     3     1     ^     
    7     3     2     ]     
    7     3     2     _     
    expected results
    JOB_REQUEST_ID     ORIGINAL_JOB_REQUEST_ID     SEQUENCE_CD     VALUE_TXT     NEW_SEQUENCE_CD
    1     1     1     g     1
    1     1     2     h     2
    1     1     2     e     2
    1     1     3     i     3
    1     1     3     f     3
    2     1     1     v     4
    2     1     1     p     4
    2     1     1     r     4
    2     1     1     t     4
    2     1     2     u     5
    2     1     2     q     5
    2     1     2     o     5
    2     1     2     s     5
    2     1     2     w     5
    3     3     7     b     7
    3     3     7     e     7
    3     3     8     `     8
    3     3     8     f     8
    3     3     8     c     8
    3     3     9     d     9
    3     3     9     a     9
    3     3     9     g     9
    4     3     1     e     10
    4     3     1     c     10
    4     3     1     a     10
    4     3     2     b     11
    4     3     2     `     11
    4     3     2     d     11
    7     3     1     ^     12
    7     3     2     ]     13
    7     3     2     _     13
    my attempt to explain.
    If the job request id = id of the new cd of sequence = sequence cd original job application

    When the employment application IDS are higher than the original increment the new cd of sequence with respect to the maximum of the original work request id sequence cd.

    I hope that the expected results will clarify.

    Hello

    It looks like you want DENSE_RANK, except that you want to ignore the numbers (for example, 6 in this example) when necessary so that new_sequence_cd > = sequence_cd.

    With the help of analytical functions:

    WITH      got_drank     AS
    (
         SELECT    m.*
         ,       DENSE_RANK () OVER ( ORDER BY  job_request_id
                                            ,      original_job_request_id
                                      ,      sequence_cd
                                  )  AS drank
         FROM      mytable  m
    )
    SELECT       job_request_id
    ,            original_job_request_id
    ,        sequence_cd
    ,       value_txt
    ,       drank + MAX ( sequence_cd
                      - drank
                    ) OVER ( ORDER BY  job_request_id
                                ,      original_job_request_id
                          ,      sequence_cd
                        )  AS new_sequence_cd
    FROM      got_drank
    ORDER BY  job_request_id
    ,            original_job_request_id
    ,        sequence_cd
    ;
    

    You can also use the MODEL.

    If you have a new_sequence_cd column in a table, one you want to fill, use the query in a MERGE statement above.

  • TRIGGER - how to auto fill a column with the sequence

    Hello

    I have a table that contains information about the customers... I have bound him to a form of the APEX so that when a user enter information through a form he generates a sequence/trigger number and saves it in the column (named tracking_NO)... I use this tracking_no as key for monitoring purposes.

    My problem is that when the admin will post information from MS access to Oracle, it generates automatically a number for my column 'tracking_No '... Please advice how to use the same trigger Auto Fill a column (tracking_no) when the value is zero.

    Here's my trigger

    CREATE OR REPLACE TRIGGER B.T_CUSTOMER_TRG
    BEFORE THE INSERT OR UPDATE
    ON B.T_CUSTOMERS
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    Start
    If: NEW. "' TRACKING_NO ' is null then
    Select T_CUSTOMER_SEQ.nextval in: NEW. "' TRACKING_NO ' from dual;
    end if;
    end;
    /

    Two copies.
    I really think this is a bug coding causing this duplication.

    Published by: PhoenixBai on December 25, 2010 21:50

  • PL/SQL Query return function, adding the column links

    Hi all

    I'm working on a SQL report with the area type = function from PL/SQL Query to return
    All columns are generated dynamically based on my mapping table and a column of ID.
    So whenever the page is loaded, according to the ID mapping table returns a set of columns in a particular order.
    So not only the columns are dynamic, but the order of the columns varies also.
    But the first 1 column is standard (it doesn't come from the mapping table) and is coded in my pl/sql block hard.

    I'm fighting with the addition of a link to this column. The link must be a Javascript function which takes the parameters in the form of 2 columns in the mapping table.
    My pl/sql block is something like that...
    v_select := 'SELECT <g href=javascript:f_report1(#map_id#,#comments#)><img src=""></a> as report1, ';  // g=a
    v_cols := 'contains all columns from the mapping table based on a ID(hidden item)';
    v_from := 'FROM table';
    v_where := 'where condition is put in here';
    v_query := v_select||v_from||v_where;
    return v_query;
    Now, I'm not able to transmit the values of this #map_id # and #comments # correctly. I tried so many different combinations of channels, but could not make it work.

    I'm not sure that the order of this map_id and commentscolumn and therefore cannot connect through the report attributes.
    How can I go to a column value to the function?



    Thank you
    Dippy

    This should work if all goes well:

    v_select := q'[ SELECT '' as chart, ]';
    

    Published by: Dimitri Gielis on May 20, 2010 20:10

  • Default qualifier to "generate the function tree.

    Hello

    Since this is my first attempt to use the CVI feature for the creation of a Commission of an include file as I am facing a very basic question...

    My problem is that in the popup 'Generate the function Tree', I need to specify a default qualifier. So Far, however, I use no qualifier by default, because one) I didn't need and b) I provide 32-bit and 64-bit software versions. If I understand correctly, I have to choose for 32 bit __stdcall or __fastcall for 64 bit. In other words, a function panel will work for 32-bit or 64-bit programs? I guess it's a misunderstanding

    Furthermore, it should be to update the tutorial (from 2014?) to reflect actual contextual Control Panel CVI2013...

    You should be able to use the __stdcall in your code, regardless of the number of bits. When you build a 64-bit version of your code, this qualifier is ignored (it will use fastcall instead), but its presence is harmless.

  • Cannot generate the multi-function in Vista

    We ship an ActiveX control for use by our customers. In our sample code, we created a multi-function for them.

    A customer reported that it cannot create a new function by using the Vista Panel - but he can create one using Windows XP.

    Is there a known issue with the creation of panels to function under Vista?

    Concerning

    John Barton

    Hi John,.

    One thing you need to check on these machines that fail is the File Format of the FP.  This opens a file of .fp to the CVI, then going to the Options menu and then click on the FP File Format.  In this dialog box, make sure that the default new File Format is set to CVI 5.5 and later versions or CVI 8.5 and later versions. Once you put in one of these formats, you should be able to generate your panels to function again.  Please let me know if this does not work, or if you have any questions.

    NickB

    National Instruments

  • Generate the series based on the column

    Hi Experts,

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

    PL/SQL Release 9.2.0.1.0 - Production

    Could you please help me to generate the folloing sequence.

    act_noto_be
    11
    02
    12
    12
    03
    13
    04
    14
    14
    14
    05
    15
    15
    15
    15
    15

    Based on the act_no I want to generate the sequence to_be in sql.  Help, please.  Thanks in advance.

    You must have a column that defines the order of the line. I added a column ID that defines the order of the single column. With this you can do.

    SQL > t
    2 as
    (3)
    4. Select 1 id, 1 act_no Union double all the
    5 select id 2, act_no 0 of all the double union
    6 select id 3, 1 act_no Union double all the
    7 select id 4, 1 act_no Union double all the
    8 select id 5, 0 act_no of all the double union
    9 select id 6, 1 act_no of all the double union
    10. select id 7, 0 act_no of all the double union
    11 select id 8, 1 act_no Union double all the
    12. select id 9, 1 act_no of all the double union
    13. select id 10, 1 act_no of all the double union
    14 select id 11, 0 act_no of all the double union
    15 select 12 id, 1 act_no of all the double union
    16. select id 13, 1 act_no of all the double union
    17 select id 14, 1 act_no of all the double union
    18 select id 15, 1 act_no of all the double union
    19 select id 16, 1 double act_no
    20)
    21 select t.id
    22, t.act_no
    23, max (t1.rno) on to_be (t.id control)
    24 t
    25 left
    Join the 26)
    27 select row_number() over (order by id) rno
    28                 , id
    29, act_no
    30 t
    31 where act_no = 0 or (id = 1 and act_no = 1)
    (32) t1
    33 on t.id = t1.id
    order of 34
    35 by id;

    ID ACT_NO TO_BE
    ---------- ---------- ----------


    1          1          1
    2          0          2
    3          1          2
    4          1          2
    5          0          3
    6          1          3
    7          0          4
    8          1          4
    9          1          4
    10          1          4
    11          0          5
    12          1          5
    13          1          5
    14          1          5
    15          1          5
    16          1          5

    16 selected lines.

    SQL >

  • Delete the name of the column in the CSV file generated by ODI

    Hello

    I want to remove the column names in the CSV file that I create the database.
    I tried to put "towards zero in the data store ', that I created for the csv file, but it does not work.

    Please help.

    Thank you
    Sudeep Nathalie

    Sudeep salvation,

    Ok.. If you don't want the column to be generated and then in your IKM (IKM SQL to THE grit file) choose the option GENERATE_HEADER to 'no '.

    Then run the interface. The target csv file will not now column header.

    Thank you
    Fati

  • Generate the DDL - change is a new column and I want to generate an alter table.

    All, morning

    I searched and searched all over the Data Modeler and I can't find this option... but I found it easily in the designer.
    I hope you can help me.

    V3.0.0.665 SQL Developer Data Modeler.

    I added a new column to a table, and when I generate the DDL I wish it were an alter table add column rather than a table to create.
    This feature is in the designer, so I think it would be in the Data Modeler.

    Just in case my description isn't clear, here are the high level steps, then it is clear.

    1 create logic model
    2. create the relational logic.
    3. create the physical relationship.
    4 generate the DDL and run in the database. At this point, I'm going to production with my system, and all right.
    5. at this point, we have an enhancement request. For the model, it will be a new column in a table.
    6. update of the logic model.
    7. relational update logic
    8 physical update of relational
    9 generate the DDL. Here, I would have generate it know that it needs to generate an alter table add column and does not create the table.
    This is something I do a lot as all my models are in production. I can't find how to do this step to get data Modeler to generate the altar.
    Designer done exceptionally well.

    Quite often, it is more than a single column. Changes can be many and made over time and at the time of generating the DDL you remember not every single amendment. To have the tool discover these changes for you and generate the appropriate DDL is a feature that I consider as very high.

    I hope that is clear and you can help me.

    See you soon
    Chris...

    Hi Chris,

    you need to compare your model on database - database relational model even import and use the option 'swap target' - in this case 'expressions of alter' against the database will be generated.
    You can watch demonstrations here http://www.oracle.com/technetwork/developer-tools/datamodeler/demonstrations-224554.html
    It would probably be more useful http://download.oracle.com/otn_hosted_doc/sqldev/importddl/importddl.html
    Sooner or later your changes will require the table to be recreated, and you will need to backup your data - you can consider using the 'Advanced DDL' option - script is generated that will land your table content (including LOBs) to the system of files accessible from the database and restore after changes. Well not try directly on the production system :).

    Philippe

Maybe you are looking for

  • What a mistake it's answer to 'Blocked Redirect'?

    I don't like the message that Firefox has prevented the redirect and was looking for a way to turn it off. These forums provided a (supposedly) definitive answer. But how bad is it: Here is where it's at: https://support.Mozilla.org/en-us/questions/8

  • Family safety reports coming in Hindi (not my language)

    Hello I'm getting reports of parental control in Hindi and I don't have defined Hindi language in none of my preferences. I checked for all possible areas where a language option is there and everywhere I have only English. My email (the id of the pa

  • Hello - problem with wrt54gl

    Hello. I have two problems with this router. 1. I can not log in with the user name and password provided by my internet provider. I can't log in to the user interface of stock, I install tomato or dd wrt to be able to connect. 2. I can't reach speed

  • How to hide all the empty fields on a page?

    HelloI want to hide all the empty fields but to exclude tables as it messes up the table. He hides this empty cell with borders and the table does not look right.My script below works currently it hides all the empty fields on this page.Is it possibl

  • Height of page too long

    I am new to Muse. I use a Mac with OS Mavericks and Muse CC 2014.2.I created a blank page (960 x 500) with a dark background around it (filling of the browser). It looks fine in Design mode, but seen in preview the blank page is far too long and exte