SQL & PL/SQL :: Using Optional Parameters To Fill Update Statement?
Jul 17, 2011
I need to use funtion optional parameters to construct an update statement in the funtion body. I have two scenarios, either both parameters are not null or the 2nd is null. Do I have to use
IF
(param2 is null)
THEN
udpate using param1 only
ELSE
update using both param1 and param2
END IF;
or is there a shortcut to do this?
I have created a simple function in database that take 2 arguments, the last one is optional.
Now i call the function in Forms 6i PL/SQL Trigger and omitt the default (optional) parameter the form builder crashes when i compile the form (CTRL + SHIFT + K)
i have tried to used both words "DEFAULT" and ":=" in the function's signature for making an optional argument.
I have a procedure that has a number of "optional" parameters.
procedure get_files( file_name_in in varchar2 default 'dummy_file', layout_in in number default 1, client_in in number default null, data_supplier_in in number default 99999 );
This procedure can be called with any combination of the input parameters.I can set up program(s) using the DBMS_SCHEDULER.CREATE_PROGRAM procedure using a program_type => 'PLSQL_BLOCK' like this:
begin sys.dbms_scheduler.create_program( program_name => 'GET_MY_FILES', program_action => ' declare begin get_files( layout_in => 11111, client_in => 2222 ); end ;', program_type => 'PLSQL_BLOCK', number_of_arguments => 0); end;
My question is: Can I set up programs(s) using the DBMS_SCHEDULER.CREATE_PROGRAM procedure using a program_type => 'STORED_PROCEDURE' when I have "optional" parameters? It appears that ALL of the program input parameters must be defined and there is no way to indicate that a parameters is "optional".
I would like to fill items :P200_A and :P200_B and so on with the result of a SELECT which depends on the different values of many select lists.
E.G. :P200_list_alpha with the list of values STATIC:less than 10;less,equal than 10;equal,above 10;above,indifferent;indiff
:P200_list_beta with the list of values STATIC:active;active,passiv;passiv,excluded;excluded
How do I write the select statement ? I think it has to be executed in an anonymous PLSQL Procedure (after submit).
What is a convenient way to write the select statement ? I could imagine to use lots of IF , ELSIF, ELSE statements and in each branch (here 12 ) the whole/complet SELECT statement is written.
How to solve this problem in an elegant way ? In my opinion the CASE statement could be useful, but how to use it in the WHERE clause with this nested conditions ?
UPDATE t_tt_hours a SET a.sak_request = ( SELECT b.sak_request FROM t_requests b, co c
[Code]...
The problem I am having is that it is updating all rows even when it is pulling back a null value for b.sak_request. I've tried adding b.sak_request is not null to the select statement like this:
UPDATE t_tt_hours a SET a.sak_request = ( SELECT b.sak_request FROM t_requests b, co c WHERE b.nam_eds_tracking_id = c.id_dir_track_eds
[Code]...
but it doesn't seem to make a difference. The reason I need to do this is that the difference between where it matches with a valid (non-null) value is 396 rows vs. 12,484 rows which is too time consuming to run on my page.
i am reading the columns value from different table but i want to update it with single update statement. such as how to update multiple columns (50 columns) of table with single update statement .. is there any sql statement available i know it how to do with pl/sql.
I am trying to put transactions into 3 different "buckets" for each month of the year.
I am trying to figure out if the syntax for the "else" part of this code is correct... this will basically appear 12 times for each month of the year changing the value for month:
case when floor(sum(total_adjusted_net_amount)/100) < 0 and month in (01) then 0 when floor(sum(total_adjusted_net_amount)/100) > 29 and month in (01) and then 30 else when floor(sum(total_adjusted_net_amount)/100) and month in (01) end Groupin_01
I have an issue with rather complicated function.Basically it is using DBMS_SQL to execute a very long statement with many parameters (~6000 of them) and binding them with DBMS_SQL.BIND_VARIABLE. Variables are called :1,:2,...,:6000.
When this arguments set is too large - I am receiving error "ORA-00939: too many arguments for function".
Currently I am thinking about dividing the query into subqueries and executing them all with performance decrease.
i want to update a table passing the parameters and the updating the table according to it
i trired this
create or replace procedure move (z1 in game.item_id%type,g1 in game.item%type) as begin update game set postion= 'l' where item_id=z1 or item_id=g1; end move; /
I have to check some parameter values for an OID tuning I do not have sys access, I have only schema user access
Now how do I see the values of SGA_TARGET, db_cache_size etc parameter
I manage to see these var in init.ora file under /dbs folder but there are 2-3 spfile also having containing these attributes, not sure which reflect the actual.
Also can I alter also these value via schema user or do I need SYS access?
when setting up data guard, if the primary clustered database is already in archive log mode, is there a need to restart both cluster instances when we update the spfile parameters for data guard ? or we can simply add the data guard parameters to the spfile while both cluster instances are online ?
create table zTEST ( PRODUCT number, ID number, Flag number, FLAG_L1 number );
[Code]...
The field FLAG_L1 is the field FLAG with a Lag 1 (order by ID, partition by PRODUCT). I want to write the field FLAG_L1 in an update statement, how can I do this?
PROCEDURE split_name ( full_name IN VARCHAR2, name1 OUT VARCHAR2, name2 OUT VARCHAR2, name3 OUT VARCHAR2, name4 OUT VARCHAR2, name5 OUT VARCHAR2 )
the above is the procedure declaration. i want to use this function in updating the records in a table. this procedure is working fine in forms and it is splitting the names perfectly and i dont know how to use this in update statement as it is not returning anything like functions do.
By using the RETURNING clause i am getting the new updated value. I need the old value for some processing. Do i have to explicitly query it before the update stmt? Pls reply.
I am having trouble figuring out why an update statment is ignoring the primary kiy index when performing an update through the application. The index IS used when the update is run from sql*plus or other sql tools.
The statement is very simple: update ITEM_MASTER set COST = :1 where SMARTPART_NUM = :2; ITEM_MASTER has unique, primary key index on SMARTPART_NUM
When I use OEM and other tools, I can see the index is not used in the exlain plan, and the query has a high CPU cost due to the full table scan. The table is analyzed, lately using 100%. Table rowcount is 229768
SELECT column_name, num_distinct, num_buckets, histogram, trunc(last_analyzed) ANALYZED FROM USER_TAB_COL_STATISTICS WHERE table_name = 'ITEM_MASTER' AND column_name = 'SMARTPART_NUM';
The database is Oracle Database 10g Release 10.2.0.4.0 - 64bit Production (on Windows, standard edition)
Here are parameters related to optimizer: optimizer_dynamic_sampling integer 2 optimizer_features_enable string 10.2.0.4 optimizer_index_caching integer 0 optimizer_index_cost_adj integer 100 optimizer_mode string ALL_ROWS optimizer_secure_view_merging boolean TRUE
We've tried rebuilding the indexes then re-analyzing, dropping stats and locking at zero, using various sample sizes; none have any impact.
We wondered if the bind variables are causing this, though in testing outside the application, we tried pl/sql and sql batches to mimic the passing of values into the binds, and all still used the index.
Other than putting a hint into SQL in the application (we'd have to ask for a customization), how can I "fix" the database to use the index? In other words, how can I make the database see that the cost of a FTS is much higher than using the index, whenever it sees these updates (either from sql or the application)? This is the simplest example, but we have 4-5 SQL updates on this and other tables that are ignoring the indexes and using full table scans, so we'd like to fix it for all.
Using Oracle 11gr2. If I call the following update statement from session A, session A will lock the row until a commit/rollback statement is issued from session A. If session B calls the same update statement and same row, session B will have to wait until the lock is released in session A. However, the application developers are speaking in terms of threads. Could it be possible that the update statement is called within the same session by multiple requests? If yes, could the case statement be evaluated without the row being locked which could lead to false results? Trying to keep this post brief. tableA has columnA (primary key, number) and columnB (number)
{update tableAset columnB = case when columnB = 3 then 4 when columnB = 4 then 5 else columnB endwhere columnA = 6;}
Could 2 requests (almost at the exact same time) in the same session evaluate columnB as 3. The desired result would be the first request sets the column to 4 and the second request sets the column to 5.
I have a table with 200k entries, which has ~12k unique combination of columns that I wish to assign an ID to. My real world problem is with addresses and street components (of which nulls are allowed); but this should be a reasonable example.
DROP TABLE tt;
CREATE TABLE tt AS SELECT ROWNUM id, CASE WHEN MOD(ROWNUM, 107) = 0 THEN NULL ELSE MOD(ROWNUM, 101) END c1, CASE
[Code]...
Now I have 3 ways to assigned an ID (fill the SID column).
The first is congruent with the method most commonly used, but seems especially slow in this case. I think this is due to the COALESCE/TO_CHAR usage. Can this be optimized?
DECLARE CURSOR c1 IS SELECT a.*, sid_seq.NEXTVAL sid FROM (SELECT DISTINCT c1, c2 FROM tt) a; BEGIN FOR s IN c1 LOOP UPDATE tt d
[Code]...
The second I've made relies on the usage of a temp table, which I really don't like, but it is faster; so that is something at least.
CREATE TABLE ttt AS SELECT a.*, sid_seq.NEXTVAL sid FROM (SELECT DISTINCT c1, c2 FROM tt) a;
[Code]...
The third discards the sequence, and uses dense_rank. This allows us to use the ID (which might have an index, whereas c1 and c2 will not).
MERGE INTO tt d USING (SELECT id, (SELECT COALESCE(MAX(sid), 317) FROM tt) + DENSE_RANK() OVER (ORDER BY c1, c2) sid FROM tt) s ON (d.id = s.id) WHEN MATCHED THEN UPDATE SET d.sid = s.sid
The ideal solution would use the SEQUENCE, not use a temporary table and match/merge/update based on ID, and be 'fast'; but I cannot conceive of such a solution; does one exist? What would you do?
I have a table called test_renames that has two columns(new_name and old_name) and one row with the following values
NEW_NAME OLD_NAME DRUG10 DRUG1
I have another table called SH0 that has 10,000 rows and the column of interest is called ITEM1. ITEM 1 contains the following distinct drug names:
DRUG1,DRUG2,DRUG3,DRUG4,DRUG5
Each DRUG has multiple rows associated with it.
I need to only update rows for DRUG1 and set the name from DRUG1 to DRUG10 for all rows where ITEM1 is DRUG1.
However I need to write this update statement by joining with the values in the test_renames table that contains the NEW_NAME and the OLD_NAME.
DRUG1 has 2,000 rows associated with it. The following SQL statement gives me 2,000 rows
(SELECT NVL(CHG.NEW_NAME, SH.ITEM1) FROM test_renames CHG,sh0 sh WHERE UPPER(SH.ITEM1) = UPPER(CHG.OLD_NAME) AND UPPER(SH.ITEM1) IN (SELECT UPPER(OLD_NAME) from test_renames))
However when I run the following update statement, it appears that the SQL query updates all the 10,000 rows in the table instead of just touching the 2,000 rows for DRUG1. It does change all the rows for DRUG1 to DRUG10, but all the other ITEM1 values become null. What I need from the update statement is only chnage the rows for DRUG1 to DRUG10 and leave the other rows that I associated with DRUG2, DRUG3 etc. Here is my update statement.
UPDATE SH0 SH SET ITEM1 = (SELECT NVL(CHG.NEW_NAME, SH.ITEM1) FROM test_renames CHG WHERE UPPER(SH.ITEM1) = UPPER(CHG.OLD_NAME) AND UPPER(SH.ITEM1) IN (SELECT UPPER(OLD_NAME) from test_renames))
This update statement touches all 10,000 rows. I am looking to update only the relevant 2,000 rows for DRUG1.
I try to apply update statement on the button for the specific records, the command does executes if in the end i write execute_query it always asks for do u wanna save the records, yes or no. I want to remove that message. Also if i write commit it does remove that message but everytime i press the button it updates the old record fine but also adds one more entry for the same record.
I have a table TEMP_TEST_1 to be loaded with multiple rows which contains the available items for a store with their sequence numbers. I also have another table TEMP_INV_1 which holds a column for inventory count of the items, and this column is to be updated after loading the first table TEMP_TEST_1.
The table TEMP_TEST_1 is updated through all possible channels in OLTP. So while updating the inventory, which is the best way. My update should either add the total number of inserts per item into the TEMP_TEST_1 table's INVENTORY_CNT column i.e. existing value + count of new rows OR a full update by taking the complete row count (Grouped by item id) and update the INVENTORY_CNT column
-------------------------------------------------------------------------------- -- Initial setup SQL's, TEMP_TEST_1 is updates on OLTP through multiple channels -------------------------------------------------------------------------------- CREATE TABLE TEMP_TEST_1 ( ITEMID NUMBER ( 4 ), INVENTORY_CNT NUMBER ( 2 ) ); CREATE TABLE TEMP_INV_1 ( ITEMID NUMBER ( 4 ), ITEMSEQ NUMBER ( 5 ) ); INSERT INTO [code].......
-------------------------------------------------------------------------------- -- Inserts for new items in the store -------------------------------------------------------------------------------- INSERT INTO TEMP_INV_1 VALUES ( 1, 11 ); INSERT INTO TEMP_INV_1 [code].......
I am issuing an update statement in which I am using multiple tables it is giving me an error " set keyword missing"
update E_CONT_DETAIL_NUMB_VALUE ecdnv, y_obj_category yoc, t_contact tc set ecdnv.ContTPRecCount = 1000 where tc.default_category_id = (select primary_key from y_ojb_category where tree_position = 'CONT') and ecdnv.detail_field_id=tc.default_category_id;
update E_CONT_DETAIL_NUMB_VALUE ecdnv, y_obj_category yoc, t_contact tc * ERROR at line 1: ORA-00971: missing SET keyword
I have to conditionally update a set of columns in a table. If the column status_code_stage_3 IS NULL THEN I have to update the column status_code_stage_2. The below query is giving error:-
Test Table create scripts CREATE TABLE test11( date_stage_3 date, reason_code_stage_3 varchar2(20), reason_code_stage_2 varchar2(20), opportunity_date date ) INSERT INTO test11 values(sysdate,'reason1',NULL,sysdate) INSERT INTO test11 values(sysdate,NULL,'reason2',sysdate)
[code]....
how to work out the update statement to use the conditional statement for columns.