Hey Guys, I've started a website of my own and will be publishing articles there moving forward.
Take a look if you're interested: www.migsisip.com/
Thanks for all your support throughout the years!
Hey Guys, I've started a website of my own and will be publishing articles there moving forward.
Take a look if you're interested: www.migsisip.com/
Thanks for all your support throughout the years!
From my experience, research and general knowledge, Dynamic SQL should be avoided as much as possible,
There are multiple reliable sources that say this, even Oracle’s revered top DBA, Tom Kyte, and Oracle’s own PL/SQL Evangelist and Oracle ACE, Steven Feuerstein has mentioned this multiple times in AskTOM and Oracle Blogs.
To list some of the disadvantages of Dynamic SQL (from research and my own inputs):
It cannot be detected by the Oracle Enterprise Manager to have bad statistics because it is not parsed before it is run. It’s basically invisible to the DB parser.
The query this is not being “recorded” in the pool, therefore, we cannot predict if this certain piece of code will perform badly or not, we cannot quantify its statistics.
There are great efficiencies to be gained by using static sql, as PLSQL will cacheopen cursors and reuse statements, even before they are run.
Dynamic SQL is not scalable. Static SQL is scalable.
Does not really have any big advantage over static SQL apart from being “flexible”, but the disadvantages greatly outweighs these advantages.
It’s actually not true that Dynamic SQL performs better, in fact: dynamic SQL is more complex than static SQL, it executes more slowly than static SQL. Especially when done wrong.
We should Re-use code whenever possible, but only when that is appropriate. And I believe we can re-use code without doing Dynamic SQL. Do we REALLY need that SQL to be dynamic?
Dynamic SQL is only really considered when we don’t know what parameters are used before runtime, something like in OBIEE, where the user will be the one to input the columns they want and need, then run the query.
I believe we can re-write these programs to use fixed, structured, and static queries instead.
Dynamic SQL is prone to SQL-Injection in General. I don’t know if there will be a time where we will encounter this issue, but it will be a huge mess if it does happen.
Personally, I find them extremely hard to debug, hard to read, and impractical because we only find out the actual query at runtime.
We cannot see the dependencies between programs because as I mentioned, they are invisible and only appear during runtime.
It will be hard to see which programs get impacted when we change a certain code, which in turn, will result in another bug, etc.
I can list down more Pros and Cons, but I believe these are
enough details to establish that the disadvantages of Dynamic SQL outweighs the
advantages.
I strongly urge that our dev teams start to write Static SQL
instead of Dynamic SQL.
To be edited further...
Structured Query Language (SQL) is basically a language for storing, manipulating and retrieving data in databases. Although there are a lot of “flavors” of SQL (MySQL, SQL Server, MS Access, Oracle, Sybase, Informix, Postgres). The American National Standards Institute (ANSI) has set a standard in 1986 that most RDBMS’s employ.
While most simple SQL Queries are straight-forward and quick to execute, there are instances wherein we experience a slowness in the query execution. In this deck, we will explore, identify and address the numerous factors that come into play in this performance degradation.
The target audience of this deck would be individuals with sufficient experience in writing SQL queries and have sufficient knowledge in Database Fundamentals.
You should be able to:
Two Words: Optimum Performance!
When the underlying SQL is Tuned effectively, The PL/SQL program is tuned as well! I know what you’re thinking:
“Isn’t there an automatic way to Tune SQL?”
“If that’s the case, then what’s the solution?”
Ideally, the time we develop code is the time we need to consider efficient and fast queries.
However, if it is unavoidable for the objects have already been existing for some time, tuning is still possible. Consider tuning when the following occurs:
Before doing the actual work of tuning a script, one needs to know first the environment. This is highly important as this will lead you to the use best approach for the current problem at hand and ensuring that it doesn’t happen in the future.
Below are the things you need to know before turning the script.
Below are my personal guidelines on how to tune SQL scripts:
Using the Oracle Enterprise Manager (OEM)
Using the Dynamic Performance Views such as v$SQL and v$SQL_PLAN
Oracle uses the Cost Estimator, to estimate the resources that will be used to execute a given query using the following measurements:
These three are very important for the estimator in figuring out how to map the Explain Plan, what access paths to be used and what Indexes should be used to execute the query.
By definition: An index is a schema object that contains an entry for each value that appears in the indexed column(s) of the table or cluster and provides direct, fast access to rows.
Oracle Database supports the following indexes:
Access Paths (aka Execution Paths), is basically the "road" that the parser plans to traverse to execute the query script, step-by-step.
An Access Path is shown inside an Explain plan. Treat Explain Plan as the Map, and the Access Path as the Road.
Depending on your various factors (i.e. Tables, Complexity, Database Parameters), the Explain plan will show you the recommended approach the parser will use to execute your query.
There are multiple types of Access Paths, as listed below:
Application
|
Job Role Name
|
Financial Reporting Compliance
|
Enterprise Risk and Control Manager
|
Financial Reporting Compliance
|
Compliance Manager
|
Advanced Financial Controls
|
Application Control Manager
|
Advanced Access Controls
|
Application Access Manager
|
In most cases, most Organizations would want to customize their Dunning Letters Templates to reflect their Organization branding and modify the words used. During the development process, developers would want to test out the look of the customized Dunning Letter Templates and thus, would need to run The "Send Dunning Letter" scheduled process in "Draft Mode". The Dunning Letter Program has two parameters that is responsible for running Dunning Letters in Draft:
- Draft Mode - indicates if the Dunning Letters are run in Final or Draft Mode (Required. Allowed values are Yes and No).
The problem with this program is that when Dunning Letters is run in "Draft Mode" without an email address, Dunning Letters would generated and sent out to actual Customer Site Contacts. This defeats the purpose of having a "Draft Mode".
- Email Address - Indicates the specified email address would receive the generated Draft Dunning Letters (optional).
The expectation of running the report in Draft Mode would be:
- If the email address parameter was supplied, the process would send all Dunning Letters to the specified email address.
- If the email address parameter was NOT supplied, the generated dunning letters can be downloaded them from the application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | select ACCT.ACCOUNT_NUMBER , hps.party_site_number , ACCT.CUST_ACCOUNT_ID --, 'DEFAULT' SET_CODE , STID.SET_CODE , custprof.CLEARING_DAYS , custprof.CREDIT_BALANCE_STATEMENTS , custprof.CREDIT_CHECKING , custprof.CREDIT_HOLD , custprof.PROFILE_CLASS_ID , decode(custprof.DISCOUNT_TERMS, 'N', NULL, custprof.DISCOUNT_GRACE_DAYS) DISCOUNT_GRACE_DAYS , custprof.DISCOUNT_TERMS , 'Y' DUNNING_LETTERS , custprof.EFFECTIVE_START_DATE , custprof.EFFECTIVE_END_DATE , custprof.LAST_CREDIT_REVIEW_DATE , custprof.NEXT_CREDIT_REVIEW_DATE , custprof.OVERRIDE_TERMS , HP.PARTY_ID , custprof.PERCENT_COLLECTABLE , custprof.SEND_STATEMENTS , custprof.TOLERANCE , coll.NAME CollectorName , custprof.EXCHANGE_RATE_TYPE , RTM.name PaymentTerms , custprof.AUTOCASH_HIERARCHY_ID , null ApplicationExceptionRuleSet , aar.Name AutoMatchRuleSet , custprof.AUTOCASH_HIERARCHY_ID_FOR_ADR , cyc.NAME StatementCycle , grp.name GroupingRule , custprof.CREDIT_CLASSIFICATION , custprof.ACCOUNT_STATUS , custprof.RISK_CODE , custprof.CREDIT_RATING , custprof.CONS_BILL_LEVEL , custprof.CONS_INV_TYPE , custprof.LOCKBOX_MATCHING_OPTION , replace(custprof.PREF_CONTACT_METHOD, 'EMAIL', 'E-Mail') PREF_CONTACT_METHOD , replace(custprof.TXN_DELIVERY_METHOD, 'EMAIL', 'E-Mail') TXN_DELIVERY_METHOD , custprof.PRINTING_OPTION_CODE , custprof.MATCH_BY_AUTOUPDATE_FLAG , custprof.AUTO_REC_INCL_DISPUTED_FLAG , custprof.CONS_INV_FLAG , NULL CREDIT_REVIEW_CYCLE , custprof.CREDIT_ANALYST_ID , custprof.CREDIT_LIMIT , custprof.CREDIT_CURRENCY_CODE , replace(custprof.STMT_DELIVERY_METHOD, 'EMAIL', 'E-Mail') STMT_DELIVERY_METHOD , custprof.ORDER_AMOUNT_LIMIT from HZ_PARTIES hp JOIN HZ_PARTY_SITES hps on HPS.PARTY_ID = HP.PARTY_ID JOIN HZ_CUST_ACCOUNTS ACCT on ACCT.PARTY_ID = HP.PARTY_ID JOIN HZ_CUST_ACCT_SITES_ALL ACTS ON (ACTS.CUST_ACCOUNT_ID = ACCT.CUST_ACCOUNT_ID AND HPS.party_site_id = ACTS.party_site_id) JOIN HZ_CUSTOMER_PROFILES_F custprof ON (hp.party_id = custprof.party_id AND ACCT.CUST_ACCOUNT_ID = custprof.CUST_ACCOUNT_ID) join HZ_CUST_SITE_USES_ALL usg ON (usg.SITE_USE_ID = custprof.SITE_USE_ID and usg.CUST_ACCT_SITE_ID = ACTS.CUST_ACCT_SITE_ID) JOIN HZ_CUST_PROFILE_CLASSES class ON (custprof.PROFILE_CLASS_ID = class.PROFILE_CLASS_ID) JOIN FND_SETID_SETS STId ON (STID.SET_ID = ACTS.SET_ID) join AR_COLLECTORS coll on (coll.collector_id = custprof.COLLECTOR_ID) join AR_STATEMENT_CYCLES cyc on (cyc.statement_cycle_id = custprof.STATEMENT_CYCLE_ID) join RA_GROUPING_RULES grp on (custprof.GROUPING_RULE_ID = grp.GROUPING_RULE_ID) JOIN RA_TERMS RTM ON (custprof.STANDARD_TERMS = rtm.TERM_ID) left JOIN AR_AUTOMATCH_RULES aar on (custprof.AUTOMATCH_RULE_ID = aar.AUTOMATCH_RULE_ID) where custprof.status = 'A' and class.status = 'A' AND ACTS.STATUS = 'A' and hp.party_type = 'ORGANIZATION' AND hp.status = 'A' and custprof.site_use_id is not null and sysdate between custprof.EFFECTIVE_START_DATE and custprof.EFFECTIVE_END_DATE and class.NAME = 'DEFAULT' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/financials/receivables/customers/customerProfileService/types/" xmlns:cus="http://xmlns.oracle.com/apps/financials/receivables/customers/customerProfileService/" xmlns:cus1="http://xmlns.oracle.com/apps/financials/receivables/customerSetup/customerProfiles/model/flex/CustomerProfileDff/" xmlns:cus2="http://xmlns.oracle.com/apps/financials/receivables/customerSetup/customerProfiles/model/flex/CustomerProfileGdf/"> <soapenv:Header/> <soapenv:Body> <typ:updateCustomerProfileAsync> <typ:customerProfile> <cus:AccountNumber>${DataSource#AccountNumber}</cus:AccountNumber> <cus:SiteNumber>${DataSource#SiteNumber}</cus:SiteNumber> <cus:CustomerAccountId>${DataSource#CustomerAccountId}</cus:CustomerAccountId> <cus:ProfileClassName>${DataSource#ProfileClassName}</cus:ProfileClassName> <cus:ClearingDays/> <cus:CreditBalanceStatements>${DataSource#CreditBalanceStatements}</cus:CreditBalanceStatements> <cus:CreditChecking>${DataSource#CreditChecking}</cus:CreditChecking> <cus:CreditHold>${DataSource#CreditHold}</cus:CreditHold> <cus:CustomerAccountProfileId>${DataSource#CustomerAccountProfileId}</cus:CustomerAccountProfileId> <cus:DiscountGraceDays/> <cus:DiscountTerms>${DataSource#DiscountTerms}</cus:DiscountTerms> <cus:DunningLetters>${DataSource#DunningLetters}</cus:DunningLetters> <cus:EffectiveEndDate>${DataSource#EffectiveEndDate}</cus:EffectiveEndDate> <cus:EffectiveStartDate>${DataSource#EffectiveStartDate}</cus:EffectiveStartDate> <cus:LastCreditReviewDate/> <cus:NextCreditReviewDate/> <cus:OverrideTerms>${DataSource#OverrideTerms}</cus:OverrideTerms> <cus:PartyId>${DataSource#PartyId}</cus:PartyId> <cus:PercentCollectable/> <cus:SendStatements>${DataSource#SendStatements}</cus:SendStatements> <cus:Tolerance>${DataSource#Tolerance}</cus:Tolerance> <cus:CollectorName>${DataSource#CollectorName}</cus:CollectorName> <cus:ConversionRateType/> <cus:PaymentTerms>${DataSource#PaymentTerms}</cus:PaymentTerms> <cus:AutoCashRuleSet/> <cus:ApplicationExceptionRuleSet/> <cus:AutoMatchRuleSet/> <cus:ReminderRuleSet/> <cus:StatementCycle>${DataSource#StatementCycle}</cus:StatementCycle> <cus:GroupingRule>${DataSource#GroupingRule}</cus:GroupingRule> <cus:CreditClassificationValue/> <cus:AccountStatusValue/> <cus:RiskCodeValue/> <cus:CreditRatingValue/> <cus:BillLevel/> <cus:BillType/> <cus:MatchReceiptsBy/> <cus:PreferredContactMethod>${DataSource#PreferredContactMethod}</cus:PreferredContactMethod> <cus:PreferredDeliveryMethod>${DataSource#PreferredDeliveryMethod}</cus:PreferredDeliveryMethod> <cus:GenerateBill/> <cus:MatchByAutoupdate/> <cus:AutoReceiptsIncludeDisputedItems>${DataSource#AutoReceiptsIncludeDisputedItems}</cus:AutoReceiptsIncludeDisputedItems> <cus:ConsolidatedInvoice>${DataSource#ConsolidatedInvoice}</cus:ConsolidatedInvoice> <cus:CreditReviewCycleName/> <cus:CreditAnalystName/> <cus:CreditLimit/> <cus:CreditCurrencyCode/> <cus:StatementDeliveryMethod>${DataSource#StatementDeliveryMethod}</cus:StatementDeliveryMethod> <cus:OrderAmountLimit/> </typ:customerProfile> </typ:updateCustomerProfileAsync> </soapenv:Body> </soapenv:Envelope> |
Introduction to SQL and Syntax What is SQL? SQL stands for Structured Query Language. is a standard programming language for accessing datab...