├── LICENSE ├── awr.sql ├── awr2.sql ├── awrcontrol.sql ├── awrsnaps.sql ├── em.sql ├── em_256colors.sql ├── em_8colors.sql ├── em_nocolors.sql ├── fun_convert_raw.sql ├── inc ├── config_vars.sql ├── load_set.sql ├── null.sql ├── reset_pars.sql └── save_set.sql ├── null.sql ├── p_delete_cascade.sql ├── p_delete_cascade_create.sql ├── p_delete_cascade_test.sql ├── parser.sql ├── sqlmon.sql ├── sqlmon2.sql ├── sqlmon3.sql ├── sqlmond.sql ├── sqlmond0.sql ├── sqlmond1.sql └── term_256colors.sql /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /awr.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script generates AWR Reports 3 | 4 | Created by Eduardo Claro 5 | Last changes on 2021-10-29 6 | 7 | See the help below in the query 8 | */ 9 | 10 | define bs="0" 11 | define es="0" 12 | define typ="AWR" 13 | define ins="" 14 | define fmt="html" 15 | define bd="" 16 | define ed="" 17 | define bs2="" 18 | define es2="" 19 | define ins2="" 20 | define sqlid="" 21 | define rac="" 22 | define opt="" 23 | define DEFAULTVAR1="bs" 24 | define DEFAULTVAR2="es" 25 | define DEFAULTVAR3="typ" 26 | define DEFAULTVAR4="ins" 27 | define DEFAULTVAR5="fmt" 28 | 29 | -- Parse the received parameters 30 | @@parser 31 | 32 | set term off 33 | col SCRIPT new_value SCRIPT 34 | col AWRSPOOL NEW_VALUE AWRSPOOL 35 | select 36 | case when upper('&HELP') in ('S','Y') then 'null' else 'awr2' end SCRIPT 37 | from dual; 38 | @inc/save_set.sql 39 | set head off feed off ver off timing off 40 | set term on 41 | 42 | WITH 43 | help as ( 44 | select q'[ 45 | ------------------------------------------------------------------------ 46 | Usage: 47 | START awr bs es typ ins fmt par=value par=value ... 48 | START awr par=value par=value ... 49 | 50 | Parameters (can be passed in any order in the form parameter=value) 51 | bs : begin SNAP_ID 52 | es : end SNAP_ID 53 | bd : begin date (use format 'yyyy/mm/dd-hh24:mi'), only for ASH reports (use bd/ed or bs/es) 54 | ed : begin date (use format 'yyyy/mm/dd-hh24:mi'), only for ASH reports (use bd/ed or bs/es) 55 | rac : Y for Global (RAC) reports 56 | ins : instance number (default 1 or NULL for RAC=Y) 57 | typ : type of the report = 'AWR' (default), 'ASH' or 'SQL' 58 | fmt : format = HTML (default) or TEXT 59 | bs2 : begin SNAP_ID for DIFF reports 60 | es2 : end SNAP_ID for DIFF reports 61 | ins2 : instance number for DIFF reports (default = ins) 62 | sqlid: the SQL_ID for the SQL type report 63 | opt : additional options (depend on the type) 64 | 65 | Example: 66 | START awr 200 210 67 | START awr 200 210 awr 1 68 | START awr bs=200 es=210 typ=awr rac=y 69 | START awr 200 210 bs2=220 es2=230 fmt=html 70 | START 200 210 sql sqlid=fkubjw4jnzvum 71 | ------------------------------------------------------------------------ 72 | ]' HELPTXT 73 | from dual 74 | ) 75 | select * from help where upper('&HELP') in ('S','Y') 76 | ; 77 | 78 | @inc/load_set.sql 79 | set term on 80 | 81 | @@&SCRIPT 82 | 83 | @@inc/reset_pars 84 | -------------------------------------------------------------------------------- /awr2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script generates AWR Reports, it is called by awr.sql 3 | 4 | Created by Eduardo Claro, 2021-04-01 5 | Last changes on 2021-10-29 6 | */ 7 | 8 | prompt Generating report, please wait... 9 | 10 | set term off 11 | @inc/save_set.sql 12 | col AWRSPOOL NEW_VALUE AWRSPOOL 13 | col INS new_value INS 14 | col INS2 new_value INS2 15 | col FORMAT new_value FORMAT 16 | col rac new_value rac 17 | col DBID new_value DBID 18 | col SUFFIX new_value SUFFIX 19 | select 20 | case when upper('&rac') = 'Y' then 'Y' else 'N' end rac, 21 | case when upper('&fmt') = 'TEXT' then 'TEXT' else 'HTML' end FORMAT, 22 | case when upper('&fmt') = 'TEXT' then 'txt' else 'html' end SUFFIX 23 | from dual; 24 | select 25 | case when '&rac' = 'Y' then '&ins' else coalesce('&ins','1') end ins, 26 | coalesce('&ins2','&ins','1') ins2, 27 | to_char(dbid) dbid, 28 | '&tmp/' || 29 | case when upper('&typ') in ('AWR','ASH','SQL') then upper('&typ') else 'AWR' end || 30 | '_' || DB_UNIQUE_NAME || 31 | case when '&rac' = 'Y' then '_RAC' end || 32 | case when '&bs2' is not null then '_DIFF' end || 33 | '_' || case when '&ins' is not null then '&ins._' end || '&bs.-&es.' || 34 | case when upper('&typ') = 'SQL' then '_&sqlid' end || 35 | case when '&bs2' is not null then '_vs_' || case when '&ins2' is not null then coalesce('&ins2','&ins') || '_' end || '&bs2.-&es2.' end || 36 | '.&SUFFIX' as AWRSPOOL 37 | from v$database; 38 | def BTIME="" 39 | def ETIME="" 40 | col BTIME new_value BTIME 41 | col ETIME new_value ETIME 42 | select 43 | case 44 | when '&bd' is not null then to_char(to_date('&bd','yyyy/mm/dd-hh24:mi'),'yyyy-mm-dd hh24:mi:ss') 45 | when '&bs' is not null then (select to_char(end_interval_time,'yyyy-mm-dd hh24:mi:ss') BTIME from dba_hist_snapshot where instance_number = '&ins' and snap_id=to_number('&bs')) 46 | else q'[&BTIME]' 47 | end BTIME, 48 | case 49 | when '&ed' is not null then to_char(to_date('&ed','yyyy/mm/dd-hh24:mi'),'yyyy-mm-dd hh24:mi:ss') 50 | when '&bs' is not null then (select to_char(end_interval_time,'yyyy-mm-dd hh24:mi:ss') ETIME from dba_hist_snapshot where instance_number = '&ins' and snap_id=to_number('&es')) 51 | else q'[&ETIME]' 52 | end ETIME 53 | from dual; 54 | 55 | SET HEAD OFF VER OFF FEED OFF TIMING OFF ECHO OFF 56 | spool &awrspool 57 | 58 | --Regular AWR report 59 | select * from table( 60 | DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_&FORMAT( 61 | l_dbid => '&dbid', 62 | l_inst_num => '&ins', 63 | l_bid => '&bs', 64 | l_eid => '&es', 65 | l_options => '&opt')) 66 | where upper('&typ') = 'AWR' and '&rac' = 'N' and '&bs2' is NULL 67 | UNION ALL 68 | --Diff AWR report 69 | select * from table( 70 | DBMS_WORKLOAD_REPOSITORY.AWR_DIFF_REPORT_&FORMAT( 71 | DBID1 => '&dbid', 72 | INST_NUM1 => '&ins', 73 | BID1 => '&bs', 74 | EID1 => '&es', 75 | DBID2 => '&dbid', 76 | INST_NUM2 => '&ins2', 77 | BID2 => '&bs2', 78 | EID2 => '&es2', 79 | P_OPTIONS => '&opt')) 80 | where upper('&typ') = 'AWR' and '&rac' = 'N' and '&bs2' is not NULL 81 | UNION ALL 82 | -- Global (RAC) AWR Report 83 | select * from table( 84 | DBMS_WORKLOAD_REPOSITORY.AWR_GLOBAL_REPORT_&FORMAT( 85 | l_dbid => '&dbid', 86 | l_inst_num => '&ins', 87 | l_bid => '&bs', 88 | l_eid => '&es', 89 | l_options => '&opt')) 90 | where upper('&typ') = 'AWR' and '&rac' = 'Y' and '&bs2' is NULL 91 | -- Global (RAC) Diff AWR Report 92 | UNION ALL 93 | select * from table( 94 | DBMS_WORKLOAD_REPOSITORY.AWR_GLOBAL_DIFF_REPORT_&FORMAT( 95 | DBID1 => '&dbid', 96 | INST_NUM1 => '&ins', 97 | BID1 => '&bs', 98 | EID1 => '&es', 99 | DBID2 => '&dbid', 100 | INST_NUM2 => '&ins2', 101 | BID2 => '&bs2', 102 | EID2 => '&es2', 103 | P_OPTIONS => '&opt')) 104 | where upper('&typ') = 'AWR' and '&rac' = 'Y' and '&bs2' is not NULL 105 | UNION ALL 106 | -- AWR SQL Report 107 | select * from table( 108 | DBMS_WORKLOAD_REPOSITORY.AWR_SQL_REPORT_&FORMAT( 109 | L_DBID => '&dbid', 110 | L_INST_NUM => '&ins', 111 | L_BID => '&bs', 112 | L_EID => '&es', 113 | L_SQLID => '&sqlid', 114 | L_OPTIONS => '&opt', 115 | L_CON_DBID => '')) 116 | where upper('&typ') = 'SQL' 117 | UNION ALL 118 | -- Regular ASH Report 119 | select * from table( 120 | DBMS_WORKLOAD_REPOSITORY.ASH_REPORT_&FORMAT( 121 | l_dbid => '&dbid', 122 | l_inst_num => '&ins', 123 | l_btime => to_date('&BTIME','yyyy-mm-dd hh24:mi:ss'), 124 | l_etime => to_date('&ETIME','yyyy-mm-dd hh24:mi:ss'), 125 | l_options => '&opt')) 126 | where upper('&typ') = 'ASH' and '&rac' = 'N' 127 | UNION ALL 128 | -- Global (RAC) ASH Report 129 | select * from table( 130 | DBMS_WORKLOAD_REPOSITORY.ASH_GLOBAL_REPORT_&FORMAT( 131 | l_dbid => '&dbid', 132 | l_inst_num => '&ins', 133 | l_btime => to_date('&BTIME','yyyy-mm-dd hh24:mi:ss'), 134 | l_etime => to_date('&ETIME','yyyy-mm-dd hh24:mi:ss'), 135 | l_options => '&opt')) 136 | where upper('&typ') = 'ASH' and '&rac' = 'Y' 137 | ; 138 | 139 | spool off 140 | 141 | prompt Report generated on "&AWRSPOOL" 142 | 143 | @inc/load_set.sql 144 | set term on 145 | 146 | prompt Report generated at &awrspool 147 | -------------------------------------------------------------------------------- /awrcontrol.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script shows AWR Control configuration 3 | 4 | Created by Eduardo Claro 5 | Last changes on 2021-10-28 6 | */ 7 | 8 | prompt =================== 9 | prompt DBA_HIST_WR_CONTROL 10 | prompt =================== 11 | 12 | col SNAP_INTERVAL for a25 13 | col RETENTION for a25 14 | col DBID for 99999999999 15 | col SRC_DBID like DBID 16 | SELECT c.* FROM 17 | dba_hist_wr_control c 18 | join v$database d on c.DBID = d.DBID; 19 | -------------------------------------------------------------------------------- /awrsnaps.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script shows AWR Snapshots 3 | It shows the MINIMUM SNAP_ID per hour 4 | With the default AWR interval of 1h, it should show all Snapshots 5 | If the AWR interval is different from 1h OR there are manual snapshots, then only the minimum SNAP_ID per hour will be displayed 6 | 7 | Created by Eduardo Claro, 2021-04-07 8 | Last changes on 2021-10-28 9 | */ 10 | 11 | @@awrcontrol 12 | 13 | prompt =================== 14 | prompt AWR Snapshots 15 | prompt =================== 16 | prompt 17 | prompt The SNAP_ID displayed is the MIN of the hour. An '*' besides the SNAP_ID means there was a STARTUP at that period. 18 | 19 | col SNAP_00 for a6 just right head "00H " 20 | col SNAP_01 for a6 just right head "01H " 21 | col SNAP_02 for a6 just right head "02H " 22 | col SNAP_03 for a6 just right head "03H " 23 | col SNAP_04 for a6 just right head "04H " 24 | col SNAP_05 for a6 just right head "05H " 25 | col SNAP_06 for a6 just right head "06H " 26 | col SNAP_07 for a6 just right head "07H " 27 | col SNAP_08 for a6 just right head "08H " 28 | col SNAP_09 for a6 just right head "09H " 29 | col SNAP_10 for a6 just right head "10H " 30 | col SNAP_11 for a6 just right head "11H " 31 | col SNAP_12 for a6 just right head "12H " 32 | col SNAP_13 for a6 just right head "13H " 33 | col SNAP_14 for a6 just right head "14H " 34 | col SNAP_15 for a6 just right head "15H " 35 | col SNAP_16 for a6 just right head "16H " 36 | col SNAP_17 for a6 just right head "17H " 37 | col SNAP_18 for a6 just right head "18H " 38 | col SNAP_19 for a6 just right head "19H " 39 | col SNAP_20 for a6 just right head "20H " 40 | col SNAP_21 for a6 just right head "21H " 41 | col SNAP_22 for a6 just right head "22H " 42 | col SNAP_23 for a6 just right head "23H " 43 | col dt head "DATE" 44 | col DATE for a10 45 | col INST for 9999 46 | WITH x as ( 47 | SELECT 48 | trunc(end_interval_time) DT, INSTANCE_NUMBER, 49 | min(case when extract(hour from end_interval_time) = 0 then snap_id else NULL end) SN00, 50 | min(case when extract(hour from end_interval_time) = 1 then snap_id else NULL end) SN01, 51 | min(case when extract(hour from end_interval_time) = 2 then snap_id else NULL end) SN02, 52 | min(case when extract(hour from end_interval_time) = 3 then snap_id else NULL end) SN03, 53 | min(case when extract(hour from end_interval_time) = 4 then snap_id else NULL end) SN04, 54 | min(case when extract(hour from end_interval_time) = 5 then snap_id else NULL end) SN05, 55 | min(case when extract(hour from end_interval_time) = 6 then snap_id else NULL end) SN06, 56 | min(case when extract(hour from end_interval_time) = 7 then snap_id else NULL end) SN07, 57 | min(case when extract(hour from end_interval_time) = 8 then snap_id else NULL end) SN08, 58 | min(case when extract(hour from end_interval_time) = 9 then snap_id else NULL end) SN09, 59 | min(case when extract(hour from end_interval_time) = 10 then snap_id else NULL end) SN10, 60 | min(case when extract(hour from end_interval_time) = 11 then snap_id else NULL end) SN11, 61 | min(case when extract(hour from end_interval_time) = 12 then snap_id else NULL end) SN12, 62 | min(case when extract(hour from end_interval_time) = 13 then snap_id else NULL end) SN13, 63 | min(case when extract(hour from end_interval_time) = 14 then snap_id else NULL end) SN14, 64 | min(case when extract(hour from end_interval_time) = 15 then snap_id else NULL end) SN15, 65 | min(case when extract(hour from end_interval_time) = 16 then snap_id else NULL end) SN16, 66 | min(case when extract(hour from end_interval_time) = 17 then snap_id else NULL end) SN17, 67 | min(case when extract(hour from end_interval_time) = 18 then snap_id else NULL end) SN18, 68 | min(case when extract(hour from end_interval_time) = 19 then snap_id else NULL end) SN19, 69 | min(case when extract(hour from end_interval_time) = 20 then snap_id else NULL end) SN20, 70 | min(case when extract(hour from end_interval_time) = 21 then snap_id else NULL end) SN21, 71 | min(case when extract(hour from end_interval_time) = 22 then snap_id else NULL end) SN22, 72 | min(case when extract(hour from end_interval_time) = 23 then snap_id else NULL end) SN23, 73 | max(case when extract(hour from end_interval_time) = 0 then startup_time else NULL end) ST00, 74 | max(case when extract(hour from end_interval_time) = 1 then startup_time else NULL end) ST01, 75 | max(case when extract(hour from end_interval_time) = 2 then startup_time else NULL end) ST02, 76 | max(case when extract(hour from end_interval_time) = 3 then startup_time else NULL end) ST03, 77 | max(case when extract(hour from end_interval_time) = 4 then startup_time else NULL end) ST04, 78 | max(case when extract(hour from end_interval_time) = 5 then startup_time else NULL end) ST05, 79 | max(case when extract(hour from end_interval_time) = 6 then startup_time else NULL end) ST06, 80 | max(case when extract(hour from end_interval_time) = 7 then startup_time else NULL end) ST07, 81 | max(case when extract(hour from end_interval_time) = 8 then startup_time else NULL end) ST08, 82 | max(case when extract(hour from end_interval_time) = 9 then startup_time else NULL end) ST09, 83 | max(case when extract(hour from end_interval_time) = 10 then startup_time else NULL end) ST10, 84 | max(case when extract(hour from end_interval_time) = 11 then startup_time else NULL end) ST11, 85 | max(case when extract(hour from end_interval_time) = 12 then startup_time else NULL end) ST12, 86 | max(case when extract(hour from end_interval_time) = 13 then startup_time else NULL end) ST13, 87 | max(case when extract(hour from end_interval_time) = 14 then startup_time else NULL end) ST14, 88 | max(case when extract(hour from end_interval_time) = 15 then startup_time else NULL end) ST15, 89 | max(case when extract(hour from end_interval_time) = 16 then startup_time else NULL end) ST16, 90 | max(case when extract(hour from end_interval_time) = 17 then startup_time else NULL end) ST17, 91 | max(case when extract(hour from end_interval_time) = 18 then startup_time else NULL end) ST18, 92 | max(case when extract(hour from end_interval_time) = 19 then startup_time else NULL end) ST19, 93 | max(case when extract(hour from end_interval_time) = 20 then startup_time else NULL end) ST20, 94 | max(case when extract(hour from end_interval_time) = 21 then startup_time else NULL end) ST21, 95 | max(case when extract(hour from end_interval_time) = 22 then startup_time else NULL end) ST22, 96 | max(case when extract(hour from end_interval_time) = 23 then startup_time else NULL end) ST23 97 | FROM dba_hist_snapshot 98 | JOIN v$database using (DBID) 99 | group by trunc(end_interval_time), INSTANCE_NUMBER 100 | ) 101 | select 102 | to_char(DT,'YYYY-MM-DD') DT, INSTANCE_NUMBER as INST, 103 | lpad(SN00 || case when ST00 is NOT NULL and ST00 <> lag(ST23) over (ORDER BY DT) then '*' else ' ' end,6,' ') as SNAP_00, 104 | lpad(SN01 || case when ST01 is NOT NULL and ST01 <> ST00 then '*' else ' ' end ,6,' ') as SNAP_01, 105 | lpad(SN02 || case when ST02 is NOT NULL and ST02 <> ST01 then '*' else ' ' end ,6,' ') as SNAP_02, 106 | lpad(SN03 || case when ST03 is NOT NULL and ST03 <> ST02 then '*' else ' ' end ,6,' ') as SNAP_03, 107 | lpad(SN04 || case when ST04 is NOT NULL and ST04 <> ST03 then '*' else ' ' end ,6,' ') as SNAP_04, 108 | lpad(SN05 || case when ST05 is NOT NULL and ST05 <> ST04 then '*' else ' ' end ,6,' ') as SNAP_05, 109 | lpad(SN06 || case when ST06 is NOT NULL and ST06 <> ST05 then '*' else ' ' end ,6,' ') as SNAP_06, 110 | lpad(SN07 || case when ST07 is NOT NULL and ST07 <> ST06 then '*' else ' ' end ,6,' ') as SNAP_07, 111 | lpad(SN08 || case when ST08 is NOT NULL and ST08 <> ST07 then '*' else ' ' end ,6,' ') as SNAP_08, 112 | lpad(SN09 || case when ST09 is NOT NULL and ST09 <> ST08 then '*' else ' ' end ,6,' ') as SNAP_09, 113 | lpad(SN10 || case when ST10 is NOT NULL and ST10 <> ST09 then '*' else ' ' end ,6,' ') as SNAP_10, 114 | lpad(SN11 || case when ST11 is NOT NULL and ST11 <> ST10 then '*' else ' ' end ,6,' ') as SNAP_11, 115 | lpad(SN12 || case when ST12 is NOT NULL and ST12 <> ST11 then '*' else ' ' end ,6,' ') as SNAP_12, 116 | lpad(SN13 || case when ST13 is NOT NULL and ST13 <> ST12 then '*' else ' ' end ,6,' ') as SNAP_13, 117 | lpad(SN14 || case when ST14 is NOT NULL and ST14 <> ST13 then '*' else ' ' end ,6,' ') as SNAP_14, 118 | lpad(SN15 || case when ST15 is NOT NULL and ST15 <> ST14 then '*' else ' ' end ,6,' ') as SNAP_15, 119 | lpad(SN16 || case when ST16 is NOT NULL and ST16 <> ST15 then '*' else ' ' end ,6,' ') as SNAP_16, 120 | lpad(SN17 || case when ST17 is NOT NULL and ST17 <> ST16 then '*' else ' ' end ,6,' ') as SNAP_17, 121 | lpad(SN18 || case when ST18 is NOT NULL and ST18 <> ST17 then '*' else ' ' end ,6,' ') as SNAP_18, 122 | lpad(SN19 || case when ST19 is NOT NULL and ST19 <> ST18 then '*' else ' ' end ,6,' ') as SNAP_19, 123 | lpad(SN20 || case when ST20 is NOT NULL and ST20 <> ST19 then '*' else ' ' end ,6,' ') as SNAP_20, 124 | lpad(SN21 || case when ST21 is NOT NULL and ST21 <> ST20 then '*' else ' ' end ,6,' ') as SNAP_21, 125 | lpad(SN22 || case when ST22 is NOT NULL and ST22 <> ST21 then '*' else ' ' end ,6,' ') as SNAP_22, 126 | lpad(SN23 || case when ST23 is NOT NULL and ST23 <> ST22 then '*' else ' ' end ,6,' ') as SNAP_23 127 | from x 128 | order by INSTANCE_NUMBER, DT 129 | ; 130 | -------------------------------------------------------------------------------- /em.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script emulates the EM performance chart 3 | Created by Eduardo Claro, 2018-03-14 4 | Last changes on 2018-03-20 5 | 6 | WARNING: It uses ASH repository, so YOU NEED Diagnostics Pack 7 | 8 | It can be used to display the Wait Class or the 5 main events of a specific Wait Class 9 | 10 | Parameters (can be passed in any order in the form parameter=value) 11 | 12 | class : specify the Wait Class (just the 3 first letters are enough) to show their events breakdown. If not specified, show the Wait Classes breakdown. 13 | begin : begin date as a DATE expression, like sysdate-1/24. 14 | end : end date as a DATE expression, like sysdate-1/24. 15 | minutes : if a positive number is provided, the period is defined starting with &BEGIN and ending the number of minutes after that (&END parameter is ignored). 16 | if a negative number is provided, the period is defined starting the number of minutes before now (sysdate) and ending now (&BEGIN and &END are ignored). 17 | view : the ASH view to query. Enter D to query DBA_ACTIVE_SESS_HISTORY. Any other value will use GV$ACTIVE_SESSION_HISTORY. 18 | group : group (Y) or not (N) the rows by minute. 19 | color : define if you want to see characters instead of colors (no), 8 colors (8) or 256 colors (256). 20 | show : SHOW (Y) or not (N) the number of sessions for each Wait Class or Event. 21 | mult : the multiplier to define how many boxes will be painted for each Average Active Session. If mult=2 and there are 3 sessions, 6 (3 * 2) boxes will be painted. 22 | zeros : show (Y) or not (N) the samples that have no active session (especially useful when showing just one Wait Class 23 | inst : specify an Instance to show (for RAC environments). NULL show all instances. 24 | 25 | Example: 26 | 27 | @em 28 | @em class=app view=D 29 | @em group=N 30 | @em begin=sysdate-3/24 show=n 31 | 32 | Attention: 33 | If the script seems to hang waiting for something, it is probably due to the SQL*Plus number variables (&1-&16) not be defined 34 | The SQL*Plus variables &1-&16 must be defined BEFORE running this script 35 | It is usually done by putting some statements in the login.sql, like this: 36 | set termout off 37 | COLUMN 1 NEW_VALUE 1 noprint 38 | COLUMN 2 NEW_VALUE 2 noprint 39 | COLUMN 3 NEW_VALUE 3 noprint 40 | ... 41 | SELECT '' as "1",'' as "2",'' as "3" ... FROM dual; 42 | set termout on 43 | */ 44 | 45 | -- Default values for the parameters 46 | define CLASS="" 47 | define BEGIN="sysdate-1/24" 48 | define END="sysdate" 49 | define MINUTES="" 50 | define VIEW="" 51 | define GROUP=Y 52 | define COLOR=256 53 | define SHOW=N 54 | define MULT=1 55 | define ZEROS=Y 56 | define INST="" 57 | 58 | -- Parse the received parameters 59 | @@parser 60 | 61 | clear breaks 62 | set echo off timing off ver off feed off 63 | 64 | define RESET = 65 | alter session set nls_Date_format="dd-MON hh24:mi:ss"; 66 | set pages 500 67 | 68 | set term off 69 | 70 | col MULT new_value MULT 71 | col xVIEW new_value VIEW 72 | col xEND new_value END 73 | col xBEGIN new_value BEGIN 74 | col QUERY new_value QUERY 75 | col INSTCOL new_value INSTCOL 76 | col SCRIPT new_value SCRIPT 77 | select 78 | -- case when upper('&GROUP') = 'Y' then &MULT else 1 end MULT, 79 | case when upper('&VIEW') = 'D' then 'DBA_HIST_ACTIVE_SESS_HISTORY' else 'GV$ACTIVE_SESSION_HISTORY' end xVIEW, 80 | case when upper('&VIEW') = 'D' then 'INSTANCE_NUMBER' else 'INST_ID' end INSTCOL, 81 | case when to_number('&MINUTES') < 0 then q'[trunc(sysdate,'mi')+(&MINUTES./24/60)]' else q'[&BEGIN]' end xBEGIN, 82 | case when '&MINUTES' is null then q'[&END]' when to_number('&MINUTES') < 0 then 'sysdate' else q'[&BEGIN.+&MINUTES./24/60]' end xEND, 83 | case when '&CLASS' IS NULL then 'ash_class_final' else 'ash_event_final' end || case when upper('&SHOW') = 'N' then '2' end QUERY, 84 | case when '&COLOR' in ('8','256') then 'em_&COLOR.colors' else 'em_nocolors' end SCRIPT 85 | from dual; 86 | 87 | -- Set the colors 88 | @@&SCRIPT 89 | 90 | col MINUTE head "TIME" 91 | col chart for a400 trunc 92 | col ONCPU for 99.9 head "OnCPU" 93 | col USERIO for 99.9 head "UsrIO" 94 | col SYSTIO for 99.9 head "SysIO" 95 | col CONC for 99.9 head "Conc" 96 | col APPLIC for 99.9 head "Appl" 97 | col COMM for 99.9 head "Comm" 98 | col CONF for 99.9 head "Conf" 99 | col ADMIN for 99.9 head "Admin" 100 | col SCHED for 99.9 head "Sched" 101 | col CLUST for 99.9 head "Clust" 102 | col QUEUE for 99.9 head "Queue" 103 | col NETW for 99.9 head "Netwk" 104 | col OTHER for 99.9 head "Other" 105 | col TOTAL for 99.9 head "TOTAL" 106 | col EV1 for 99.9 107 | col EV2 for 99.9 108 | col EV3 for 99.9 109 | col EV4 for 99.9 110 | col EV5 for 99.9 111 | 112 | -- Using DELETE instead of TRUNCATE just for not to end a transaction in course 113 | delete from plan_table where STATEMENT_ID = 'EM-SQLPLUS' 114 | ; 115 | insert into plan_table (STATEMENT_ID, TIMESTAMP, REMARKS) 116 | select 117 | 'EM-SQLPLUS', 118 | cast(sample_time as date) sample_time, --remove sub-seconds difference of the RAC instances 119 | 'ALL SAMPLES' wait_class 120 | from &VIEW 121 | where sample_time between &begin and &end 122 | and ('&INST' is null OR &INSTCOL = nvl('&INST','&INSTCOL')) 123 | ; 124 | insert into plan_table (STATEMENT_ID, TIMESTAMP, REMARKS, COST) 125 | select 126 | 'EM-SQLPLUS', 127 | cast(sample_time as date) sample_time, --remove sub-seconds difference of the RAC instances 128 | nvl(wait_class,'On CPU') wait_class, count(*) sessions 129 | from &VIEW 130 | where '&class' IS NULL and sample_time between &begin and &end 131 | and ('&INST' is null OR &INSTCOL = nvl('&INST','&INSTCOL')) 132 | group by cast(sample_time as date), wait_class 133 | ; 134 | insert into plan_table (STATEMENT_ID, TIMESTAMP, REMARKS, PLAN_ID, COST) 135 | select 136 | 'EM-SQLPLUS', 137 | cast(sample_time as date) sample_time, --remove sub-seconds difference of the RAC instances 138 | event, event_id, count(*) sessions 139 | from &VIEW 140 | where '&class' IS NOT NULL and sample_time between &begin and &end 141 | and wait_class = (select wait_class from v$event_name where upper(wait_class) like upper('&class%') and rownum = 1) 142 | and ('&INST' is null OR &INSTCOL = nvl('&INST','&INSTCOL')) 143 | group by cast(sample_time as date), event, event_id 144 | ; 145 | set term on 146 | 147 | WITH 148 | ash_allsamples AS ( 149 | select distinct 150 | TIMESTAMP sample_time 151 | from plan_table 152 | where STATEMENT_ID = 'EM-SQLPLUS' and REMARKS = 'ALL SAMPLES' 153 | ), 154 | ash_class AS ( 155 | select * from ( 156 | select TIMESTAMP sample_time, REMARKS wait_class, COST sessions, 157 | count(distinct TIMESTAMP) over (partition by trunc(TIMESTAMP,'MI')) SAMPLES_PER_MIN 158 | from plan_table 159 | where STATEMENT_ID = 'EM-SQLPLUS' 160 | ) where wait_class <> 'ALL SAMPLES' 161 | ), 162 | ash_event AS ( 163 | select * from ( 164 | select TIMESTAMP sample_time, REMARKS event, PLAN_ID event_id, COST sessions, 165 | count(distinct TIMESTAMP) over (partition by trunc(TIMESTAMP,'MI')) SAMPLES_PER_MIN 166 | from plan_table 167 | where STATEMENT_ID = 'EM-SQLPLUS' 168 | ) where event <> 'ALL SAMPLES' 169 | ), 170 | ash_mainevents AS ( 171 | select 172 | event, position 173 | from ( 174 | select 175 | event, 176 | rank() over (order by sum(sessions) desc, event_id) position 177 | from ash_event 178 | group by event, event_id 179 | order by sum(sessions) desc 180 | ) 181 | where position <= 5 182 | ), 183 | ash_class_minute AS ( 184 | select 185 | case when upper('&GROUP') = 'Y' then trunc(sample_time,'MI') else sample_time end minute, 186 | case when wait_class in ('On CPU','User I/O','System I/O','Concurrency','Application','Commit','Configuration', 187 | 'Administrative','Scheduler','Cluster','Queueing','Network','Other') then wait_class else 'Other' end wait_class, 188 | case when upper('&GROUP') = 'Y' then sum(sessions)/SAMPLES_PER_MIN else sum(sessions) end avg_sessions 189 | from ash_allsamples left join ash_class using (sample_time) 190 | group by SAMPLES_PER_MIN, 191 | case when upper('&GROUP') = 'Y' then trunc(sample_time,'MI') else sample_time end, 192 | case when wait_class in ('On CPU','User I/O','System I/O','Concurrency','Application','Commit','Configuration', 193 | 'Administrative','Scheduler','Cluster','Queueing','Network','Other') then wait_class else 'Other' end 194 | ), 195 | ash_event_minute AS ( 196 | select 197 | case when upper('&GROUP') = 'Y' then trunc(sample_time,'MI') else sample_time end minute, 198 | to_char(nvl(position,0)) position, 199 | case when upper('&GROUP') = 'Y' then sum(sessions)/SAMPLES_PER_MIN else sum(sessions) end avg_sessions 200 | from ash_allsamples left join ash_event e using (sample_time) left join ash_mainevents m on e.event = m.event 201 | group by SAMPLES_PER_MIN, 202 | case when upper('&GROUP') = 'Y' then trunc(sample_time,'MI') else sample_time end, position 203 | ), 204 | ash_class_pivot AS ( 205 | select minute, nvl(ONCPU,0) ONCPU, nvl(USERIO,0) USERIO, nvl(SYSTIO,0) SYSTIO, nvl(APPLIC,0) APPLIC, 206 | nvl(CONC,0) CONC, nvl(CONF,0) CONF, nvl(COMM,0) COMM, nvl(ADMIN,0) ADMIN, nvl(SCHED,0) SCHED, 207 | nvl(CLUST,0) CLUST, nvl(QUEUE,0) QUEUE, nvl(NETW,0) NETW, nvl(OTHER,0) OTHER 208 | from ( 209 | select * 210 | from ash_class_minute 211 | pivot 212 | (sum(avg_sessions) for wait_class in ( 213 | 'On CPU' as ONCPU 214 | ,'User I/O' as USERIO 215 | ,'System I/O' as SYSTIO 216 | ,'Application' as APPLIC 217 | ,'Concurrency' as CONC 218 | ,'Configuration' as CONF 219 | ,'Commit' as COMM 220 | ,'Administrative' as ADMIN 221 | ,'Scheduler' as SCHED 222 | ,'Cluster' as CLUST 223 | ,'Queueing' as QUEUE 224 | ,'Network' as NETW 225 | ,'Other' as OTHER))) 226 | ), 227 | ash_event_pivot AS ( 228 | select minute, nvl(EV1,0) EV1, nvl(EV2,0) EV2, nvl(EV3,0) EV3, nvl(EV4,0) EV4, nvl(EV5,0) EV5, nvl(OTHER,0) OTHER 229 | from ( 230 | select * 231 | from ash_event_minute 232 | pivot 233 | (sum(avg_sessions) for position in ( 234 | '1' as EV1 235 | ,'2' as EV2 236 | ,'3' as EV3 237 | ,'4' as EV4 238 | ,'5' as EV5 239 | ,'0' as OTHER))) 240 | ), 241 | ash_class_final AS ( 242 | select ash_class_pivot.*, 243 | ONCPU + USERIO + SYSTIO + APPLIC + CONC + CONF + COMM + ADMIN + SCHED + CLUST + QUEUE + NETW + Other as TOTAL, 244 | '&RESET' || 245 | '&BG_ONCPU' || lpad('&CH_ONCPU', round(ONCPU * &MULT) , '&CH_ONCPU') || 246 | '&BG_USER' || lpad('&CH_USER' , round(USERIO * &MULT) , '&CH_USER' ) || 247 | '&BG_SYST' || lpad('&CH_SYST' , round(SYSTIO * &MULT) , '&CH_SYST' ) || 248 | '&BG_CONC' || lpad('&CH_CONC' , round(CONC * &MULT) , '&CH_CONC' ) || 249 | '&BG_APPL' || lpad('&CH_APPL' , round(APPLIC * &MULT) , '&CH_APPL' ) || 250 | '&BG_CONF' || lpad('&CH_CONF' , round(CONF * &MULT) , '&CH_CONF' ) || 251 | '&BG_COMM' || lpad('&CH_COMM' , round(COMM * &MULT) , '&CH_COMM' ) || 252 | '&BG_ADMI' || lpad('&CH_ADMI' , round(ADMIN * &MULT) , '&CH_ADMI' ) || 253 | '&BG_SCHE' || lpad('&CH_SCHE' , round(SCHED * &MULT) , '&CH_SCHE' ) || 254 | '&BG_CLUS' || lpad('&CH_CLUS' , round(CLUST * &MULT) , '&CH_CLUS' ) || 255 | '&BG_QUEU' || lpad('&CH_QUEU' , round(QUEUE * &MULT) , '&CH_QUEU' ) || 256 | '&BG_NETW' || lpad('&CH_NETW' , round(NETW * &MULT) , '&CH_NETW' ) || 257 | '&BG_OTHE' || lpad('&CH_OTHE' , round(Other * &MULT) , '&CH_OTHE' ) || 258 | '&RESET' chart 259 | from ash_class_pivot 260 | order by minute 261 | ), 262 | ash_class_final2 AS ( 263 | select minute, total, chart from ash_class_final 264 | ), 265 | ash_event_final AS ( 266 | select ash_event_pivot.*, 267 | EV1 + EV2 + EV3 + EV4 + EV5 + Other as TOTAL, 268 | '&RESET' || 269 | '&BG_USER' || lpad('&CH_EV1' , round(EV1 * &MULT) , '&CH_EV1' ) || 270 | '&BG_SYST' || lpad('&CH_EV2' , round(EV2 * &MULT) , '&CH_EV2' ) || 271 | '&BG_CONC' || lpad('&CH_EV3' , round(EV3 * &MULT) , '&CH_EV3' ) || 272 | '&BG_APPL' || lpad('&CH_EV4' , round(EV4 * &MULT) , '&CH_EV4' ) || 273 | '&BG_CONF' || lpad('&CH_EV5' , round(EV5 * &MULT) , '&CH_EV5' ) || 274 | '&BG_OTHE' || lpad('&CH_OTHE' , round(OTHER * &MULT) , '&CH_OTHE' ) || 275 | '&RESET' chart 276 | from ash_event_pivot 277 | order by minute 278 | ), 279 | ash_event_final2 AS ( 280 | select minute, total, chart from ash_event_final 281 | ) 282 | select * from &QUERY 283 | where (upper('&ZEROS') = 'Y' OR round(total,1) > 0) 284 | / 285 | 286 | col CHART for a30 287 | col xGROUP head "WAIT CLASS" for a20 trunc 288 | SELECT * FROM ( 289 | select 'On CPU' xGROUP, '&BG_ONCPU' || lpad('&CH_ONCPU', 5 , '&CH_ONCPU') || '&RESET' chart from dual UNION ALL 290 | select 'User I/O' xGROUP, '&BG_USER' || lpad('&CH_USER' , 5 , '&CH_USER' ) || '&RESET' chart from dual UNION ALL 291 | select 'System I/O' xGROUP, '&BG_SYST' || lpad('&CH_SYST' , 5 , '&CH_SYST' ) || '&RESET' chart from dual UNION ALL 292 | select 'Application' xGROUP, '&BG_APPL' || lpad('&CH_APPL' , 5 , '&CH_APPL' ) || '&RESET' chart from dual UNION ALL 293 | select 'Concurrency' xGROUP, '&BG_CONC' || lpad('&CH_CONC' , 5 , '&CH_CONC' ) || '&RESET' chart from dual UNION ALL 294 | select 'Configuration' xGROUP, '&BG_CONF' || lpad('&CH_CONF' , 5 , '&CH_CONF' ) || '&RESET' chart from dual UNION ALL 295 | select 'Commit' xGROUP, '&BG_COMM' || lpad('&CH_COMM' , 5 , '&CH_COMM' ) || '&RESET' chart from dual UNION ALL 296 | select 'Administrative' xGROUP, '&BG_ADMI' || lpad('&CH_ADMI' , 5 , '&CH_ADMI' ) || '&RESET' chart from dual UNION ALL 297 | select 'Scheduler' xGROUP, '&BG_SCHE' || lpad('&CH_SCHE' , 5 , '&CH_SCHE' ) || '&RESET' chart from dual UNION ALL 298 | select 'Cluster' xGROUP, '&BG_CLUS' || lpad('&CH_CLUS' , 5 , '&CH_CLUS' ) || '&RESET' chart from dual UNION ALL 299 | select 'Queueing' xGROUP, '&BG_QUEU' || lpad('&CH_QUEU' , 5 , '&CH_QUEU' ) || '&RESET' chart from dual UNION ALL 300 | select 'Network' xGROUP, '&BG_NETW' || lpad('&CH_NETW' , 5 , '&CH_NETW' ) || '&RESET' chart from dual UNION ALL 301 | select 'Other' xGROUP, '&BG_OTHE' || lpad('&CH_OTHE' , 5 , '&CH_OTHE' ) || '&RESET' chart from dual 302 | ) WHERE '&class' IS NULL 303 | ; 304 | col xGROUP head "EVENT" for a64 trunc 305 | WITH events AS ( 306 | select 307 | event, position 308 | from ( 309 | select 310 | REMARKS event, 311 | rank() over (order by SUM(COST) desc, PLAN_ID) position 312 | from plan_table 313 | where STATEMENT_ID = 'EM-SQLPLUS' and REMARKS <> 'ALL SAMPLES' 314 | group by REMARKS, PLAN_ID 315 | order by SUM(COST) desc 316 | ) 317 | where position <= 5 318 | ) 319 | select * from ( 320 | select event xGROUP, '&BG_USER' || lpad('&CH_EV1' , 5 , '&CH_EV1' ) || '&RESET' chart from events WHERE position = 1 UNION ALL 321 | select event xGROUP, '&BG_SYST' || lpad('&CH_EV2' , 5 , '&CH_EV2' ) || '&RESET' chart from events WHERE position = 2 UNION ALL 322 | select event xGROUP, '&BG_APPL' || lpad('&CH_EV3' , 5 , '&CH_EV3' ) || '&RESET' chart from events WHERE position = 3 UNION ALL 323 | select event xGROUP, '&BG_CONC' || lpad('&CH_EV4' , 5 , '&CH_EV4' ) || '&RESET' chart from events WHERE position = 4 UNION ALL 324 | select event xGROUP, '&BG_CONF' || lpad('&CH_EV5' , 5 , '&CH_EV5' ) || '&RESET' chart from events WHERE position = 5 UNION ALL 325 | select 'Other' xGROUP, '&BG_OTHE' || lpad('&CH_OTHE' , 5 , '&CH_OTHE' ) || '&RESET' chart from dual 326 | ) WHERE '&class' IS NOT NULL 327 | ; 328 | 329 | define 1="" 330 | define 2="" 331 | define 3="" 332 | define 4="" 333 | define 5="" 334 | define 6="" 335 | define 7="" 336 | define 8="" 337 | define 9="" 338 | define 10="" 339 | define 11="" 340 | define 12="" 341 | define 13="" 342 | define 14="" 343 | define 15="" 344 | define 16="" 345 | -------------------------------------------------------------------------------- /em_256colors.sql: -------------------------------------------------------------------------------- 1 | define BG_ONCPU="" 2 | define BG_USER ="" 3 | define BG_SYST ="" 4 | define BG_CONC ="" 5 | define BG_APPL ="" 6 | define BG_COMM ="" 7 | define BG_CONF ="" 8 | define BG_ADMI ="" 9 | define BG_SCHE ="" 10 | define BG_CLUS ="" 11 | define BG_QUEU ="" 12 | define BG_NETW ="" 13 | define BG_OTHE ="" 14 | 15 | define CH_ONCPU=" " 16 | define CH_USER =" " 17 | define CH_SYST =" " 18 | define CH_CONC =" " 19 | define CH_APPL =" " 20 | define CH_COMM =" " 21 | define CH_CONF =" " 22 | define CH_ADMI =" " 23 | define CH_SCHE =" " 24 | define CH_CLUS =" " 25 | define CH_QUEU =" " 26 | define CH_NETW =" " 27 | define CH_OTHE =" " 28 | 29 | define CH_EV1=" " 30 | define CH_EV2=" " 31 | define CH_EV3=" " 32 | define CH_EV4=" " 33 | define CH_EV5=" " 34 | -------------------------------------------------------------------------------- /em_8colors.sql: -------------------------------------------------------------------------------- 1 | define BG_ONCPU="" 2 | define BG_USER ="" 3 | define BG_SYST ="" 4 | define BG_CONC ="" 5 | define BG_APPL ="" 6 | define BG_COMM ="" 7 | define BG_CONF ="" 8 | define BG_ADMI ="" 9 | define BG_SCHE ="" 10 | define BG_CLUS ="" 11 | define BG_QUEU ="" 12 | define BG_NETW ="" 13 | define BG_OTHE ="" 14 | 15 | define CH_ONCPU=" " 16 | define CH_USER =" " 17 | define CH_SYST =" " 18 | define CH_CONC =" " 19 | define CH_APPL =" " 20 | define CH_COMM =" " 21 | define CH_CONF =" " 22 | define CH_ADMI ="a" 23 | define CH_SCHE ="s" 24 | define CH_CLUS ="c" 25 | define CH_QUEU ="q" 26 | define CH_NETW ="n" 27 | define CH_OTHE ="o" 28 | 29 | define CH_EV1=" " 30 | define CH_EV2=" " 31 | define CH_EV3=" " 32 | define CH_EV4=" " 33 | define CH_EV5=" " 34 | -------------------------------------------------------------------------------- /em_nocolors.sql: -------------------------------------------------------------------------------- 1 | define BG_ONCPU="" 2 | define BG_USER ="" 3 | define BG_SYST ="" 4 | define BG_CONC ="" 5 | define BG_APPL ="" 6 | define BG_COMM ="" 7 | define BG_CONF ="" 8 | define BG_ADMI ="" 9 | define BG_SCHE ="" 10 | define BG_CLUS ="" 11 | define BG_QUEU ="" 12 | define BG_NETW ="" 13 | define BG_OTHE ="" 14 | 15 | define CH_ONCPU="." 16 | define CH_USER ="U" 17 | define CH_SYST ="S" 18 | define CH_CONC ="C" 19 | define CH_APPL ="A" 20 | define CH_COMM ="M" 21 | define CH_CONF ="F" 22 | define CH_ADMI ="a" 23 | define CH_SCHE ="s" 24 | define CH_CLUS ="c" 25 | define CH_QUEU ="q" 26 | define CH_NETW ="n" 27 | define CH_OTHE ="o" 28 | 29 | define CH_EV1="1" 30 | define CH_EV2="2" 31 | define CH_EV3="3" 32 | define CH_EV4="4" 33 | define CH_EV5="5" 34 | -------------------------------------------------------------------------------- /fun_convert_raw.sql: -------------------------------------------------------------------------------- 1 | function FUN_CONVERT_RAW (P_VALUE raw, P_DATATYPE VARCHAR2) 2 | return varchar2 3 | is 4 | begin 5 | if P_VALUE is null then return ''; 6 | elsif P_DATATYPE in ('VARCHAR2','CHAR') then return utl_raw.cast_to_varchar2(P_VALUE); 7 | elsif P_DATATYPE = 'NUMBER' then return to_char(utl_raw.cast_to_number(P_VALUE)); 8 | elsif P_DATATYPE = 'DATE' then return TO_CHAR(dbms_stats.convert_raw_to_date(P_VALUE),'yyyy-mm-dd hh24:mi:ss'); 9 | elsif P_DATATYPE like 'TIMESTAMP%WITH TIME ZONE' then return -- if it is TIMESTAMP WITH TIMEZONE, convert from UTC to local time 10 | to_char( 11 | FROM_TZ( 12 | to_timestamp(dbms_stats.convert_raw_to_date(hextoraw(substr(P_VALUE,1,14)))) + 13 | numtodsinterval( nvl( to_number(hextoraw(substr(P_VALUE,15,8)),'XXXXXXXX')/1e9, 0 ), 'SECOND') 14 | , 'UTC' ) at local 15 | ,'yyyy-mm-dd hh24:mi:ss.ff9'); 16 | elsif P_DATATYPE like 'TIMESTAMP%' then return 17 | to_char( 18 | to_timestamp(dbms_stats.convert_raw_to_date(hextoraw(substr(P_VALUE,1,14)))) + 19 | numtodsinterval( nvl( to_number(hextoraw(substr(P_VALUE,15,8)),'XXXXXXXX')/1e9, 0 ), 'SECOND') 20 | ,'yyyy-mm-dd hh24:mi:ss.ff9'); 21 | else return ''; 22 | end if; 23 | end; 24 | -------------------------------------------------------------------------------- /inc/config_vars.sql: -------------------------------------------------------------------------------- 1 | define MYDB="" 2 | define MYSESS_TXT="" 3 | define MYSID="" 4 | define MYSER="" 5 | define MYINST="" 6 | define USE_PROMPT_COLOR=Y 7 | 8 | -- EBS database? 9 | define EBS="N" 10 | col EBS new_value EBS 11 | select 'Y' EBS from all_tables where table_name='FND_USER' and owner='APPLSYS'; 12 | 13 | -- OS specifics 14 | col tmp NEW_VALUE tmp 15 | col PROMPT_COLOR NEW_VALUE PROMPT_COLOR 16 | select 17 | case when upper('&_EDITOR') = 'NOTEPAD' then 'C:\temp' else '/tmp' end as tmp, 18 | case when upper('&_EDITOR') = 'NOTEPAD' then '#&_C_REVERSE' else '#&_CB_CYAN' end as PROMPT_COLOR 19 | from dual; 20 | col tmp clear 21 | col PROMPT_COLOR clear 22 | 23 | -- Get SQLPATH from OS 24 | set echo off ver off feed off pages 0 escape # 25 | select 26 | case when upper('&_EDITOR') = 'NOTEPAD' then 27 | 'host echo define SQLPATH="%SQLPATH%" > config_vars2.tmp' 28 | else 29 | 'host echo define SQLPATH="$SQLPATH" > config_vars2.tmp' 30 | end 31 | from dual 32 | . 33 | spool config_vars.tmp 34 | / 35 | spool off 36 | @config_vars.tmp 37 | @config_vars2.tmp 38 | 39 | -- Configure my session variables 40 | col MYSESS new_value MYSESS 41 | col MYSESS_TXT new_value MYSESS_TXT 42 | col MYDB new_value MYDB 43 | col MYINST new_value MYINST 44 | col MYSID new_value MYSID 45 | col MYSER new_value MYSER 46 | select 47 | sid || ',' || s.serial# || ',@' || sys_context( 'userenv', 'instance' ) as MYSESS, 48 | d.DB_UNIQUE_NAME || '_' || sid || '_' || s.serial# || '_' || sys_context( 'userenv', 'instance' ) as MYSESS_TXT, 49 | d.DB_UNIQUE_NAME MYDB, sid MYSID, s.serial# MYSER, sys_context( 'userenv', 'instance' ) MYINST 50 | from v$session s 51 | cross join v$database d 52 | where sid = userenv('SID'); 53 | col MYSESS clear 54 | col MYSESS_TXT clear 55 | col MYDB clear 56 | col MYINST clear 57 | col MYSID clear 58 | col MYSER clear 59 | -------------------------------------------------------------------------------- /inc/load_set.sql: -------------------------------------------------------------------------------- 1 | @ &tmp/_tmp_load_set_&MYSESS_TXT..sql 2 | -------------------------------------------------------------------------------- /inc/null.sql: -------------------------------------------------------------------------------- 1 | --this is a NULL script to be called to do nothing, instead of an optional other that would do something for particular cases depending on the calling script -------------------------------------------------------------------------------- /inc/reset_pars.sql: -------------------------------------------------------------------------------- 1 | --http://orasql.org/2013/03/29/sqlplus-tips-1/ 2 | 3 | --undef 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 4 | 5 | define 1="" 6 | define 2="" 7 | define 3="" 8 | define 4="" 9 | define 5="" 10 | define 6="" 11 | define 7="" 12 | define 8="" 13 | define 9="" 14 | define 10="" 15 | define 11="" 16 | define 12="" 17 | define 13="" 18 | define 14="" 19 | define 15="" 20 | define 16="" 21 | define DEFAULTVAR1="" 22 | define DEFAULTVAR2="" 23 | define DEFAULTVAR3="" 24 | define DEFAULTVAR4="" 25 | define DEFAULTVAR5="" 26 | 27 | /* 28 | set termout off 29 | COLUMN 1 NEW_VALUE 1 noprint 30 | COLUMN 2 NEW_VALUE 2 noprint 31 | COLUMN 3 NEW_VALUE 3 noprint 32 | COLUMN 4 NEW_VALUE 4 noprint 33 | COLUMN 5 NEW_VALUE 5 noprint 34 | COLUMN 6 NEW_VALUE 6 noprint 35 | COLUMN 7 NEW_VALUE 7 noprint 36 | COLUMN 8 NEW_VALUE 8 noprint 37 | COLUMN 9 NEW_VALUE 9 noprint 38 | COLUMN 10 NEW_VALUE 10 noprint 39 | COLUMN 11 NEW_VALUE 11 noprint 40 | COLUMN 12 NEW_VALUE 12 noprint 41 | COLUMN 13 NEW_VALUE 13 noprint 42 | COLUMN 14 NEW_VALUE 14 noprint 43 | COLUMN 15 NEW_VALUE 15 noprint 44 | COLUMN 16 NEW_VALUE 16 noprint 45 | SELECT '' "1", '' "5", '' "9", '' "13" 46 | ,'' "2", '' "6", '' "10", '' "14" 47 | ,'' "3", '' "7", '' "11", '' "15" 48 | ,'' "4", '' "8", '' "12", '' "16" 49 | FROM dual; 50 | set termout on; 51 | */ 52 | -------------------------------------------------------------------------------- /inc/save_set.sql: -------------------------------------------------------------------------------- 1 | store set &tmp/_tmp_load_set_&MYSESS_TXT..sql replace -------------------------------------------------------------------------------- /null.sql: -------------------------------------------------------------------------------- 1 | --this script is intentionally left empty. It's just to be called and do nothing 2 | -------------------------------------------------------------------------------- /p_delete_cascade.sql: -------------------------------------------------------------------------------- 1 | create or replace procedure P_DELETE_CASCADE ( 2 | /* 3 | Created by EDUARDO CLARO, 2018/03/05 4 | Latest update, 2018/03/26 5 | This procedure is intended to DELETE rows in a table, and all related child rows in all child tables. 6 | The parameters are explained below 7 | The procedure scans all child tables of all levels, recursively, and generates/executes the DELETE statements 8 | */ 9 | p_owner in varchar2, -- owner of the main table 10 | p_table in varchar2, -- the main table 11 | p_constraint in varchar2 default NULL, -- the PK/UK constraint to use in the main_stmt table (if NULL, all) 12 | p_where in varchar2 default '1=1', -- the WHERE clause to define which rows will be DELETED in the main table 13 | p_commit in number default 10000, -- COMMIT interval (rows of the main table) 14 | p_mode in varchar2 default 'GS', -- modes of execution: any combination of: 15 | -- G (generate statements) 16 | -- S (show the statements) 17 | -- X (execute) 18 | -- C (commit) 19 | -- A (ALL = G + X + C) 20 | p_limit in number default 9999, -- limit the number of levels 21 | p_level in number default 1, -- (recursive parameter: the current level of recursive calls) 22 | p_parent_owner in varchar2 default NULL, -- (recursive parameter: the parent owner, will be used to build the recursive DELETE statement) 23 | p_parent_table in varchar2 default NULL, -- (recursive parameter: the parent table, will be used to build the recursive DELETE statement) 24 | p_parent_cols in varchar2 default NULL, -- (recursive parameter: the parent columns, will be used to build the recursive DELETE statement) 25 | p_child_cols in varchar2 default NULL -- (recursive parameter: the child columns, will be used to build the recursive DELETE statement) 26 | ) 27 | is 28 | v_delstmt clob; 29 | v_selstmt clob; 30 | v_where clob; 31 | v_rows number; 32 | v_totalrows number; 33 | v_parent_constraint varchar2(30); 34 | v_child_constraint varchar2(30); 35 | cursor C_CONS is 36 | select 37 | rcon.owner as r_owner, rcon.constraint_name as r_constraint_name, rcon.table_name as r_table_name, 38 | listagg (rcol.column_name, ', ') WITHIN GROUP (ORDER BY rcol.owner, rcol.table_name, rcol.constraint_name) R_COLUMNS, 39 | rcon.constraint_type as type, 40 | con.owner, con.table_name, con.constraint_name, 41 | listagg (col.column_name, ', ') WITHIN GROUP (ORDER BY col.owner, col.table_name, col.constraint_name) XCOLUMNS 42 | from 43 | all_constraints rcon 44 | join all_cons_columns rcol 45 | on rcol.owner=rcon.owner and rcol.table_name=rcon.table_name and rcol.constraint_name=rcon.constraint_name 46 | left join all_constraints con 47 | on rcon.owner = con.r_owner and rcon.constraint_name = con.r_constraint_name 48 | left join all_cons_columns col 49 | on col.owner=con.owner and col.table_name=con.table_name and col.constraint_name=con.constraint_name 50 | and rcol.position = col.position 51 | where rcon.owner = upper(p_owner) and rcon.table_name = upper(p_table) and rcon.constraint_type in ('P','U') 52 | and rcon.constraint_name = nvl(upper(p_constraint),rcon.constraint_name) and rcon.status = 'ENABLED' 53 | group by 54 | rcon.owner, rcon.constraint_name, rcon.table_name, rcon.constraint_type, 55 | con.owner, con.table_name, con.constraint_name 56 | order by rcon.owner, rcon.constraint_name, rcon.constraint_type; 57 | cursor C_STMT is 58 | select * from tmp_delete_cascade_stmt order by lev desc, id; 59 | begin 60 | 61 | ------------------------------------------------------------------------------------------------------------------------------------ 62 | --GENERATE STATEMENTS 63 | if upper(p_mode) like '%G%' OR upper(p_mode) like '%A%' then 64 | 65 | -- start truncating the tables and defining the where clause 66 | if p_level = 1 then 67 | execute immediate 'truncate table tmp_delete_cascade_stmt'; 68 | v_where := p_where; 69 | else 70 | v_where := '(' || p_child_cols || ') in (SELECT ' || chr(10) || p_parent_cols || ' FROM ' || 71 | p_parent_owner || '.' || p_parent_table || ' WHERE ' || chr(10) || p_where || ')' || chr(10); 72 | end if; 73 | 74 | -- show the level and table 75 | if upper(p_mode) like '%S%' then 76 | dbms_output.put_line('================================================================'); 77 | dbms_output.put_line('Level : ' || p_level); 78 | dbms_output.put_line('Table : ' || p_table); 79 | end if; 80 | 81 | -- Build the delete statement 82 | v_delstmt := 'DELETE FROM ' || p_owner || '.' || p_table || ' WHERE ' || v_where; 83 | if upper(p_mode) like '%S%' then 84 | dbms_output.put_line('Statement: ' || chr(10) || v_delstmt); 85 | end if; 86 | 87 | -- Verify if the table has rows to delete 88 | v_selstmt := 'SELECT COUNT(1) FROM ' || p_owner || '.' || p_table || ' WHERE ' || v_where || ' AND ROWNUM = 1'; 89 | execute immediate v_selstmt into v_rows; 90 | 91 | -- Enter in the recursive loop ONLY IF the level is under the limit AND there are rows to delete 92 | if p_level < p_limit AND v_rows = 1 then 93 | 94 | -- Loop of the parent and child constraints 95 | for R_CONS in C_CONS loop 96 | 97 | -- show the level and table 98 | if C_CONS%ROWCOUNT > 1 and upper(p_mode) like '%S%' then 99 | dbms_output.put_line('================================================================'); 100 | dbms_output.put_line('Level : ' || p_level); 101 | dbms_output.put_line('Table : ' || p_table); 102 | end if; 103 | 104 | -- show the parent and child 105 | if upper(p_mode) like '%S%' then 106 | dbms_output.put_line('================================================================'); 107 | dbms_output.put_line('Parent Constraint: '||R_CONS.r_constraint_name); 108 | dbms_output.put_line('Parent Table : '||R_CONS.r_table_name); 109 | dbms_output.put_line('Child Constraint: '||R_CONS.constraint_name); 110 | dbms_output.put_line('Child Table : '||R_CONS.table_name); 111 | end if; 112 | 113 | -- save values to use outside of the loop 114 | v_parent_constraint := R_CONS.r_constraint_name; 115 | v_child_constraint := R_CONS.constraint_name; 116 | 117 | -- If there are child tables 118 | if R_CONS.table_name IS NOT NULL then 119 | -- recursively calls the same procedure 120 | P_DELETE_CASCADE ( 121 | p_owner => R_CONS.owner, 122 | p_table => R_CONS.table_name, 123 | p_where => v_where, 124 | p_commit => p_commit, 125 | p_mode => p_mode, 126 | p_limit => p_limit, 127 | p_level => p_level + 1, 128 | p_parent_owner => R_CONS.r_owner, 129 | p_parent_table => R_CONS.r_table_name, 130 | p_parent_cols => R_CONS.R_COLUMNS, 131 | p_child_cols => R_CONS.XCOLUMNS 132 | ); 133 | end if; 134 | end loop; 135 | end if; 136 | 137 | -- Save the delete statement IF there are rows to delete 138 | if v_rows = 1 then 139 | if upper(p_mode) like '%S%' then 140 | dbms_output.put_line('Registering the statement to delete table ' || p_table); 141 | end if; 142 | insert into tmp_delete_cascade_stmt(id, lev, owner, table_name, parent_constraint, child_constraint, statement) 143 | values (seq_delete_cascade.nextval, p_level, p_owner, p_table, v_parent_constraint, v_child_constraint, v_delstmt); 144 | else 145 | if upper(p_mode) like '%S%' then 146 | dbms_output.put_line('The statement has no rows to delete'); 147 | end if; 148 | end if; 149 | commit; 150 | 151 | end if; 152 | 153 | ------------------------------------------------------------------------------------------------------------------------------------ 154 | --EXECUTE and COMMIT 155 | if p_level = 1 AND (upper(p_mode) like '%A%' OR upper(p_mode) like '%X%' OR upper(p_mode) like '%C') then 156 | 157 | for R_STMT in C_STMT loop 158 | 159 | -- show the statements 160 | if upper(p_mode) like '%S%' then 161 | dbms_output.put_line(''); 162 | dbms_output.put_line('================================================================'); 163 | dbms_output.put_line('Statement ID: ' || R_STMT.id); 164 | dbms_output.put_line(R_STMT.statement); 165 | end if; 166 | 167 | if upper(p_mode) like '%X%' OR upper(p_mode) like '%A%' then 168 | 169 | v_rows := -1; 170 | v_totalrows := 0; 171 | 172 | while v_rows <> 0 loop 173 | v_delstmt := R_STMT.statement || ' AND ROWNUM <= ' || p_commit; 174 | execute immediate v_delstmt; 175 | v_rows := SQL%ROWCOUNT; 176 | v_totalrows := v_totalrows + v_rows; 177 | if upper(p_mode) like '%C%' OR upper(p_mode) like '%A%' then 178 | commit; 179 | end if; 180 | end loop; 181 | 182 | update tmp_delete_cascade_stmt set rows_deleted = v_totalrows where id = R_STMT.id; 183 | if upper(p_mode) like '%C%' OR upper(p_mode) like '%A%' then 184 | commit; 185 | end if; 186 | 187 | if upper(p_mode) like '%S%' then 188 | dbms_output.put_line(v_totalrows || ' rows deleted'); 189 | end if; 190 | end if; 191 | end loop; 192 | end if; 193 | 194 | exception 195 | when others then 196 | dbms_output.put_line(''); 197 | dbms_output.put_line(''); 198 | dbms_output.put_line('================================================================'); 199 | dbms_output.put_line('****** ERROR ******'); 200 | dbms_output.put_line(SQLCODE); 201 | dbms_output.put_line(SQLERRM); 202 | dbms_output.put_line(''); 203 | dbms_output.put_line('Owner: ' || p_owner); 204 | dbms_output.put_line('Table: ' || p_table); 205 | dbms_output.put_line('Level: ' || p_level); 206 | dbms_output.put_line('Last DELETE Statement: ' || chr(10) || v_delstmt); 207 | 208 | end; 209 | / 210 | -------------------------------------------------------------------------------- /p_delete_cascade_create.sql: -------------------------------------------------------------------------------- 1 | undefine schema 2 | alter session set current_schema=&schema; 3 | set serverout on size 1000000 4 | 5 | drop table tmp_delete_cascade_stmt; 6 | drop sequence seq_delete_cascade; 7 | 8 | create table tmp_delete_cascade_stmt ( 9 | id number primary key, lev number, owner varchar2(30), table_name varchar2(30), parent_constraint varchar2(30), 10 | child_constraint varchar2(30), statement clob, rows_deleted number); 11 | create sequence seq_delete_cascade; 12 | 13 | @@p_delete_cascade 14 | -------------------------------------------------------------------------------- /p_delete_cascade_test.sql: -------------------------------------------------------------------------------- 1 | -- Providers 2 | create table T_PROVIDER ( 3 | provider_id number constraint pk_provider primary key, 4 | provider_name varchar2(20) not null 5 | ); 6 | insert into T_PROVIDER values (1,'Provider 1'); 7 | insert into T_PROVIDER values (2,'Provider 2'); 8 | commit; 9 | 10 | -- Warehouses 11 | create table T_WAREHOUSE ( 12 | warehouse_id number constraint pk_warehouse primary key, 13 | warehouse_name varchar2(20) not null 14 | ); 15 | insert into T_WAREHOUSE values (1,'Warehouse 1'); 16 | insert into T_WAREHOUSE values (2,'Warehouse 2'); 17 | commit; 18 | 19 | -- Products 20 | create table T_PRODUCT ( 21 | product_id number constraint pk_product primary key, 22 | product_name varchar2(20) not null, 23 | provider_id number not null constraint fk_prod_prov references T_PROVIDER, 24 | provider_product_id number not null, 25 | product_equivalent number constraint fk_prod_prod references T_PRODUCT, 26 | constraint uk_prov_prodid unique (provider_id, provider_product_id) 27 | ); 28 | insert into T_PRODUCT values (1,'Product 1',1,9991,NULL); 29 | insert into T_PRODUCT values (2,'Product 2',2,9991,1); 30 | insert into T_PRODUCT values (3,'Product 3',1,9992,NULL); 31 | insert into T_PRODUCT values (4,'Product 4',1,9993,NULL); 32 | insert into T_PRODUCT values (5,'Product 5',2,9992,NULL); 33 | insert into T_PRODUCT values (6,'Product 6',2,9993,NULL); 34 | commit; 35 | 36 | -- Products per Warehouses 37 | create table T_PRODUCT_WAREHOUSE ( 38 | product_id number not null constraint fk_prodware_product references T_PRODUCT, 39 | warehouse_id number not null constraint fk_prodware_warehouse references T_WAREHOUSE, 40 | pieces_in_stock number not null, 41 | constraint pk_prodware primary key (product_id, warehouse_id) 42 | ); 43 | insert into T_PRODUCT_WAREHOUSE values (1,1,10); 44 | insert into T_PRODUCT_WAREHOUSE values (1,2,15); 45 | insert into T_PRODUCT_WAREHOUSE values (2,1,7); 46 | insert into T_PRODUCT_WAREHOUSE values (3,1,11); 47 | insert into T_PRODUCT_WAREHOUSE values (4,2,3); 48 | insert into T_PRODUCT_WAREHOUSE values (5,2,1); 49 | insert into T_PRODUCT_WAREHOUSE values (6,1,4); 50 | insert into T_PRODUCT_WAREHOUSE values (6,2,10); 51 | commit; 52 | 53 | -- Invoices 54 | create table T_INVOICE ( 55 | invoice_id number constraint pk_invoice primary key, 56 | invoice_date date default sysdate not null 57 | ); 58 | insert into T_INVOICE values (1,sysdate); 59 | insert into T_INVOICE values (2,sysdate); 60 | insert into T_INVOICE values (3,sysdate); 61 | insert into T_INVOICE values (4,sysdate); 62 | commit; 63 | 64 | -- Invoice Items 65 | create table T_INVOICE_ITEM ( 66 | invoice_id number not null constraint fk_invitem_invoice references T_INVOICE, 67 | product_id number not null constraint fk_invitem_product references T_PRODUCT, 68 | quantity number not null, 69 | constraint pk_invitem primary key (invoice_id,product_id) 70 | ); 71 | insert into T_INVOICE_ITEM values (1,1,2); 72 | insert into T_INVOICE_ITEM values (1,6,1); 73 | insert into T_INVOICE_ITEM values (2,2,5); 74 | insert into T_INVOICE_ITEM values (3,4,3); 75 | insert into T_INVOICE_ITEM values (3,6,4); 76 | insert into T_INVOICE_ITEM values (4,3,5); 77 | commit; 78 | 79 | -- Invoice Items Delivery 80 | create table T_INVOICE_ITEM_DELIVERY ( 81 | invoice_id number not null, 82 | product_id number not null, 83 | delivery_date date default sysdate not null, 84 | quantity_delivered number not null, 85 | constraint pk_invitdel primary key (invoice_id,product_id,delivery_date), 86 | constraint fk_invitdel foreign key (invoice_id,product_id) references T_INVOICE_ITEM 87 | ); 88 | insert into T_INVOICE_ITEM_DELIVERY values (1,1,sysdate-1,1); 89 | insert into T_INVOICE_ITEM_DELIVERY values (1,1,sysdate,1); 90 | insert into T_INVOICE_ITEM_DELIVERY values (1,6,sysdate-1,1); 91 | insert into T_INVOICE_ITEM_DELIVERY values (3,4,sysdate,3); 92 | insert into T_INVOICE_ITEM_DELIVERY values (3,6,sysdate-1,4); 93 | commit; 94 | 95 | -- Generate, execute and show (but don't COMMIT yet) the DELETE statements 96 | begin 97 | P_DELETE_CASCADE( 98 | p_owner=>user, 99 | p_table=>'T_PRODUCT', 100 | p_where=>'product_id in (1,6)', 101 | p_mode => 'GX' 102 | ); 103 | end; 104 | / 105 | 106 | -- Verify the statements and the number of rows affected by each one 107 | col statement for a80 word_wrap 108 | select table_name, statement, rows_deleted from tmp_delete_cascade_stmt order by lev desc, id; 109 | 110 | -- Check which records remain 111 | select * from T_PRODUCT; 112 | select * from T_PRODUCT_WAREHOUSE; 113 | select * from T_INVOICE; 114 | select * from T_INVOICE_ITEM; 115 | select * from T_INVOICE_ITEM_DELIVERY; 116 | 117 | -- Please note that the Invoices 1 and 2 still exist in the T_INVOICE table, despite there is no child record in T_INVOICE_ITEM for them. 118 | -- This is normal because this rule is not enforced by any constraint, so I must delete them manually. 119 | -------------------------------------------------------------------------------- /parser.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Parameter parser 3 | 4 | This script transform all the parameters (&1-&16) into SQL*Plus variables 5 | 6 | Created by Eduardo Claro, 2018-3-15 7 | Last changes on 2021-11-12 8 | 9 | Usage 10 | 11 | @parser PAR=value PAR=value ... 12 | 13 | You can pass up to 16 parameters in no specific order. 14 | To pass parameters with spaces or other special characters, use "" and '' like in the examples below. 15 | In order for this to work properly, the number variables should be pre-defined as NULL in the login.sql. 16 | The general format to pass the parameters is PAR=value. 17 | If caller script have defined a default variable, then you can call it just passing the parameter value (see examples). 18 | 19 | If the first parameter is HELP, it creates a variable HELP=Y 20 | 21 | I always issue "set term off" before running this script, and "set term on" after it, to not show the results in the terminal. 22 | 23 | Examples: 24 | 25 | @parser VAR1='X' "VAR2='A B C'" VAR3= 26 | this would result in: 27 | DEFINE VAR1 = "X" 28 | DEFINE VAR2 = "A B C" 29 | 30 | @parser ABC123 XYZ 31 | this would result in: 32 | DEFINE &DEFAULTVAR1 = "ABC123" 33 | DEFINE &DEFAULTVAR2 = "XYZ" 34 | */ 35 | set term off 36 | define HELP="" 37 | store set set.tmp replace 38 | set feed off ver off echo off head off timing off 39 | spool parser.tmp REPLACE 40 | select 41 | case 42 | when upper(q'!&1!') in ('HELP','HLP') then 'define HELP=Y' 43 | when q'!&1!' not like '%=%' then 'define &DEFAULTVAR1=' || q'!&1!' 44 | when q'!&1!' is not null then regexp_replace(q'!define &1."!','=','="',1,1) end || chr(10) || 45 | case 46 | when q'!&2!' not like '%=%' then 'define &DEFAULTVAR2=' || q'!&2!' 47 | when q'!&2!' is not null then regexp_replace(q'!define &2."!','=','="',1,1) end || chr(10) || 48 | case 49 | when q'!&3!' not like '%=%' then 'define &DEFAULTVAR3=' || q'!&3!' 50 | when q'!&3!' is not null then regexp_replace(q'!define &3."!','=','="',1,1) end || chr(10) || 51 | case 52 | when q'!&4!' not like '%=%' then 'define &DEFAULTVAR4=' || q'!&4!' 53 | when q'!&4!' is not null then regexp_replace(q'!define &4."!','=','="',1,1) end || chr(10) || 54 | case when q'!&5!' is not null then regexp_replace(q'!define &5."!','=','="',1,1) end || chr(10) || 55 | case when q'!&6!' is not null then regexp_replace(q'!define &6."!','=','="',1,1) end || chr(10) || 56 | case when q'!&7!' is not null then regexp_replace(q'!define &7."!','=','="',1,1) end || chr(10) || 57 | case when q'!&8!' is not null then regexp_replace(q'!define &8."!','=','="',1,1) end || chr(10) || 58 | case when q'!&9!' is not null then regexp_replace(q'!define &9."!','=','="',1,1) end || chr(10) || 59 | case when q'!&10!' is not null then regexp_replace(q'!define &10."!','=','="',1,1) end || chr(10) || 60 | case when q'!&11!' is not null then regexp_replace(q'!define &11."!','=','="',1,1) end || chr(10) || 61 | case when q'!&12!' is not null then regexp_replace(q'!define &12."!','=','="',1,1) end || chr(10) || 62 | case when q'!&13!' is not null then regexp_replace(q'!define &13."!','=','="',1,1) end || chr(10) || 63 | case when q'!&14!' is not null then regexp_replace(q'!define &14."!','=','="',1,1) end || chr(10) || 64 | case when q'!&15!' is not null then regexp_replace(q'!define &15."!','=','="',1,1) end || chr(10) || 65 | case when q'!&16!' is not null then regexp_replace(q'!define &16."!','=','="',1,1) end statement 66 | from dual; 67 | spool off 68 | @parser.tmp 69 | @set.tmp 70 | set term on 71 | -------------------------------------------------------------------------------- /sqlmon.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script generates a SQL Monitor report for a specific run of a query 3 | 4 | Created by Eduardo Claro 5 | Last changes on 2021-11-12 6 | 7 | See the help below in the query 8 | */ 9 | 10 | set term off 11 | @inc/save_set 12 | 13 | -- Default values for the parameters 14 | define type="" 15 | define sqlid="" 16 | define phv="" 17 | define exec="" 18 | define begin="sysdate-1" 19 | define end="sysdate" 20 | define min="0" 21 | define tim="" 22 | define bd="" 23 | define ed="" 24 | define user="" 25 | define src="A" 26 | define out="A" 27 | define secs=0 28 | define DEFAULTVAR1="type" 29 | define DEFAULTVAR2="sqlid" 30 | define DEFAULTVAR3="phv" 31 | define DEFAULTVAR4="exec" 32 | 33 | def KEYREP="" 34 | 35 | -- Parse the received parameters 36 | @@parser 37 | 38 | set term off 39 | col QUERY NEW_VALUE QUERY 40 | col datini new_value datini 41 | col datfin new_value datfin 42 | coL SCRIPT NEW_VALUE SCRIPT 43 | col SQLID NEW_VALUE SQLID 44 | col TYPE NEW_VALUE TYPE 45 | select 46 | case 47 | when upper('&HELP') in ('S','Y') or upper('&TYPE') in ('D','M') then 'help' 48 | else 'main' 49 | end QUERY, 50 | case 51 | when upper('&HELP') in ('S','Y') or '&OUT' = '0' then 'null' 52 | when upper('&TYPE') in ('C') then 'null' 53 | when upper('&TYPE') in ('D','M') then 'sqlmond1' 54 | else 'sqlmon2' 55 | end SCRIPT, 56 | case 57 | when to_number('&MIN') < 0 then q'[trunc(sysdate,'mi')+(&MIN./24/60)]' 58 | when to_number('&MIN') > 0 then q'[&begin]' 59 | when '&bd' is not null then q'[to_date('&bd','yyyy/mm/dd-hh24:mi')]' 60 | else q'[&begin]' 61 | end datini, 62 | case 63 | when to_number('&MIN') < 0 then 'sysdate' 64 | when to_number('&MIN') > 0 then q'[&begin.+&MIN./24/60]' 65 | when '&ed' is not null then q'[to_date('&ed','yyyy/mm/dd-hh24:mi')]' 66 | else q'[&END]' 67 | end datfin, 68 | case 69 | when upper('&TYPE') NOT in ('R','C','D','M') then '&TYPE' 70 | else '&SQLID' 71 | end SQLID, 72 | case 73 | when upper('&TYPE') NOT in ('R','C','D','M') then 'R' 74 | else '&TYPE' 75 | end TYPE 76 | from dual; 77 | col TIM new_value TIM 78 | select nvl('&TIM',decode(upper('&TYPE'),'D',0,1)) TIM from dual where upper('&TYPE') in ('M','D'); 79 | 80 | col OBJECT_NODE NEW_VALUE OBJECT_NODE 81 | select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') OBJECT_NODE from dual; 82 | INSERT INTO PLAN_TABLE ( 83 | STATEMENT_ID/*'SQLMON'*/,OBJECT_NODE/*SYSDATE*/, REMARKS/*SRC*/,PLAN_ID/*KEYREP*/, 84 | OPERATION/*SQL_ID*/,ID/*SQL_EXEC_ID*/,OPTIONS/*USERNAME*/, 85 | PARENT_ID/*SQL_PLAN_HASH_VALUE*/,DEPTH/*FMS*/,OTHER_TAG/*STATUS*/, 86 | TIMESTAMP/*EXEC_START*/,PARTITION_STOP/*LAST_REFR*/, 87 | COST/*SECS*/, ACCESS_PREDICATES/*SQL_TEXT*/ 88 | ) 89 | WITH 90 | mem as ( 91 | select * 92 | from ( 93 | select key, report_id, sql_id, SQL_EXEC_ID, USERNAME, 94 | SQL_PLAN_HASH_VALUE, force_matching_signature FMS, status, sql_exec_start, 95 | LAST_REFRESH_TIME, (LAST_REFRESH_TIME - sql_exec_start) *24*60*60 SECS, 96 | sql_text 97 | from gv$sql_monitor 98 | where (SQL_ID='&sqlid' or '&sqlid' is null) 99 | and (SQL_PLAN_HASH_VALUE = to_number('&phv') or '&phv' is null) 100 | and (SQL_EXEC_ID = to_number('&exec') or '&exec' is null) 101 | and SQL_PLAN_HASH_VALUE <> 0 102 | and nvl(PX_QCSID,SID) = SID and nvl(PX_QCINST_ID,INST_ID) = INST_ID --don't show Parallel slaves 103 | and upper('&SRC') <> 'H' 104 | and sql_exec_start between &datini and &datfin 105 | and (username = upper('&USER') or '&USER' is null) 106 | ) 107 | where secs >= &secs 108 | ), 109 | hist as ( 110 | select * 111 | from ( 112 | select a.*, (LAST_REFRESH_TIME - sql_exec_start) *24*60*60 SECS 113 | from 114 | ( 115 | select report_id, KEY1 as SQL_ID, to_number(KEY2) as SQL_EXEC_ID, GENERATION_TIME, 116 | to_date(key3,'mm:dd:yyyy hh24:mi:ss') as sql_exec_start, 117 | -- to_date(EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/@sql_exec_start'),'mm/dd/yyyy hh24:mi:ss') sql_exec_start, 118 | EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/status') status, 119 | to_date(EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/last_refresh_time'),'mm/dd/yyyy hh24:mi:ss') last_refresh_time, 120 | EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/sql_text') sql_text, 121 | EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/user') username, 122 | to_number(EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/plan_hash')) SQL_PLAN_HASH_VALUE 123 | from DBA_HIST_REPORTS 124 | where component_name = 'sqlmonitor' 125 | AND report_name = 'main' 126 | AND (KEY1='&sqlid' or '&sqlid' is null) 127 | and (to_number(EXTRACTVALUE(XMLType(report_summary),'/report_repository_summary/sql/plan_hash')) = to_number('&phv') or '&phv' is null) 128 | and (KEY2 = '&exec' or '&exec' is null) 129 | and upper('&SRC') <> 'M' 130 | and GENERATION_TIME between &datini and &datfin 131 | ) a 132 | ) 133 | where secs >= &secs 134 | and (username = upper('&USER') or '&USER' is null) 135 | ) 136 | select 137 | 'SQLMON', '&OBJECT_NODE', 138 | case when mem.SQL_PLAN_HASH_VALUE is not null then 'MEM' else 'HIST' end SRC, 139 | coalesce(mem.KEY, hist.REPORT_ID) keyrep, 140 | SQL_ID, SQL_EXEC_ID, 141 | coalesce(mem.USERNAME, hist.USERNAME) USERNAME, 142 | coalesce(mem.SQL_PLAN_HASH_VALUE, hist.SQL_PLAN_HASH_VALUE) SQL_PLAN_HASH_VALUE, mem.FMS, 143 | coalesce(mem.STATUS, hist.STATUS) STATUS, coalesce(mem.SQL_EXEC_START, hist.SQL_EXEC_START) EXEC_START, 144 | to_char(coalesce(mem.LAST_REFRESH_TIME,hist.LAST_REFRESH_TIME),'yyyy-mm-dd hh24:mi:ss') LAST_REFR, 145 | coalesce(mem.SECS, hist.SECS) SECS, coalesce(mem.SQL_TEXT, hist.SQL_TEXT) SQL_TEXT 146 | from mem 147 | full join hist using (SQL_ID, SQL_EXEC_ID) 148 | where nvl(upper('&HELP'),'N') NOT in ('S','Y') 149 | and nvl(upper('&TYPE'),'R') NOT in ('D','M') 150 | ; 151 | set term on 152 | 153 | col keyrep NEW_VALUE KEYREP for 9999999999999 154 | col module for a16 trunc 155 | col action for a20 trunc 156 | col sql_text for a35 trunc 157 | col refresh_count for 9999 head "REFRs" 158 | col FMS for 999999999999999999999 159 | col SECS for 99999 160 | set tab off 161 | col KEYREP head "KEY/REPORT_ID" 162 | col SRC for a4 163 | col zSTATUS head "STATUS" for a20 trunc 164 | col SQL_EXEC_START for a20 165 | 166 | WITH 167 | help as ( 168 | select q'[ 169 | Usage: 170 | START sqlmon par=value par=value ... 171 | 172 | Parameters (can be passed in any order in the form parameter=value) 173 | type : (first MANDATORY parameter) the type of execution: 174 | c = just checks (shows) the reports available 175 | r = after seeing the the reports available you can inform one to extract the SQL Monitor report (the default value) 176 | d = details (execution plan and associated statistics) of a specific execution (finished or not). Only for src=M. 177 | m = monitor a running SQL in real time, showing stats for each row that have change over the last &tim minutes. Only for src=M. 178 | sqlid: (default second parameter) the SQL_ID 179 | phv : (default third parameter) the PLAN_HASH_VALUE 180 | exec : (default fourth parameter) the SQL_EXEC_ID 181 | tim : time in minutes to show in SQL Monitor details (just for type=M, default 1) 182 | user : the USERNAME 183 | src : the source. Enter H to query the history view or M to query memory. Any other value will bring both. 184 | secs : minimum seconds (default 0) 185 | out : the output type of the report: 186 | A = active (the default value) 187 | H = html 188 | T = text 189 | 0 = none 190 | 191 | To filter queries by their SQL_EXEC_START (for type R/C): 192 | begin: begin date as a DATE expression, like sysdate-1 (the default value). 193 | end : end date as a DATE expression, like sysdate (the default value). 194 | min : interval in minutes, can only be combined with begin/end, not bd/ed. 195 | if a positive number is provided, the period is defined starting with begin and ending the number of minutes after that (end parameter is ignored). 196 | if a negative number is provided, the period is defined starting the number of minutes before now (sysdate) and ending now (begin and end are ignored). 197 | bd : begin date (use format 'yyyy/mm/dd-hh24:mi'). 198 | ed : begin date (use format 'yyyy/mm/dd-hh24:mi'). 199 | -- 200 | 201 | Example: 202 | START sqlmon 92y2r3d37mxg5 203 | START sqlmon src=H sqlid=92y2r3d37mxg5 user=CLAROE 204 | ]' HELPTXT 205 | from dual 206 | where upper('&HELP') in ('S','Y') 207 | ), 208 | --============================================================================================================== 209 | main as ( 210 | select 211 | REMARKS as SRC, PLAN_ID as KEYREP, 212 | OPERATION as SQL_ID, PARENT_ID as SQL_PLAN_HASH_VALUE, ID as SQL_EXEC_ID, 213 | OPTIONS as USERNAME, DEPTH as FMS, OTHER_TAG as zSTATUS, 214 | TIMESTAMP as EXEC_START, to_date(PARTITION_STOP,'yyyy-mm-dd hh24:mi:ss') as LAST_REFR, 215 | COST as SECS, ACCESS_PREDICATES as SQL_TEXT 216 | from plan_table 217 | where STATEMENT_ID = 'SQLMON' 218 | and OBJECT_NODE = '&OBJECT_NODE' 219 | and COST /*SECS*/ >= &secs 220 | order by EXEC_START 221 | ) 222 | --============================================================================================================== 223 | select * from &QUERY 224 | ; 225 | 226 | set term off 227 | select case when '&KEYREP' is NULL and '&SCRIPT' = 'sqlmon2' then 'null' else '&SCRIPT' end SCRIPT from dual; 228 | set term on 229 | 230 | @@&SCRIPT 231 | 232 | @inc/load_set 233 | set term on 234 | 235 | @@inc/reset_pars 236 | -------------------------------------------------------------------------------- /sqlmon2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script is a continuation of sqlmon.sql. 3 | It shows the SQL Monitor options to select one for the report generation. 4 | 5 | Created by Eduardo Claro 6 | Last changes on 2021-8-13 7 | */ 8 | 9 | set NUMWIDTH 15 10 | prompt 11 | accept KEYREP DEF "&KEYREP" prompt 'KEY/REPORT_ID for the report [&KEYREP]: ' 12 | --accept OUT DEF "A" prompt 'Output type (A=Active/H=Html/T=Text) [A]: ' 13 | 14 | set term off 15 | col sqlid new_value sqlid 16 | select 17 | OPERATION as SQLID 18 | from plan_table 19 | where STATEMENT_ID = 'SQLMON' 20 | and OBJECT_NODE = '&OBJECT_NODE' 21 | and PLAN_ID=to_number(nvl('&KEYREP','0')) 22 | ; 23 | col SPOOL NEW_VALUE SPOOL 24 | col TYPE NEW_VALUE TYPE 25 | col SCRIPT NEW_VALUE SCRIPT 26 | select 27 | '&tmp/sqlmon_&sqlid._' || trim('&KEYREP.') || 28 | decode(upper('&OUT'),'A','_ACTIVE.','H','_HTML.','T','.','_ACTIVE.') || 29 | decode(upper('&OUT'),'A','html','H','html','T','txt','html') SPOOL, 30 | decode(upper('&OUT'),'A','ACTIVE','H','HTML','T','TXT','ACTIVE') TYPE, 31 | case when '&KEYREP' is NULL or '&KEYREP' = '0' then 'null' else 'sqlmon3' end SCRIPT 32 | from dual; 33 | 34 | @@&SCRIPT 35 | -------------------------------------------------------------------------------- /sqlmon3.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script is a continuation of sqlmon.sql 3 | 4 | Created by Eduardo Claro 5 | Last changes on 2021-8-12 6 | */ 7 | 8 | /* 9 | https://sqlmaria.com/2017/08/01/getting-the-most-out-of-oracle-sql-monitor/?unapproved=15990&moderation-hash=345d82d91085062ece092c8cd001201e#comment-15990 10 | Disabling SQL Monitor compression that hits a bug (28649388) when < 18C RU 18.4, that makes the SQL Monitor not display for very large reports 11 | */ 12 | alter session set events = 'emx_control compress_xml=none'; 13 | set term on 14 | ---------------------- 15 | set lines 32767 trimout on trimspool on head off feed off echo off timing off termout off long 1000000 longchunksize 1000000 ver off pages 0 16 | spool &SPOOL 17 | select DBMS_SQL_MONITOR.report_sql_monitor( 18 | sql_id => a.OPERATION, 19 | sql_exec_start => a.TIMESTAMP, 20 | sql_exec_id => a.ID, 21 | report_level=>'ALL',type=>'&TYPE') 22 | from plan_table a 23 | where STATEMENT_ID = 'SQLMON' 24 | and OBJECT_NODE = '&OBJECT_NODE' 25 | and PLAN_ID=to_number(nvl('&KEYREP','0')) 26 | and REMARKS='MEM' 27 | UNION ALL 28 | select dbms_auto_report.Report_repository_detail( 29 | RID => to_number(nvl('&KEYREP','0')), 30 | TYPE => '&TYPE') 31 | from plan_table a 32 | where STATEMENT_ID = 'SQLMON' 33 | and OBJECT_NODE = '&OBJECT_NODE' 34 | and PLAN_ID=to_number(nvl('&KEYREP','0')) 35 | and REMARKS='HIST' 36 | ; 37 | spool off 38 | 39 | prompt 40 | prompt Report generated on "&SPOOL" 41 | -------------------------------------------------------------------------------- /sqlmond.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script sets variables and call sqlmond1.sql 3 | 4 | Created by Eduardo Claro on 2021-10-6 5 | Last changes on 2021-11-10 6 | 7 | Parameter 1: SQL_ID 8 | Parameter 2: PLAN_HASH_VALUE 9 | Parameter 3: SQL_EXEC_ID (optional) 10 | Parameter 4: minutes (0=show all, default 1) 11 | */ 12 | 13 | def sqlid="&1" 14 | def phv="&2" 15 | def exec="&3" 16 | def tim="&4" 17 | @@sqlmond1 18 | -------------------------------------------------------------------------------- /sqlmond0.sql: -------------------------------------------------------------------------------- 1 | --set term off 2 | def 1="&sqlid" 3 | def 2="&phv" 4 | def 3="&exec" 5 | def 4="&tim" 6 | set term on 7 | @@sqlmond1 8 | -------------------------------------------------------------------------------- /sqlmond1.sql: -------------------------------------------------------------------------------- 1 | /* 2 | This script shows the SQL Monitor details for a given SQL while it's running 3 | It shows the steps that had changes in stats for the last minute 4 | 5 | Created by Eduardo Claro on 2021-8-3 6 | Last changes on 2021-11-11 7 | 8 | Parameter 1: SQL_ID 9 | Parameter 2: PLAN_HASH_VALUE 10 | Parameter 3: SQL_EXEC_ID (optional) 11 | Parameter 4: minutes (0=show all, default 1) 12 | */ 13 | 14 | col OBJECT for a40 15 | col OPOP for a50 16 | col OPOB for a80 head "OPERATION + OPTIONS + OBJECT" 17 | col OUT_ROWS for 999999999999 18 | col FIRST_CHG_TIME for a20 19 | col LAST_CHG_TIME for a20 20 | 21 | compute sum of STARTS on report 22 | compute min max of LINE_ID on report 23 | compute sum of OUT_ROWS on report 24 | break on report 25 | 26 | WITH q as ( 27 | select KEY, INST_ID, CON_ID, SQL_EXEC_ID, SID 28 | from gv$sql_monitor 29 | where sql_id='&sqlid' and SQL_PLAN_HASH_VALUE='&phv' 30 | and (SQL_EXEC_ID = '&exec' or '&exec' is null) 31 | and rownum=1 32 | ), 33 | ash as ( 34 | select * from ( 35 | select 36 | ash.SQL_PLAN_LINE_ID, s.SID, s.INST_ID, s.SQL_EXEC_ID, 37 | row_number() over (partition by s.inst_id, s.sid, s.SERIAL# order by sample_id desc) rn 38 | from gv$active_session_history ash 39 | join gv$session s 40 | on s.status = 'ACTIVE' 41 | and ash.inst_id = s.inst_id 42 | and ash.session_id = s.sid 43 | and ash.SESSION_SERIAL# = s.SERIAL# 44 | and ash.sql_id = s.sql_id 45 | and ash.sql_exec_id = s.sql_exec_id 46 | and ash.sample_time >= sysdate - 10/24/60/60 --s.sql_exec_start 47 | where ash.sql_id='&sqlid' and ash.SQL_PLAN_HASH_VALUE='&phv' 48 | and (ash.SQL_EXEC_ID = '&exec' or '&exec' is null) 49 | ) 50 | where rn=1 51 | ) 52 | select 53 | -- spm.CON_ID , 54 | -- spm.KEY , 55 | -- spm.STATUS , 56 | -- to_char(FIRST_REFRESH_TIME,'YY-MM-DD hh24:mi:ss') as FIRST_REF_TIME, 57 | -- to_char(LAST_REFRESH_TIME,'YY-MM-DD hh24:mi:ss') as LAST_REF_TIME, 58 | to_char(spm.FIRST_CHANGE_TIME,'YY-MM-DD hh24:mi:ss') as FIRST_CHG_TIME, 59 | to_char(spm.LAST_CHANGE_TIME,'YY-MM-DD hh24:mi:ss') as LAST_CHG_TIME, 60 | -- spm.REFRESH_COUNT as REF_CNT, 61 | -- spm.SID , 62 | -- spm.PROCESS_NAME , 63 | -- spm.SQL_ID , 64 | -- spm.SQL_EXEC_START , 65 | -- spm.SQL_EXEC_ID , 66 | -- spm.SQL_PLAN_HASH_VALUE , 67 | -- spm.SQL_CHILD_ADDRESS , 68 | -- spm.PLAN_PARENT_ID , 69 | case when coalesce(spm.PLAN_LINE_ID,ash.SQL_PLAN_LINE_ID) = lop.SQL_PLAN_LINE_ID then '==>' else '' end CUR, 70 | spm.PLAN_LINE_ID as LINE_ID, 71 | spm.STARTS , 72 | spm.OUTPUT_ROWS OUT_ROWS, 73 | lpad(' ',spm.PLAN_DEPTH,' ') || spm.PLAN_OPERATION || ' ' || spm.PLAN_OPTIONS || ' ' || 74 | case when spm.PLAN_OBJECT_OWNER is NULL then '' else spm.PLAN_OBJECT_OWNER || '.' end || spm.PLAN_OBJECT_NAME as OPOB, 75 | spm.PLAN_COST as COST, 76 | spm.PLAN_CARDINALITY as CARD, 77 | spm.PLAN_BYTES as BYTES, 78 | spm.PLAN_DEPTH as DEPTH, 79 | spm.PLAN_POSITION as POS, 80 | -- spm.PLAN_TIME , 81 | -- spm.PLAN_PARTITION_START , 82 | -- spm.PLAN_PARTITION_STOP , 83 | -- spm.PLAN_CPU_COST , 84 | -- spm.PLAN_IO_COST , 85 | -- spm.PLAN_TEMP_SPACE , 86 | -- spm.IO_INTERCONNECT_BYTES , 87 | -- spm.PHYSICAL_READ_REQUESTS , 88 | -- spm.PHYSICAL_READ_BYTES , 89 | -- spm.PHYSICAL_WRITE_REQUESTS , 90 | -- spm.PHYSICAL_WRITE_BYTES , 91 | -- spm.WORKAREA_MEM , 92 | -- spm.WORKAREA_MAX_MEM , 93 | -- spm.WORKAREA_TEMPSEG , 94 | -- spm.WORKAREA_MAX_TEMPSEG , 95 | -- spm.OTHERSTAT_GROUP_ID , 96 | -- spm.OTHERSTAT_1_ID , 97 | -- spm.OTHERSTAT_1_TYPE , 98 | -- spm.OTHERSTAT_1_VALUE , 99 | -- spm.OTHERSTAT_2_ID , 100 | -- spm.OTHERSTAT_2_TYPE , 101 | -- spm.OTHERSTAT_2_VALUE , 102 | -- spm.OTHERSTAT_3_ID , 103 | -- spm.OTHERSTAT_3_TYPE , 104 | -- spm.OTHERSTAT_3_VALUE , 105 | -- spm.OTHERSTAT_4_ID , 106 | -- spm.OTHERSTAT_4_TYPE , 107 | -- spm.OTHERSTAT_4_VALUE , 108 | -- spm.OTHERSTAT_5_ID , 109 | -- spm.OTHERSTAT_5_TYPE , 110 | -- spm.OTHERSTAT_5_VALUE , 111 | -- spm.OTHERSTAT_6_ID , 112 | -- spm.OTHERSTAT_6_TYPE , 113 | -- spm.OTHERSTAT_6_VALUE , 114 | -- spm.OTHERSTAT_7_ID , 115 | -- spm.OTHERSTAT_7_TYPE , 116 | -- spm.OTHERSTAT_7_VALUE , 117 | -- spm.OTHERSTAT_8_ID , 118 | -- spm.OTHERSTAT_8_TYPE , 119 | -- spm.OTHERSTAT_8_VALUE , 120 | -- spm.OTHERSTAT_9_ID , 121 | -- spm.OTHERSTAT_9_TYPE , 122 | -- spm.OTHERSTAT_9_VALUE , 123 | -- spm.OTHERSTAT_10_ID , 124 | -- spm.OTHERSTAT_10_TYPE , 125 | -- spm.OTHERSTAT_10_VALUE , 126 | -- spm.OTHER_XML , 127 | -- spm.PLAN_OPERATION_INACTIVE , 128 | 0 dummy 129 | from gv$sql_plan_monitor spm 130 | join q on q.KEY = spm.KEY and q.INST_ID = spm.INST_ID and q.CON_ID = spm.CON_ID 131 | left join gv$session_longops lop on lop.INST_ID = q.INST_ID and lop.SID = q.SID and q.SQL_EXEC_ID = lop.SQL_EXEC_ID and lop.SOFAR < lop.TOTALWORK 132 | left join ash on q.SID = ash.SID and q.INST_ID = ash.INST_ID and q.SQL_EXEC_ID = ash.SQL_EXEC_ID 133 | where (spm.LAST_CHANGE_TIME >= sysdate - nvl(to_number('&tim'),1)/24/60 or to_number('&tim')=0) 134 | order by spm.PLAN_LINE_ID 135 | ; 136 | 137 | /* 138 | select report 139 | from DBA_HIST_REPORTS_details 140 | where report_Id=7990232 141 | ; 142 | 143 | SELECT 144 | XMLSERIALIZE( DOCUMENT 145 | XMLTYPE ( 146 | report 147 | ) as CLOB INDENT) report 148 | FROM dba_hist_reports_details 149 | WHERE report_id =7990232 150 | ; 151 | 152 | select 153 | --report 154 | extractvalue(XMLType(report),'/sql_monitor_report/report_parameters/sql_id') sql_id 155 | -- extractvalue(XMLType(report_summary),'/report_repository_summary/sql/@sql_exec_id') sql_exec_id, 156 | -- extractvalue(XMLType(report_summary),'/report_repository_summary/sql/@sql_exec_start') sql_exec_start 157 | from DBA_HIST_REPORTS_details 158 | where report_Id=7990232 159 | ; 160 | 161 | SELECT report_id 162 | FROM XMLTABLE 163 | ('//report_repository_summary/sql/report_id' 164 | PASSING XMLTYPE (REPORT) 165 | COLUMNS 166 | report_id NUMBER PATH '.') 167 | from DBA_HIST_REPORTS_details 168 | where report_Id=7990232 169 | ; 170 | 171 | SELECT VALUE(p) AS elemento 172 | FROM 173 | ( 174 | SELECT XMLTYPE(REPORT) AS xmlrep 175 | FROM DBA_HIST_REPORTS_details 176 | where report_Id=7990232 177 | ) t , 178 | TABLE(xmlsequence(extract(xmlrep, '/report_repository_summary/sql/last_refresh_time'))) p 179 | ; 180 | 181 | select 182 | extractvalue(XMLType(report_summary),'/report_repository_summary/sql/@sql_id') sql_id, 183 | extractvalue(XMLType(report_summary),'/report_repository_summary/sql/@sql_exec_id') sql_exec_id, 184 | extractvalue(XMLType(report_summary),'/report_repository_summary/sql/@sql_exec_start') sql_exec_start, 185 | REPORT_SUMMARY 186 | from DBA_HIST_REPORTS a 187 | where report_Id=7990232 188 | ; 189 | */ 190 | 191 | @inc/reset_pars 192 | -------------------------------------------------------------------------------- /term_256colors.sql: -------------------------------------------------------------------------------- 1 | /* Show all the 256 colors (if the terminal have this capability) */ 2 | 3 | col color for a200 4 | 5 | prompt 6 | prompt Background colors. USAGE: chr(27) || '[48;5;' || number 7 | define x=48 8 | select 9 | 'id=' || to_char(4 * (level-1) + 1,'999') || 10 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 1 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 11 | 'id=' || to_char(4 * (level-1) + 2,'999') || 12 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 2 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 13 | 'id=' || to_char(4 * (level-1) + 3,'999') || 14 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 3 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 15 | 'id=' || to_char(4 * (level-1) + 4,'999') || 16 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 4 ) || 'm' || ' COLOR ' || chr(27) || '[0m' color 17 | from dual connect by level <= 256/4; 18 | 19 | prompt 20 | prompt Foreground colors USAGE: chr(27) || '[38;5;' || number 21 | define x=38 22 | select 23 | 'id=' || to_char(4 * (level-1) + 1,'999') || 24 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 1 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 25 | 'id=' || to_char(4 * (level-1) + 2,'999') || 26 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 2 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 27 | 'id=' || to_char(4 * (level-1) + 3,'999') || 28 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 3 ) || 'm' || ' COLOR ' || chr(27) || '[0m' || ' ' || 29 | 'id=' || to_char(4 * (level-1) + 4,'999') || 30 | chr(27) || '[&x.;5;' || ( 4 * (level-1) + 4 ) || 'm' || ' COLOR ' || chr(27) || '[0m' color 31 | from dual connect by level <= 256/4; 32 | --------------------------------------------------------------------------------