Compound trigger returns too many lines

Hi all.
I have created a compound trigger which executes a procedure. Although the trigger now runs (I was getting a mutating table error before), it returns multiple lines where I am expecting only one line. When I run the procedure by itself, without the trigger, it runs as expected. Truth is, I created the trigger based on an example I found online, and I am not sure how to modify it to my needs. I don't need the data I am generating in the AFTER EACH ROW section. It exists because the trigger doesn't seem to run otherwise. Any help would be highly appreciated.
create or replace trigger test.requisitions_trigger
  FOR INSERT OR UPDATE ON test.supply_items
COMPOUND TRIGGER
TYPE t_change_tab IS TABLE OF test.tab1_audit%ROWTYPE; g_change_tab t_change_tab := t_change_tab();
AFTER EACH ROW IS
BEGIN
  g_change_tab.extend;
  IF INSERTING THEN
    g_change_tab(g_change_tab.last).action := 'INSERT';
  ELSE
    g_change_tab(g_change_tab.last).action := 'UPDATE';
  END IF;
  g_change_tab(g_change_tab.last).created_time := SYSTIMESTAMP;
END AFTER EACH ROW;
AFTER STATEMENT IS
BEGIN
  test.Requisitions;
END AFTER STATEMENT;
END requisitions_trigger;

In your Re: Mutating Table error - Compound Trigger, the REQUISITIONS procedure was taking an argument that was taken from the row being inserted or updated. In this version, there is no argument. If the REQUISITIONS procedure takes no arguments (and just to harp on it, I'll reiterate that having a table and a procedure with the same name is more than a bit confusing), then you just need a statement level trigger. A statement level trigger is free to query the table being modified all it likes without raising any mutating table concerns (because the current statements changes are either guaranteed to have not been applied or to have been completely applied, there is no risk of seeing data in an inconsistent state).
Justin

Similar Messages

  • Too many lines for CO-PA assessment postings in KSB1

    Hi Experts,
    I created an assessment cycle in KEU1, with one segment, using an PA transfer structure (several cost elements to several value fields), and I´m using one single secondary cost element (category 42) to credit the cost centers.
    When I execute the assessment via KEU5, the credits in the cost centers for the cost element category 42 generates too many lines (for example, I had 3 postings to 3 primary cost elements and in KSB1 I have 9 lines of "credits" - operation KSPA.):
    Primary Cost Elements:
    4110201004  ==> 3.000,00
    4110209009  ==> 2.000,00
    4110209013  ==> 1.000,00
    Secondary cost element (after settlement through KEU5):
    6519999999 ==> 134,36-
                                198,92-
                                190,49-
                                291,54-
                                548,27-
                                311,88-
                                2.659,89-
                                1.268,02-
                                396,63-
    Do you know how can I summarize this postings to have only 3 (ore one) line for the secondary cost element? I cannot identify what was the criteria used by SAP to generate 9 lines.
    Kind Regards
    Mayumi

    the number of line item crediting the cost centre, shall be the same of the line item required in the COPA posting. So the more receiver you have in COPA , the more line item are created.
    Paolo

  • Huge Conversion File - Too many lines

    Hi Experts,
    Is there any way to split a Conversion File?
    I have a Conversión file with too many lines, so when I save it, it takes a lot of time, (11.000 rows, more than half an hour) and sometimes the Excel hand up (froze).
    It is becaming a problem, because everytime I save the Conversion file, I can not use the excel for a while.
    Any idea?
    Thanks in advance.
    Iria

    Iria and Patrick,
    I want to give an information about this.
    BPC transformation file can be multiple steps in one file.
    For example,
    *Options
    *Transformation
    *Conversion
    *Options
    *Transformation
    *Conversion
    *Options
    *Transformation
    *Conversion
    Therefore, If you only has a problem with conversion, you can do it as below
    *Options
    *Transformation
    *Conversion
           conversion part1    
    *Options
    *Transformation
    *Conversion
           conversion part2    
    *Options
    *Transformation
    *Conversion
           conversion part3    
    Note 1 :  If you don't need multiple transformation, you only need to specifiy it in the first transformation.
    Note 2 :  Conversion file can have multiple Tabs in one conversion excel workbook but I am not sure about the performance
                  when you do that. So please try two things.
                       1. Split it into multiple worksheet
                       2. Split it into multiple workbooks.
                  Please update your result for others.
    Note3 : You don't need multiple Convert task, it will be executed in a convert task.
    I hope it will help you
    Thank you.
    James Lim
    Edited by: James Lim on Mar 4, 2010 4:31 PM

  • Too many lines

    When opening an excel file I received as an attachment, and I want to open in Numbers, I either get major lag in viewing the workbook and editing it, Or I receive a message that an error occurred because there are "too many lines" and the workbook won't even import to Numbers
    I have a "New" IPad 3rd gen.
    Apple told me it is because I only have 512ram, but I understood that the new iPad had 1gb?
    Is numbers just not strong enough?
    Also, when I do get files to import, fonts, formulas and formats are commonly not supported and it negates being able to use the ipad to work on a workbook remotely and send it forward.
    Are ther any fixes?

    this is the oracle forms forum. your chances increase going to the right forum.
    Gerd

  • ExecuteQueryForObject returned too many results jdbc error

    Hi All,
    I am getting the following error on running the tomcat 6.0 and I have Oracle 11g installed.
    08 Dec 2010 16:23:41 ERROR [QUARTZ_Worker-5] org.quartz.core.JobRunShell - Job DCTM.DCTMServerPipe threw an unhandled Exception:
    org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Error: executeQueryForObject returned too many results.; nested exception is java.sql.SQLException: Error: executeQueryForObject returned too many results.
         at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:121)
         at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
         at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
         at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
         at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:265)
         at com.emc.documentum.bpm.daos.impl.AbstractIbatisBaseDaoImpl.queryForObject(AbstractIbatisBaseDaoImpl.java:119)
         at com.emc.documentum.bpm.bamengine.daos.impl.ServerConfigDaoImpl.getDBCurrentTime(ServerConfigDaoImpl.java:28)
         at com.emc.documentum.bpm.bamengine.services.server.factory.impl.ServersFactoryImpl.updatePipeServerTimezoneOffset(ServersFactoryImpl.java:56)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
         at $Proxy50.updatePipeServerTimezoneOffset(Unknown Source)
         at com.emc.documentum.bpm.bamengine.services.sharedservices.impl.TaskManagerServiceImpl.executePipe(TaskManagerServiceImpl.java:341)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
         at $Proxy52.executePipe(Unknown Source)
         at com.emc.documentum.bpm.bamengine.scheduler.impl.PipeJobImpl.execute(PipeJobImpl.java:17)
         at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
         at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
    Caused by: java.sql.SQLException: Error: executeQueryForObject returned too many results.
         at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:124)
         at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
         at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
         at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
         at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
         at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
         ... 23 more
    How can this be resolved? Please help !!
    Thanks, T
    Edited by: 805903 on Dec 9, 2010 3:00 AM

    Error executeQueryForObject returned too many results
    Typical Error msg:
    “SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Error: executeQueryForObject returned too many results.; nested exception is java.sql.SQLException: Error: executeQueryForObject returned too many results”
    The error is caused for using queryForObject (for a single result) instead of queryForList (when expecting multiple results).
    Example of correct solution
    In DAO:
    public List<UpdatedContractRateDO> getUpdatedCtrctRate(Map paramMap) throws DataAccessException {
    return (List<UpdatedContractRateDO>) getSqlMapClientTemplate().queryForList("charge.getUpdatedCtrctRate", paramMap);
    }

  • ExecuteQueryForObject returned too many results.

    Hi,
    My servlet accesses an Oracle db, it works fine most of the time except for when I search for one particular entry.
    When I do this the following error message is displayed:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Error: executeQueryForObject returned too many results.
         org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
         org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
         org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
         org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    java.sql.SQLException: Error: executeQueryForObject returned too many results.
         com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:108)
         com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:561)
         com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:536)
         com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:93)
         com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:70)
         com.bmw.urt3fms.cardata.ctrl.SearchCarAction.execute(Unknown Source)
         org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
         org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
         org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
         org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    This is really strange as all the other searches I have done all worked except this one.
    Any ideas as to why it would display this??
    Nick

    Error executeQueryForObject returned too many results
    Typical Error msg:
    “SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Error: executeQueryForObject returned too many results.; nested exception is java.sql.SQLException: Error: executeQueryForObject returned too many results”
    The error is caused for using queryForObject (for a single result) instead of queryForList (when expecting multiple results).
    Example of correct solution
    In DAO:
    public List<UpdatedContractRateDO> getUpdatedCtrctRate(Map paramMap) throws DataAccessException {
    return (List<UpdatedContractRateDO>) getSqlMapClientTemplate().queryForList("charge.getUpdatedCtrctRate", paramMap);
    }

  • Too many lines in my log file

    Hy every body,
    I've made a Tomcat project under Eclipse and I'm using log4j.
    I've configured my log4j in "log4j-config.xml" file.
    I've made one file per level (DEBUG, INFO, WARN and ERROR), but I'm receiving too many lines in my "debug.log" file.
    Example:
    17:52:39 - [main] [DEBUG] org.apache.commons.beanutils.BeanUtils : BeanUtils.populate(org.apache.struts.tiles.TilesPlugin@14d556e, {definitions-parser-validate=true, definitions-parser-details=2, definitions-debug=2, moduleAware=true, definitions-config=/WEB-INF/struts/struts-tiles-defs.xml})
    17:52:39 - [main] [DEBUG] org.apache.commons.beanutils.BeanUtils : setProperty(org.apache.struts.tiles.TilesPlugin@14d556e, definitions-parser-validate, true)
    17:52:39 - [main] [DEBUG] org.apache.commons.beanutils.BeanUtils : setProperty(org.apache.struts.tiles.TilesPlugin@14d556e, definitions-parser-details, 2)
    Can some one tell me how to filter my logs.
    Here is a part of my "log4j-config.xml" file:
    <appender name="DEBUG" class="org.apache.log4j.FileAppender">
              <param name="File" value="${log.path}/debug.log" />
    <param name="Threshold" value="DEBUG" />
    <param name="Append" value="false" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{HH:mm:ss} - [%t] [%-5p] %c : %m%n" />
    </layout>
         </appender>
    Thanks in advance.

    Hy every body,
    I've made a Tomcat project under Eclipse and I'm
    using log4j.
    I've configured my log4j in "log4j-config.xml" file.
    I've made one file per level (DEBUG, INFO, WARN and
    ERROR), but I'm receiving too many lines in my
    "debug.log" file.Then don't use that level. The whole point of the various levels is to be able to trade off level of detail for volume of output. Debug is meant to be very verbose.
    You can set various classes or packages to log at different levels, overriding the default for that logger. So if you don't want debug output for com.acme.whatever, then in log4j.properties or log4j.xml or whatever, you can configure that package and all "subpackages" for info, warn, or error. See log4j's docs for details.

  • Texts keep getting returned--too many digits error, pls help

    Hi, everyone!
    I upgraded to 4.3.3, yesterday so far no problems, except this morning my phone started to send me an error message every time I send a text and says "this message could not be sent, you've entered too many digits." How do I fix this? And the number it shows is an 11-digit number because it adds the 1...
    Does anyone know what I can do?

    Error executeQueryForObject returned too many results
    Typical Error msg:
    “SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Error: executeQueryForObject returned too many results.; nested exception is java.sql.SQLException: Error: executeQueryForObject returned too many results”
    The error is caused for using queryForObject (for a single result) instead of queryForList (when expecting multiple results).
    Example of correct solution
    In DAO:
    public List<UpdatedContractRateDO> getUpdatedCtrctRate(Map paramMap) throws DataAccessException {
    return (List<UpdatedContractRateDO>) getSqlMapClientTemplate().queryForList("charge.getUpdatedCtrctRate", paramMap);
    }

  • Too Many Line Items While Creating a PO

    Dear All,
    Here we have a scenario:
    We are creating a PO which is having around 10000(ten thousand) line items, and while saving system is showing error message "Too Many PO Line Items" Message No: FI899. and not able to save it.
    Kindly Let me know is there any limit for line item creation in a PO.
    Regards,
    Ravi B

    Limitations are limitations, you need a workaround or pay SAP for an extra developement. Probably worth, if you have such POs everyday.
    ( I cannot even imagine for what reason a PO should have more than 10000 items. Manual maintenance is impossible, the person would sit for a week and more to finish one PO. the CSR at your vendor is as well not able to put the items from your PO into their Sales order within a reasonable time frame - order entry should be ready before delivery date is arrived.
    This sounds like you want buy a company and want create just one purchase order to buy any single material they have on stock. But for that purpose the PO is certainly not designed.
    Can you give more background that makes my mind open ?   )

  • SQL subquery returning too many rows with Max function

    Hello, I hope someone can help me, I been working on this all day. I need to get max value, and the date and id where that max value is associated with between specific date ranges. Here is my code , and I have tried many different version but it still returning
    more than one ID and date
    Thanks in advance
    SELECT
      distinctbw_s.id, 
    avs.carProd,cd_s.RecordDate,
    cd_s.milkProductionasMilkProd,
    cd_s.WaterProductionasWaterProd
    FROMtblTestbw_s
    INNERJOINtblTestCpcd_sWITH(NOLOCK)
    ONbw_s.id=cd_s.id   
    ANDcd_s.recorddateBETWEEN'08/06/2014'AND'10/05/2014'
    InnerJoin
    (selectid,max(CarVol)ascarProd
    fromtblTestCp
    whererecorddateBETWEEN'08/06/2014'AND'10/05/2014'
     groupby 
    id)avs
    onavs.id=bw_s.id
    id RecordDate carProd       MilkProd WaterProd
    47790 2014-10-05   132155   0 225
    47790 2014-10-01   13444    0 0
    47790 2014-08-06   132111    10 100
    47790 2014-09-05   10000    500 145
    47790 2014-09-20   10000    800 500
    47791 2014-09-20   10000    300 500
    47791 2014-09-21   10001    400 500
    47791 2014-08-21   20001    600 500
    And the result should be ( max carprod)
    id RecordDate carProd       MilkProd WaterProd
    47790 2014-10-05   132155  0 225
    47791 2014-08-21   20001    600 500

    Help your readers help you.  Remember that we cannot see your screen, do not know your data, do not understand your schema, and cannot test a query without a complete script.  So - remove the derived table (to which you gave the alias "avs")
    and the associated columns from your query.  Does that generate the correct results?  I have my doubts since you say "too many" and the derived table will generate a single row per ID.  That suggests that your join between the first
    2 tables is the source of the problem.  In addition, the use of DISTINCT is generally a sign that the query logic is incorrect, that there is a schema issue, or that there is a misunderstanding of the schema. 

  • Pl/Sql block returning too many values

    Hi
    Below is simple pl/sql block.while excecuting this i'm getting too many values exception
    declare
    attrib QW_ACCT_ATTR%ROWTYPE;
    begin
    SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL INTO attrib FROM (SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL FROM QW_ACCT_ATTR where CUST_ACCT_ID='5158660414' AND ATTR_NM = 'SS' ORDER BY ATTR_END_DATE DESC) where rownum = 1;
    DBMS_OUTPUT.PUT_LINE('end daate is...'||attrib.ATTR_END_DATE);
    end;
    could anybody please help me how to rewrite this qwery to get only one record.
    we are not supposed to use cursors here,
    thanks

    I am just changing your logic,
    declare
    attrib QW_ACCT_ATTR%ROWTYPE;
    begin
    SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL INTO attrib FROM (SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL FROM QW_ACCT_ATTR where CUST_ACCT_ID='5158660414' AND ATTR_NM = 'SS' ORDER BY ATTR_END_DATE DESC where rownum = 1) ;
    DBMS_OUTPUT.PUT_LINE('end daate is...'||attrib.ATTR_END_DATE);
    end;

  • JDO: Query returns too many results.

    Hello,
    I want to get some DO-Entities from an empty table. When I execute the query I retrieve more than 2 000 000 000 results what is definitly too much for an empty table. The DO has an one-to-many relationship to another class and a many-to-one relationship to another one.
    The .map and .jdo files of the class and the classes in relation made accordng to the explanations in the Development Manual chapter "Mapping Persistent Classes to Database Tables" (so including DFG- and embedded- attributes). Enhancing is successfull and the work with the classes that doesn't have relationships also.
    The query looks like this:
                   manager = getPersistenceFactory().getPersistenceManager();
                   String filter = "version == \"" + version + "\" && postingLevel == \"" + postingLevel +
                                       "\" && closingPeriod == " + closingPeriod + " && bunit== \"" + bunit + "\"";
                   Query query = manager.newQuery(AD_DO_Protocol.class, filter);
                   Collection col = (Collection) query.execute();
    I also tried to use the extent with the same result.
    Any ideas?
    Regards,
    Jan

    Hi Guru,
    first of all in that certain method of the DAO I'm not able to use the primary key because I implement a check if an entity with the given attributes allready exists.
    Second I don't want (and as I think don't have) to write the mentioned java function for the following reason: There must be max one result for the given query. Thats a constraint implied by our business logic.
    In fact at the given moment there must not be a single result because the table IS EMPTY!!!
    Any other ideas?
    Thx and regards,
    Jan

  • CO 1SRJ-001: Too many line items selected via report interface

    Report group/report 1SRJ/1SRJ-001 (CCentres: Rolling Year):  provides an overview for the last 12 periods of actual and plan data.
    When you access line item report RKAEP000 (KSB1 or KSBP) from report Cost Centres Rolling Year (1SRJ-001) using the report/report interface, too much data is selected.
    For example, you enter fiscal year 2009 and month 8 in selection parameters, the report generates results for the last 12 periods:  2008/9 to 2009/8.  But the line item report accessed via report interface selected ALL data for the fiscal years 2008 and 2009.
    I searched and found Note 127643 that described a similar but not exactly the same situation.  Have anyone have any problems with this report?  Any suggestion is appreicated.
    Regards,

    Issue with report 1SRJ-001 (S_ALR_87013631) has been resolved.  The interfaced line item report selects all data records for fiscal years 2008 and 2009, instead of just for the selected last 12 months.  The problem is due to missing restrictions for a characteristic, in this case, the from-period and to-period fields.
    SAP has corrected the problem by issuing an updated version (1999) and the one we were using was the 1995 version.  I imported the updated version of report from client 000 and now it works fine.

  • Left join and where clause with not equal ( ) returns too many rows

    Say I have something like this
    Table A
    =========
    Id
    OrderNum
    Date
    StoreName
    AddressKey
    Table B
    ========
    Id
    StreetNumber
    City
    State
    select a.* from [Table A] a
    left join [Table B] b on a.AddressKey = b.Id
    where a.StoreName <> 'Burger place'
    The trouble is that the above query still returns rows that have StoreName = 'Burger place'
    One way Ive handled this is to use a table expression, select everything into that, then select from the CTE and apply the filter there.  How could you handle it in the same query however?

    Hi Joe,
    Thanks for your notes.
    INT SURROGATE PRIMARY KEY provides a small footprint JOIN ON column. Hence performance gain and simple JOIN programming.  In the Addresses table, address_id is 4 bytes as opposed to 15 bytes san. Similarly for the Orders table.
    INT SURROGATE PRIMARY KEY is a meaningless number which can be duplicated at will in other tables as FOREIGN KEY.  Having a meaningful PRIMARY KEY violates the RDBMS basics about avoiding data duplication.  If I make CelebrityName (Frank Sinatra)
    a PRIMARY KEY, I have to duplicate "Frank Sinatra" as an FK wherever it needed as opposed to duplicating SURROGATE PRIMARY KEY CelebrityID (79) a meaningless number.
    This is how we design in SQL Server world.
    QUOTE from Wiki: "
    Advantages[edit]
    Immutability[edit]
    Surrogate keys do not change while the row exists. This has the following advantages:
    Applications cannot lose their reference to a row in the database (since the identifier never changes).
    The primary or natural key data can always be modified, even with databases that do not support cascading updates across related
    foreign keys.
    Requirement changes[edit]
    Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:
    An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies
    were separate).
    In these cases, generally a new attribute must be added to the natural key (for example, an
    original_company column). With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.
    Some problem domains do not clearly identify a suitable natural key. Surrogate key avoids choosing a natural key that might be incorrect.
    Performance[edit]
    Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore a non-redundant distribution of keys causes the resulting
    b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than
    compound keys.
    Compatibility[edit]
    While using several database application development systems, drivers, and
    object-relational mapping systems, such as
    Ruby on Rails or
    Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.
    Uniformity[edit]
    When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.
    Validation[edit]
    It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to "look differently from"
    those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic
    of the applications themselves, as this would violate the principles of
    Database normalization"
    LINK: http://en.wikipedia.org/wiki/Surrogate_key
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • PL/SQL problem with too many lines - can not apply changes

    I have a complex PL/SQL that requires checking 90 check boxes and the query works to a certain point then it just stops being able to be saved (apply changes) after a high no. of lines has been typed in. (The PL/SQL query is to check against a file, that the file has all the check boxes as yes. If there is only 1 or 2 boxes checked, then the sql created only checks those 2 fields for yes.) Is there a way to increase the coding space (or number of lines) that APEX can save/use.

    This is the whole PL/SQL coding. At this point, we cannot add any more lines or it will come up with "web page cannot be found" message.
    declare
    q varchar2(32767); -- query
    new varchar2(1):='Y'; -- first one
    begin
    q := 'select a."CONTR_ID", a."NAME", b."PHONE_NO", b."EMAIL_ADDR" FROM contractor a, contacts b where a.contr_id = b.contr_id and a.contr_id not in (Select unique a."CONTR_ID" from contractor a, contractor_competency b where a."CONTR_ID" = b."CONTR_ID" ';
    -------------------Start ENV
    if :P33_AIR_QUALITY_TESTING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Air Quality Testing'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_ASBESTOS_REMOVAL_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Asbestos Removal De-Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_ASBESTOS_REMOVAL_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Asbestos Removal Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_BUILDING_ASBESTOS_REMOVAL = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Building Asbestos Removal'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_ENVIRONMENTAL_CONSULTING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Environmental Consulting'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_MANHOLE_ASBESTOS_REM_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Manhole Asbestos Removal De-Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_MANHOLE_ASBESTOS_REM_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Manhole Asbestos Removal Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_OIL_FILTERING = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Oil Filtering'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_OIL_SAMPLING = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Oil Sampling'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_OIL_SPILL_CLEANUP = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Oil Spill Cleanup'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_PUMPING_OUT_MANHOLES = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Pumping Out Manholes'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_SIGNED_ENVIRO_DOCS = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Signed Enviro Docs PRO-MS-008'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_TRANSPORTATION_OF_D_GOODS = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Transportation of Dangerous Goods'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_TRANSPORTATION_OF_PCB = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Transportation of PCB'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_WASTE_PICK_UP = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Waste Pick-Up'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    -------------------- start OCM
    if :P33_GREENFIELD_POLELINE_CONST = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Greenfield Poleline Construction'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_HV_OVERHEAD_MAINTENANCE = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''HV Overhead Maintenance'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_INSULATOR_WARNING = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Insulator Warning'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_LV_OVERHEAD_MAINTENANCE = 'YES' then
    if new = 'Y' then q := q || ' and (';
    new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''LV Overhead Maintenance'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_OVERHEAD_INFRARED_SCAN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Overhead Infrared Scanning'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_POLEHOLES_AND_ANCHORS = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || ' (instr(upper(b."JOB"),upper(''Poleholes and Anchors'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_POLELINE_INSPECTION = 'YES' then
    if new = 'Y' then q := q || ' and( '; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || ' (instr(upper(b."JOB"),upper(''Poleline Inspection'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_POLELINE_WORK_TO_35KV = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || ' (instr(upper(b."JOB"),upper(''Poleline Work to 35KV'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_POLELINE_TO_44KV = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || ' (instr(upper(b."JOB"),upper(''Poleline to 44KV'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_ROCK_DRILLING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Rock Drilling'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_TENSION_STRINGING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || ' (instr(upper(b."JOB"),upper(''Tension Stringing'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_TREE_TRIMMING_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Tree Trimming (De-Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_TREE_TRIMMING_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Tree Trimming (Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_WOOD_POLE_TESTING_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Wood Pole Testing De-Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_WOOD_POLE_TESTING_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Wood Pole Testing Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    ------------------ start UCM
    if :P33_CO2_CLEANING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''CO2 Cleaning'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_CABLE_PULLING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Cable Pulling'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_CABLE_TESTING_DEENERGIZED = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Cable Testing De-Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_CABLE_TESTING_ENERGIZED = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Cable Testing Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_CONC_DUCT_MAN_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Conc. Duct & Manhole (De-Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_CONC_DUCT_MAN_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Conc. Duct & Manhole (Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_DIR_BURIED_DUCT_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Direct Buried (De-Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_DIR_BURIED_DUCT_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Direct Buried (Energized)'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_DIRECTIONAL_BORING_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Directional Boring De-Energized'')) > 0) and
    ((instr(upper(b."SET_YES_NO"),''NO'') > 0) or
    (instr(upper(b."CRAFTMAN_YES_NO"),''NO'') > 0) and
    (instr(upper(b."PROBATION_YES_NO"),''NO'') > 0)) ';
    end if;
    if :P33_DIRECTIONAL_BORING_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Directional Boring Energized'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_GENERAL_EXCAVATION = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''General Excavation Around Plant'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_HV_UG_MAINTENANCE = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''HV Underground Maintenance'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_LV_UG_MAINTENANCE = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''LV Underground Maintenance'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_MANHOLE_CLEANING_DEEN = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Manhole Cleaning De-Energized'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_MANHOLE_CLEANING_ENER = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Manhole Cleaning Energized'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_MANHOLE_INSPECTION = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Manhole Inspection'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_UG_EQUIPMENT_INSPECTIONS = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''UG Equipment Inspections'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_UG_INFRA_RED_SCANNING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''UG Infra Red Scanning'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_UG_CABLE_LOCATES = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Underground Cable Locates'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    ------------------------ start SCM
    if :P33_FENCING_AROUND_SUBSTATION = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Fencing Around Substation'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_FENCING_GREENFIELD = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Fencing Greenfield'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_INSPECTION_AND_TESTING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Inspection And Testing'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_STATION_CIVIL_WORK = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Station Civil Work'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_STATION_CONST_DEENERGIZED = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Station Construction (De'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_STATION_CONST_ENERGIZED = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Station Construction (E'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_STATION_INFRARED_SCANNING = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Station Infrared Scanning'')) > 0) and
    (instr(upper(b.”SET_YES_NO”),''NO'') > 0) ';
    end if;
    if :P33_STATIONS_ASBESTOS_REMOVAL = 'YES' then
    if new = 'Y' then q := q || ' and ('; new := 'N';
    else
    q := q || ' or '; end if;
    q := q || '(instr(upper(b."JOB"),upper(''Stations Asbestos Removal'')) > 0) and
    (instr(upper(b."SET_YES_NO"),''NO'') > 0) ';
    end if;
    if new = 'N' then q := q || ' ) ';
    end if;
    q := q || ' ) ';
    return q;
    end;

Maybe you are looking for