Tag Info

Hot answers tagged

13

I think this is what you're after: V_COUNT := MY_ARRAY.COUNT;


12

Benefits of Packages Logical Grouping – Methods that work together can be put into a cohesive unit rather than just logically coupled but physically separate. Secure Private Methods - Functions and Procedures can be made private to the package and only be used within it. This makes the public surface simpler and more secure. Privilege Management – ...


12

The code you posted is using a cursor. It is using an implicit cursor loop. There are cases where using an explicit cursor loop (i.e. declaring a CURSOR variable in the declaration section) produces either cleaner code or better performance If you have more complex queries that you can't refactor out into views, it can make the code easier to read if ...


10

You can do this with DBMS_LOCK and an exclusive lock. See the following procedure: CREATE OR REPLACE PROCEDURE myproc IS lockhandle VARCHAR2(128); retcode NUMBER; BEGIN DBMS_LOCK.ALLOCATE_UNIQUE('myproclock',lockhandle); retcode:=DBMS_LOCK.REQUEST(lockhandle,timeout=>0, lockmode=>DBMS_LOCK.x_mode); IF retcode<>0 THEN ...


10

If T2 is derived data based on the contents of T1, then you may want to replace T2 with a materialized view. If T2 is rarely accessed, and quick to derive, then you may just want to use a view. On the application side, if you stop maintaining table T2, then the values it gets will become increasing incorrect. This can be partially corrected by ...


10

If you're really only looking to learn about the development side and have no interest in the administration or installation side at the moment, a quicker route might be to download a prebuilt developer VM image for Virtualbox. That can get you up and running very quickly, and you can connect to the DB running inside the VM from outside, so you can continue ...


10

Oracle's official documentation library has some great resources, including: The Database Concepts guide, which is essential reading for beginner and Oracle ninja alike. The 2 Day DBA The 2 Day Developer's Guide


9

Its an interesting question, to be sure. Most people who are familiar with Oracle development wouldn't give it a thought but when you come down to it, its sometimes confusing to define the demarcation between SQL and PL/SQL. By looking at the definition of the acronyms, you start to get an idea of what areas of functionality each covers: SQL - Structured ...


9

If it is wrapped in BEGIN ... END DECLARE ... END CREATE OR REPLACE ... END Is a one-liner prefixed EXECUTE Then it is PL/SQL. What does this mean under the hood? SQL gets "compiled" to a query plan and executed, immediately returning a result set in the event of SELECT or the number of rows affected in other cases, or an error. PL/SQL however is more ...


8

Here is an example of the API structure to replace a trigger. By calling the AddEntry procedure in the package, the data is inserted into both tables. CREATE OR REPLACE PACKAGE MyPackage IS Procedure AddEntry (pValue1 IN Number, pValue2 IN Number); END; / CREATE OR REPLACE PACKAGE BODY MyPackage IS Procedure AddEntry (pValue1 IN Number, pValue2 IN ...


8

National Language Support (because Americans have this weird idea of using MM-DD-YYYY as a date format, and different languages have different words for their months).


8

The Oracle Concepts Guide for 11.2 says the following (The note is of particular interest): Globalization Support Environment The globalization support environment includes the client application and the database. You can control language-dependent operations by setting parameters and environment variables on the client and server, which ...


8

Of course you ought to study the license, but as I recall it is free to download and use for non-production purposes. It includes all of the Option packs, and is not in any sense cripled, but patches will not be available as they would be if you had a support account. Oracle XE is free to use in production environments, but has limited functionality and ...


7

The most likely cause of a mutating table error is the misuse of triggers. Here is a typical example: you insert a row in table A a trigger on table A (for each row) executes a query on table A, for example to compute a summary column Oracle throws an ORA-04091: table A is mutating, trigger/function may not see it This is an expected and normal ...


7

Is there some operator or function that can give me the indices of the array No, you have to loop through the associative array: declare type a_arr_t is table of PLS_INTEGER index by PLS_INTEGER; type keys_t is table of PLS_INTEGER; a_arr a_arr_t; keys_ keys_t := keys_t(); l_index integer; begin a_arr(1) := ...


6

It didn't seem like people were really addressing the second part of your question so I thought I'd chime in. First, I like both answers to part 1 of your question. I think either a materialized view or creating a stored procedure to manage inserting into the second table are satisfactory (+1'd both of them). I like the flexibility of using a stored ...


6

Oracle has Java server-side, but I'd caution that it is not a replacement for PL/SQL. There is no better language than PL/SQL for manipulating data stored in the database - Java may be appropriate for computationally intensive business logic. For postgres, There are currently four procedural languages available in the standard PostgreSQL distribution: ...


6

So the way I do this is I don't use default values. Or rather, I set them to NULL as default. Then within my procedure body I check to see if it's equal to NULL and if so set it to a sane default. At that point you could mangle a flag or two in the same space to see what's being set or not set. However, there's the edge case of if they intended to pass in ...


6

I would just delete. Even if I had to only delete if there were say exactly 2 records, then I would add this condition to the where clause, like DELETE FROM table1 WHERE col1='somevalue' AND (SELECT COUNT(*) FROM table1 WHERE col1 = 'somevalue') = 2; In all cases when writing a delete statement consider that in general the where clause is usually either ...


6

I don't know of any built-in way to accomplish this but you could use a derived table or a Common Table Expression (CTE or as Oracle likes to call them: subquery_factoring_clause), if your aim is to pass the parameters only once in the USING: -- derived table OPEN myCursor FOR SELECT value1 AS Value1, myPackage.function1 (value1, my.id) AS ...


5

No, there's really no shortcuts here. Examine things in the following order: Check the procedure name. Check the number of parameters. Check the types of the parameters.


5

The error in you script is that the script now expects a table named tablename, having a column named columnname. In this case you don't know the table and column names so you should use dynamic sql to run this. Next to that, if possible, forget about LONG and implement lobs instead. For docu see ...


5

Assuming that you are using PL/SQL to dequeue the message (there may be additional JMS limitations-- I don't know enough about the interplay between JMS and AQ), you should be able to use a priority queue to implement LIFO (though it would be a bit hokey). When you enqueue a message, you can specify a priority The priority attribute specifies the ...


5

That's tricky, because identifiers cannot be variables in plain SQL. You need to use dynamic SQL with EXECUTE - which is still tricky, because variables are not visible inside EXECUTE. Here is a demo how to get around this: CREATE TYPE mytype AS (id int, txt text); DO $body$ DECLARE _val mytype := (1, NULL)::mytype; _name text := 'txt'; ...


5

Gathering statistics and rebuilding indexes are two completely separate things. It is exceedingly rare that an index in Oracle needs to be rebuilt so any process that is regularly rebuilding an index is highly suspect. I strongly suspect that rebuilding the indexes is unnecessary. And I would strongly suggest spending some quality time reading through ...


5

From a general perspective (not platform-specific), here's what I'd recommend mastering for data warehouse projects: Know how to load data fast. BI projects usually involve nightly loads of large amounts of data. The ETL guys need to shove data in fast with a minimum of concurrency issues. This means knowing when to disable indexes, when to perform tasks ...


5

Use a bind variable anywhere that you might actually change the value that is passed in. It probably doesn't make sense, for example, to use a bind variable in the EXISTS clause in your third example because it seems extremely unlikely that anyone would ever want to pass in a different constant for the EXISTS clause. In your second example, it probably ...


5

If I understand the question correctly you want to find numbers that have, for example, more than 4 digits of precision after the decimal? E.g., you want 3.0671, 3.06713, etc. but not 3.067 or 3.06 or 3. If that is the case then you could do something like: select number from table where number - trunc(number,4) <> 0; trunc here will simply remove ...


5

It sounds like you want the GREATEST function INSERT INTO my_table( date_column ) VALUES( GREATEST( date_default, date_insert_value ));


4

Is there a demarcation between SQL and PL/SQL? SQL is a standard*. PL/SQL is a vendor extension to the SQL standard*. *SQL is a language that has an explicit grammar and rules for how that grammar should be implemented, and is but is not a standard per-se. However, since there is a language specification, that everyone can agree on, then anything ...



Only top voted, non community-wiki answers of a minimum length are eligible