plsql

How can I use "IF statements" in a postgres trigger

I have a trigger function that I only want to fire on certain instances of INSERTS, in this case, if do_backup = true. If it fires in all instances, I get an infinite loop. The logic seems pretty simple to me, and the rest of the function works. But the trigger function does not seem to register my conditional and always runs, even when ...

Query a stored procedure for it's parameter names and types

Is there any easy way to query a stored procedure (Oracle - PL/SQL) for what parameters it expects? I know that I can query USER_SOURCE to get the whole procedure but I'd then have to parse the whole procedure, and if the parameter is of type [table].[column]%TYPE I'd then have to query the table schema as well. Either using just sql o...

how to know on which column,the sequence is applied?

I have to fetch all sequences with their table name along with the column name on which sequence is applied .Some how i managed to fetch table name corresponding to sequence because in my data base sequence is stored with first name as table name from data dictionary(all_sequences and all_tables) . Please let me know how to fetch corres...

Query to check the consistency of records

I have four tables TableA: id1 id2 id3 value TableB: id1 desc TableC: id2 desc TableD: id3 desc What I need to do is to check if all combinations of id1 id2 id3 from table B C and D exist in the TableA. In other words, table A should contain all possible combinations of id1 id2 and id3 which are stored in the other three...

Oracle aggregate function to return a random value for a group?

The standard SQL aggregate function max() will return the highest value in a group; min() will return the lowest. Is there an aggregate function in Oracle to return a random value from a group? Or some technique to achieve this? E.g., given the table foo: group_id value 1 1 1 5 1 9 2 2 2 4 2 8...

Concatenation of CLOB datatypes in a LOOP in PL/SQL

Good Day Gurus, I am trying to concatenate clobs in a PL/SQL loop and it has been returning null whilst when using DBMS_OUTPUT prints out the loop values and when executing each result of the clobs gives an output as well. The system is meant to execute an already stored SQL in a table based on the report name passed into it. This part...

Oracle locking with SELECT...FOR UPDATE OF

I'm selecting from tables FOO and BAR. I'd like to lock the records of FOO which are being returned, but I don't want the records of BAR to be locked. cursor c_foobar is select foo.*, bar.* from foo, bar where foo.id = bar.foo_id for update of <what should I put here?> It seems like I need to specify individual columns, but I want t...

Can I lock rows in a cursor if the cursor only returns a single count(*) row?

I would like to restrict users from inserting more than 3 records with color = 'Red' in my FOO table. My intentions are to A) retrieve the current count so that I can determine whether another record is allowed and B) prevent any other processes from inserting any Red records while this one is in process, hence the for update of. I'd l...

ORA-00060: deadlock detected while waiting for resource

Hi, I have a series of scripts running in parallel as a nohup on an AIX server hosting oracle 10g. These scripts are written by somebody else and are meant to be executed concurrently. All the scripts are performing updates on a table. I am getting the error, ORA-00060: deadlock detected while waiting for resource As I g...

Is there a way to troubleshoot change notifications in Oracle?

I'm trying to use oracle change notifications (API from Dbms_Change_Notification package) to update complex materialized views. I install change notification for my table with my PL/SQL callback and I can see in USER_CHANGE_NOTIFICATION_REGS view that my change notification is installed properly. On development oracle servers with low lo...

PL/SQL base conversion without functions

Is there any way to convert decimal to binary, or binary to decimal, in Oracle 10g without having to first define a function? I have limited database access (SELECT only) and all the solutions for this I've found online seem to involve CREATE FUNCTION, which does not work for me. ...

Oracle Multiple update Query

I have two tables like the below one in my DB. In the first table ITEM for evry DEPARTMENT_CODE there will be multiple ITEM_CODE. ITEM ---------------------------------------------------- "STORE_CODE" "ITEM_CODE" "DEPARTMENT_CODE" "011" "912003" "14" "011" "912004" "14" "011" "914001" "14" ----------------------...

How to find out what tables/views/synonyms are used in a stored procedure

Through Oracle queries is it possible to find out which views/synonyms/tables a stored procedure use? In PL/SQL Developer if you collapse out a stored procedure it will show "References" which shows all the tables/views/synonyms that the stored procedure uses. I am trying to implement this functionality into a script which will com...

Understanding the differences between Table and Transaction API's

Friends, This Ask Tom thread which I found via another SO question, mentions Table and Transactional API's and I'm trying to understand the difference between them. A Table API (TAPI) is where there is no access to the underlying tables and there are "getters" & "setters" to obtain information. For example to select an address I ...

Alter Type in Oracle Fails with ORA-22324 and ORA-21700

I'm trying to add an attribute to an already existing Object Type in an Oracle 10.2.0.4 DB. The schema is valid, and everything is working before running the following statement: ALTER TYPE sometype ADD ATTRIBUTE (somefield varchar(14)) CASCADE INCLUDING TABLE DATA / SHOW ERRORS The alter fails with an ORA-22324 and an ORA-21700. Afte...

Is it possible to pass types defined in plsql package headers using odp.net?

TYPE point IS RECORD ( X NUMBER, -- The X co-ordinate of the point Y NUMBER -- The Y co-ordingate of the point ); This is defined in my package header. It is then used in a procedure defined in the same package. Is it possible for me to call the procedure via ODP.net? ...

When will automatic rollbacks be executed in PHP executing Oracle PL/SQL - OCI8?

I have PHP code that execute a stored procedure 10 times. If one stored procedure call fails, it should continue on, and at the end commit the transaction. It basically looks like this: $connection = getConn(); foreach($row as $i=>$j) { $SQL = "BEGIN MYPROC.EXECUTE(:VAL1, :VAL2); END;"; $statement = OCIParse($connection, $SQL); ...

Oracle: copy row while updating one field

Please note: I am asking the question I want answered. I know this question means the database is set up poorly. So I will vote down any questions that suggest changing the way the table is set up. I need to duplicate a bunch of rows, while changing one value. name col1 col2 dave a nil sue b nil sam c 5 needs t...

Can odp.net pass a parameter to a boolean pl/sql parameter?

Is it possible to correctly pass an OracleParameter to a boolean parameter in a pl/sql stored procedure? ...

Oracle SELECT query: collapsing NULL values when pairing up dates for different fields

This question is very much like my previous question, but a bit more complicated. Rob van Wijk's answer worked perfectly for my other question, and I've been using that as a starting point. My problem now is that I am pivoting dates for different fields. Whereas before I cared about getting all open_in and open_out values for a given ...