conditional select into statement
Hi people.
I'm trying to implement a conditional block in a select statement. I browsed the forums and seen the suggestions with the DECODING and the recurrent insistence that IF/ELSE do not or cannot work within the PL/SQL, which is what it would be.
I'm trying to connect a simple string value if the value of a column is null. The block WHEN either does not either or I'm doing it wrong, but I would take any suggestions that you that you better informed than me on this.
Here is the block:
------------------
SELECT c.CHCTRLID 'CC ID', c.STATUS3, b.VPTIMSTAMP,
a.VP_DATE AS 'Submit Date', a.CRITI_EXP_DT AS 'Critical Date', c.REQ_TYPE, c.SUBJLETTER,
c.PGCOUNT AS 'Total Page', c.EFFECT_PGCOUNT,
c.PUBTYPE AS "Type of Publication", c.COMPLEXITYLEVEL,.
c.PUBDATE, a.BRANCH, a.BRANCH_SEC, a.PRIORITY, c.WRITER, a.REQ_INFO_DESCRIPT, a.DEPT,
ABS (Round ((pubDate-VPTIMSTAMP), 0)) AS 'level of SLA in days. "
-WHEN PUBDATE IS NULL
- then return "n/a" AS "secondary ALS."
-WHILE OTHERS THEN
-BACK Abs (Round (SYSDATE-VPTIMSTAMP), 0)) AS 'secondary ALS. "
a.OPS_MAN_CHG, a.OPS_MAN_PPCHAP, a.STRATEGY_UPDATE, a.CRITICAL_EXP
B INNER JOIN CHG_CTRL_USR one CHG_CTRL_ADM
ON b.CHCTRLID = a.CHCTRLID
C INNER JOIN ADM_SUPP_INDX ON b.CHCTRLID = c.CHCTRLID
WHERE c.STATUS3! = 'Cancelled' AND a.VP_DATE > 4 April 11 '
ORDER BY a.CHCTRLID
---------------------------
I commented on the block ONCE because it wouldn't work, but basically, that's what I'm trying to accomplish.
Thank you.
Decode is possible, but the CASE is more readable.
Try this as a column value
CASE WHEN PUBDATE IS NULL then 'n/a' else to_char(Abs(Round(SYSDATE-VPTIMSTAMP),0)) ) end AS "Secondary SLA",
second possibility to check NULL is use NVL or NVL2.
The data type of these two results must match.
as in
nvl2(PUBDATE, to_char(Abs(Round(SYSDATE-VPTIMSTAMP))) , 'n/a')
Tags: Database
Similar Questions
-
Select Into statement in the function db - query issued schema table
problem with "select into" in the function db to point 10.2
There are two schemas. "mdbdev" is the master database, and 'devusr' is granted SELECT access table to run queries in the mdbdev schema.
with devusr, in SQL, I am able to run the following query
Select wm_concat (strConcatedCountryList)
from (select country_name as mdbdev.country_master mdbcm strConcatedCountryList
where mdbcm.country_ship_status = < param? >
order of country_name)
but when I use the same procedure/function with 'select into' motion, failed to compile with error * "table or view does not exist."
FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS NUMBER)
RETURN VARCHAR2
IS
var2CountryList VARCHAR2 (1000);
BEGIN
Select wm_concat INTO var2CountryList (strConcatedCountryList)
from (select country_name as mdbdev.country_master mdbcm strConcatedCountryList
where mdbcm.country_ship_status = value < SHIP_STATUS >
order of country_name);
Return var2CountryList;
END;
Please advise/help/suggestion :)You don't have to ask for the DBA, you can run a query to find out:
select * from all_tab_privs_recd where owner = 'MDBDEV' and table_name = 'COUNTRY_MASTER'
What give you?
-
How to modify a statement "select into" how to use a cursor
The following code fails with an exception too many lines. How can I modify statement Select Into the procedure to use a cursor?
CREATE OR REPLACE PROCEDURE Track_Asset( business_date IN NUMBER DEFAULT NULL, missing_table_name OUT VARCHAR2) IS ln_business_date NUMBER; incorrectdateformat EXCEPTION; BEGIN IF business_date < 0 THEN RAISE incorrectdateformat; ELSE DECLARE ln_business_date NUMBER; BEGIN SELECT MAX(business_date) INTO ln_business_date FROM sproof ; EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line('NO MATCH FOUND'); WHEN OTHERS THEN dbms_output.put_line('ORACLE ERROR :' || SQLERRM); END; DECLARE missedfeedfnd EXCEPTION; BEGIN SELECT 'Missing Value : ' || table_name INTO missing_table_name FROM ( SELECT UPPER(table_name) table_name FROM filespec WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3') MINUS ( SELECT DISTINCT UPPER(first_table_name) FROM dpca WHERE business_date = ln_business_date AND first_table_name IN ('TABLE1','TABLE2','TABLE3') GROUP BY UPPER(first_table_name) UNION SELECT UPPER(first_table_name) FROM dpca WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' ) AND first_table_name = 'TABLE4' GROUP BY UPPER(first_table_name) )); IF missing_table_name IS NOT NULL THEN dbms_output.put_line('Missing Value : '|| missing_table_name); RAISE missedfeedfnd; ELSE NULL; END IF; EXCEPTION WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows'); WHEN missedfeedfnd THEN raise_application_error ( - 20003, 'Missed Feed'); END; END IF; EXCEPTION WHEN incorrectdatevalue THEN raise_application_error ( - 20001, 'Incorrect/Bad Date Entered'); END;
OK, try this - OUT param will be filled with the table names comma-separated list:
PROCEDURE Track_Asset( business_date IN NUMBER DEFAULT NULL, missing_table_name OUT VARCHAR2) ... ... cursor c_table_names is select datatablename from ( select upper(datatablename) datatablename from filespec where data_table_name in ('TABLE1','TABLE2','TABLE3' ) MINUS ( select upper(first_table_name) from dpca where business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table] and fus_data_table_name in ('TABLE1','TABLE2','TABLE3' ) group by upper(first_table_name) UNION select upper(first_table_name) from dpca where business_dt_num = to_number( substr('201111',1,6) || '01' ) and first_table_name = 'TABLE4' group by upper(first_table_name) )); ... ... begin ... for rec in c_table_names loop missing_table_name := missing_table_name || rec.datatablename ||','; end loop; missing_table_name := rtim(missing_table_name , ','); ... ... end ;
HTH
Published by: user130038 on December 28, 2011 08:46
-
SELECT INTO does not return no loop lines and stops
I scoured the internet looking for an appropriate way to handle this, but have developed in white. I'm not a pro so please excuse me if I asked a basic question stupidly. Firstly I have search the Forum but no joy (or rather too much results, none seemed relevant to my case).
In any case, I have the following:
DECLARE
v_period_start DATE: = TO_DATE ('2010-02-21 00:00:00 ',' YYYY-MM-DD HH24:MI:SS');
v_period_end DATE: = TO_DATE (' 2010-03-20 23:59:59 ',' YYYY-MM-DD HH24:MI:SS' ");
v_last_active DATE;
CURSOR cust_list
IS
SELECT a.cust_no,
a.service_id,
b.Name,
c.account_no,
c.agreement_no,
c.agreement_part_no,
c.MSISDN,
c.equipment_no,
a.ordered_from,
a.cancelled_to,
a.contract_period_until,
c.valid_from,
c.valid_to,
a.Status,
d.campaign_service_no,
d.Name LIKE 'CAMPAIGN '.
Order_rows a,
b services
mobilebb_equips_p_agree_part c,
campaign_services d
WHERE < where the big clause >
FC cust_list_futur % ROWTYPE;
BEGIN
FOR cf IN cust_list
LOOP
-Search for a command line with the same equipment which ended within 24 hours of the new order from. This should identify up/downgrades
SELECT o.cancelled_to
IN v_last_active
Of order_rows o
WHERE o.agreement_no = cf.agreement_no
AND o.agreement_part_no = cf.agreement_part_no
AND o.equipment_no = cf.equipment_no
AND o.service_id <>cf.service_id
AND o.cancelled_to BETWEEN cf.ordered_from - 1 AND cf.ordered_from
AND rownum < 2;
INSERT INTO miken_mobint_cust
VALUES (cf.cust_no, cf.service_id, cf.name, cf.account_no, cf.msisdn, cf.equipment_no, cf.ordered_from, cf.cancelled_to,
CF.contract_period_until, cf.valid_from, cf.valid_to, cf.status, cf.campaign_service_no, cf.campaign, cf.agreement_no, cf.agreement_part_no, v_last_active);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN v_last_active: = NULL;
END;
The problem seems to be that the SELECT INTO retuens that all lines and my main INSERT never never seems to run. If I comment the SELECT INTO and set the field last slot insert on a NULL value of the table Gets the appropriate records.
I do not expect a return value very often of the SELECT INTO statement, so I need to know how it default null and continue the treatment when nothing is returned.Try this.
DECLARE v_period_start DATE := TO_DATE('2010-02-21 00:00:00','YYYY-MM-DD HH24:MI:SS'); v_period_end DATE := TO_DATE('2010-03-20 23:59:59','YYYY-MM-DD HH24:MI:SS'); v_last_active DATE; CURSOR cust_list IS SELECT a.cust_no, a.service_id, b.name, c.account_no, c.agreement_no, c.agreement_part_no, c.msisdn, c.equipment_no, a.ordered_from, a.cancelled_to, a.contract_period_until, c.valid_from, c.valid_to, a.status, d.campaign_service_no, d.name AS "CAMPAIGN" FROM order_rows a, services b, mobilebb_equips_p_agree_part c, campaign_services d WHERE cf cust_list_futur%ROWTYPE; BEGIN FOR cf IN cust_list LOOP -- Look for an order row with the same equipment that finished within 24 hours of the new order starting. This should identify up/downgrades BEGIN SELECT o.cancelled_to INTO v_last_active FROM order_rows o WHERE o.agreement_no = cf.agreement_no AND o.agreement_part_no = cf.agreement_part_no AND o.equipment_no = cf.equipment_no AND o.service_id <> cf.service_id AND o.cancelled_to BETWEEN cf.ordered_from - 1 AND cf.ordered_from AND rownum < 2; EXCEPTION WHEN NO_DATA_FOUND THEN v_last_active := null; END; INSERT INTO miken_mobint_cust VALUES (cf.cust_no, cf.service_id, cf.name, cf.account_no, cf.msisdn, cf.equipment_no, cf.ordered_from, cf.cancelled_to, cf.contract_period_until, cf.valid_from, cf.valid_to, cf.status, cf.campaign_service_no, cf.campaign, cf.agreement_no, cf.agreement_part_no, v_last_active); END LOOP; EXCEPTION WHEN NO_DATA_FOUND THEN v_last_active := NULL; END;
-
How to add a condition to this statement.
Hi friends,
I have a requirement of the customer.
Let me explain the scenario.
I have a table, which contains some employees say 1, 2,3,4.
So I wrote a query so that it...
Select * from where a trunc (sysdate) between effective_start_date and effective_end_date person_id =: p_person_id;
in this statement, I would like to add a condition more say
If person_id in (1,2,3,4) then
p_person_id: = null;
on the other
p_person_id = person_id;
the addition of this condition in mysql statement...
can someone help me with this...
Thanks in advance.Hello
Looks like that (no data, not yet tested)
select * from A where trunc(sysdate) between effective_start_date and effective_end_date and person_id = CASE WHEN NOT :p_person_id in (1,2,3,4) THEN :p_person_id ELSE person_id END;
Concerning
Peter -
Hi all
I try to choose in a variable in a loop of cursor but I get NO DATA FOUND when
Select does not return a value.
I want to set the variable to 0 when the selection fails.
I tried to add an exception, but I get the following:
ORA-00900: invalid SQL statement
Here is the code I am trying to run (the exception is commented):
Line: -.
PROCEDURE MyProc IS
v_op NUMBER;
BEGIN
FOR cursor1 IN (select * from myTable)
LOOP
Operation of SELECTION IN v_op from operationsTable where id = cursor1.ID;
-EXCEPTION *.
-WHEN NO_DATA_FOUND THEN
-v_op: = 0;
-END; *
END LOOP;
MyProc END;
Line: -.
Does anyone know how to set a variable when the selection fails and NO DATA FOUND?
Thank you
dyahavYou need to hold your exception by BEGIN and END
BEGIN select into... EXCEPTION WHEN NO_DATA_FOUND do_something END;
-
Comment of "Syntax error in INSERT INTO statement." validation error.
I had this working perfectly on MySQL. Then I was told that I had to do with a mdb database in Access, now the errors pop up like crazy. I fixed all of them except this one, I get a "syntax error in INSERT INTO statement." When I try to post a comment on a post in my mini-blog site.
The thing is, I use almost the same code for the comments I make blog themselves. The positions work fine, the comments are not.
He said that the error is on my page addcomment_process as 119. It is the following (line 119 is underlined, bold line is also bolded in the error message):
< name cfquery = "input_comments."
DataSource = "" #DSN # ""
username = "" #DSNUSER # ""
password = "#DSNPASS #" >
INSERT INTO (comments)
speaker,
Comment,
DateTime,
post_id
)
VALUES)
"#form.commenter #"
"#form.comment #"
"#form.datetime #"
"#form.post_id #".
)
< / cfquery >
It is all fine data, by simply inserting not, because it says:
"INSERT INTO comments (speaker, comment, datetime, post_id) VALUES ('Anonymous', 'test commentary.', 25 April 12 22:55 ', ' 2').
It worked perfectly, when it was a MySQL database, now I keep getting errors present a part of the site now that it is MDB. Anyone know what is happening?
DateTime is a reserved word in Access.
--
Adam
-
Select Into when no line is detected
In my select Into, it is possible that we will not find the lines and it causes an error. How to define v_3Month_lb null so that when no line is detected, that an exception is not thrown?
Select Pa_Entered_Value
IN v_3Month_lb
of wr_measure_value
where wr_measure_oid = 2
and project_associate_oid = p_ProjectAssociateOID
and period_oid = (p_PERIOD_OID)
and wr_item_oid = p_ItemOID;How to define v_3Month_lb null so that when no line is detected, that an exception is not thrown?
You do not have.
Exception handler is not required. -
Select the statement to insert into a table by using a loop
Hello
what I want to do is create 3 records based on this one in a loopcreate table uploadtab( itema varchar2(3), xtype varchar2(1), salesa number, margina number, salesb number, marginb number, salesc number, marginc number); insert into uploadtab (itema, xtype, salesa, margina, salesb, marginb, salesc, marginc) values ('abc', 'a', 100, .40, 300, .10, 450, .25); create table testinsert(itema varchar2(3), xtype varchar2(1), sales number, margin number);
so here's my desired for testinsert output
I don't want to use 3 insert tables if possibleabc a 100 .40 abc a 300 .10 abc a 450 .25
any help would be greatly appreciated
Thanks in advance
Published by: DM on July 7, 2010 14:22This gives a shot:
INSERT INTO testinsert ( itema , xtype , sales , margin ) SELECT itema , xtype , DECODE ( RN , 1,salesa , 2,salesb , 3,salesc ) , DECODE ( RN , 1,margina , 2,marginb , 3,marginc ) FROM uploadtab CROSS JOIN ( SELECT ROWNUM RN FROM dual CONNECT BY LEVEL <= 3 ) ;
-
I'm trying to make a
SELECT EMP_TOTAL FROM EMPLOYEES WHERE ADD_DATE = SYSDATE
In the statement above "WHERE ADD_DATE = SYSDATE' this condition eliminates several values since in my table there is only a 1 value for each sysdate
And this unique value, I want to choose in a variable coz
If it is not equal to zero
I want to run a bunch of SQL
ON THE OTHER
SOME other SQL.
The problem I face is when selecting in the variable.
I get error when I try
DECLARE a number
SELECT EMP_TOTAL FROM EMPLOYEES WHERE ADD_DATE = SYSDATE;
IF a! = 0 THEN
-------SQL----------
ON THE OTHER
--------SQL-------
I also tried
DECLARE a NUMBER: SELECTION EMP_TOTAL OF EMPLOYEES WHERE ADD_DATE = SYSDATE
Help, please.
Newbie in PLSQLI get error when I try
Let me guess, the error is right no data found? He should know that sysdate (in fact, all dates in Oracle) always has a component "time" to the second, so it is unlikely that you would have a file meets the criteria. Depending on whether you actually store times in your area of add_date that you must do something more like:
If there is no time in your area
DECLARE a number; BEGIN SELECT emp_total INTO a FROM employees WHERE add_date = TRUNC(sysdate) ; IF a != 0 THEN -------SQL---------- ELSE --------SQL------- END IF; END;
If you are actually storing time:
DECLARE a number; BEGIN SELECT emp_total INTO a FROM employees WHERE add_date >= TRUNC(sysdate) and add_date < TRUNC(sysdate + 1); IF a != 0 THEN -------SQL---------- ELSE --------SQL------- END IF; END;
John
-
How to test different Select into a PL/SQL block?
Hello
I'm relatively new to PL/SQL and I'm doing several int selects only one PL/SQL block. I am faced with the fact that if a single select statement returns no data, I have to go to the when exception DATA_NOT_FOUND.
Or, I would test selects different.
In an authentication script, I'm looking for a table for a USER ID (USERID) and an ID application, to check if a user is registered under this username for this APPLICATION.
There are different possibilities: 4 possibilities:
-Existing USER name or do not exist and
-Aplication ID found or not found for this particular USER ID.
I would test teas 4 possibilities to obtain the status of this user do regardin this application.
The problem is that if a select returns no rows, I'll not found exception data.
In the example below you can see that if no line is returned, with the exception
I would like to first of all make this statement:DECLARE P_USERID VARCHAR2(400) DEFAULT NULL; P_APPLICATION_ID NUMBER DEFAULT NULL; P_REGISTERED VARCHAR2(400) DEFAULT NULL; BEGIN SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ; :P39_TYPE_UTILISATEUR := 'USER_REGISTERED'; EXCEPTION WHEN NO_DATA_FOUND THEN :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND'; END;
Do this if the user is found:SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID
etc...SELECT DISTINCT(USERID) INTO P_USERID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID AND APPLICATION_ID = :APP_ID ;
Basically, I don't want to go to the not found exception before you have tested the 4 possibilities.
Do you have a suggestion?
Thank you very much for your help!
ChristianIf you I had to check several conditions, this is how I would do:
DECLARE P_USERID VARCHAR2(400) DEFAULT NULL; P_APPLICATION_ID NUMBER DEFAULT NULL; P_REGISTERED VARCHAR2(400) DEFAULT NULL; BEGIN SELECT USERID , MAX(DECODE(application_id, :APP_ID, :APP_ID)) app_id_valid INTO P_USERID , P_APPLICATION_ID FROM ACL_EMPLOYEES WHERE USERID = :P39_USERID GROUP BY USERID IF P_APPLICATION_ID IS NULL THEN :P39_TYPE_UTILISATEUR := 'NOT REGISTERED TO APPLICATION_ID'; ELSE :P39_TYPE_UTILISATEUR := 'USER_REGISTERED'; END IF; EXCEPTION WHEN NO_DATA_FOUND THEN :P39_TYPE_UTILISATEUR := 'USER_NOT_FOUND'; END; /
not tested
C.
-
Refresh us the data from the production environment by using the Task Scheduler tool (channels, programs, programs, etc.). It is probably not the best way, but I inherited structure, is what it is. Seen retrieve data on a database link, apply logic to the data (collection ontime, ontime delivery) and fill the tables.
Procedures to insert in temporary tables, which carries data over a database link. Then records are deleted and inserted into the actual table based on records from the temporary table using the IN clause on the primary key. Some tables have several columns of hundreds (new legacy, not preferred) using an UPDATE is not feasible. Here is an example of one of the procedures.
DATE_CUTOFF is the create date or the date of update of the document. NN_SHIPMENT_INFO_XA is the actual table. NN_SHIPMENT_INFO_XA_TEMP is the temporary table.
NN_SHIPMENT_INFO_XA has 292 columns, so deletion and insertion of 10 k lines takes nearly two hours. I read what one of the most inefficient operators. I tried to gather statistics on the temporary table every time, but that has not helped. Break the view into pieces and reducing the number of columns is difficult because there are several layers of logic and tables between the database link and the layer of the end user. Because of its complexity, I am committed to the design of my predecessor in the foreseeable future. Is there a better way to build this procedure to make it run faster?
Any suggestions are greatly appreciated.
In the code you posted, you do:
Select max (date_cutoff_nnsi_xa) - interval time '12'
in last_cutoff_nnsi_xa
of nn_shipment_info_xa
Keep little and use last_cutoff_nnsi_xa as a predicate on the view using a part of the merge as you statement used to fill the temporary table. So, the merger would look more like:
merge into nn_shipment_info_xa targ
using (select * from nn_shipment_info_xa_temp)
where date_cutoff_nnsi_xa > last_cutoff_nnsi_xa) CBC
on (targ.shipment_id = src.shipment_id)
When matched then
Update
Set targ.col1 = src.col1,
Targ.col2 = src.col2,
...
-possibly
where targ.col1 <> src.col1 and
Targ.col2 <> src.col2
...
When not matched then
Insert (shipment_id, col1, col2,...)
values (CBC, col1, src.shipment_id, src.col2,...)
John
-
After a SELECT INTO, the use of the result as a parameter to another SQL variable?
Hello world
My apologies for these basic questions, but I need your help in order to run the report in STATSPACK (spreport.sql) in a NON-interactive manner.
To do this, I need 3 parameters:
- begin_snap
- end_snap
- report_name
I have a version of the report named spreportBH.sql. This sql receives 3 parameters and generates the report success.
SQL > @spreportBH.sql 923 1111 /u01/BHB/test4.txt
For this example begin_snap=923, end_snap=1111 and report_name is /u01/BHB/test4.txt
My problem is that the snapid must be calculated based on the date.
To achieve this goal, I can query the table STATS$ SNAPSHOT.
For example, this query gives me the 923:
Select min (snap_id)
de PERFSTAT . STATS$ SNAPSHOT
où snap_time >= TO_DATE ('12-06-2014','dd-mm-YYYY');
I know that I can put the value in a variable. For this, I'm doing:
sqlplus "virtue sysdba" s < <! 1 > > ${fichier_de_sortie} 2 > > ${error_file}
DECLARE
firstSnapId NUMBER;
BEGIN
Select min (snap_id) INTO firstSnapId
of PERFSTAT. STATS\$ SNAPSHOT
where snap_time > = to_date ('12-06-2014', ' dd-mm-YYYY');
END;
/
!
How can I use firstSnapId to call @spreportBH.sql?
I'd appreciate any help that can give me.
Thank you d ' attribute
Bety
Hi, Bety,
So, you want to call a script in SQL * more. I'm not suggesting using PL/SQL use SQL * Plus Substitution Variable instead.
-The following command of the COLUMN said that everything which appears in a column called
-firstSnapIdCol will also go in a variable of substtitution called firstSnapId
COLUMN firstSnapIdCol new_value by firstSnapId
Select min (snap_id) AS firstSnapIdCol
of PERFSTAT. STATS$ SNAPSHOT
where snap_time > = to_date (6 December 2014 ", 'dd-mm-YYYY');
-Now that firstSnapId has a value, we can use it like this:
@spreportBH.sql & firstSnapID 1111 /u01/BHB/test14.txt
-
SELECT INTO make case-insensitive query?
Hi all
I'm having a problem with a query as if it is case-insensitive when I do a «SELECT table.x variable INTO...» ». If I do the same query, without the "variable INTO", I get a result as expected.
The query is similar to the following:
SELECT table_id variable FROM table WHERE table.varchar2column = 'name' AND table.integercolumn = int_variable;
There is a unique constraint, forcing the varchar2column / integercolumn of the unique values.
If the varchar2column has two entries that differ only in this case, a regular at the statement select returns a result. However, the procedure stored with the, I get the following error message:
ORA-01422: exact fetch returns more than number of lines
He gets not only if I remove the entry that only differs in the case of the letters. It is 10.2.0.1.0 Oracle, if that matters.
I need this application to be case-sensitive. I'm not an expert of the DB, I'm just a developer trying to solve a problem. I tried to run "ALTER session SET nls_sort = binary" in the stored procedure, but I guess I can't do that...
Any suggestion would be appreciated.As mentioned before... name your best-er settings.
Your setting is the same as the name of the column on the table that you query... bad move.
Here I change the username to work things p_username and 'magically '.
CREATE OR REPLACE FUNCTION get_cached_user_id(p_username user_security_table.username%type, authserver user_security_table.authentication_server_id%type) RETURN user_security_table.user_security_id%type IS cacheduserid user_security_table.user_security_id%type; BEGIN 6 SELECT uat.user_security_id INTO cacheduserid FROM user_security_table uat WHERE uat.username = p_username AND uat.authentication_server_id = authserver; IF cacheduserid IS NULL THEN SELECT uat.user_security_id INTO cacheduserid FROM user_security_table uat WHERE uat.username = 'anonymous' AND uat.authentication_server_id IS NULL; END IF; RETURN cacheduserid; EXCEPTION WHEN NO_DATA_FOUND THEN SELECT uat.user_security_id INTO cacheduserid FROM user_security_table uat WHERE uat.username = 'anonymous' AND uat.authentication_server_id IS NULL; RETURN cacheduserid; END; 21 / Function created. TUBBY_TUBBZ?SELECT get_cached_user_id('sample',20) from dual; GET_CACHED_USER_ID('SAMPLE',20) ------------------------------- 2 1 row selected. TUBBY_TUBBZ?
Simple fix... development of a standard in the future, as for all procedure using p_ settings can save you a lot of grief.
-
Query internal within a select if statement
I would like to know how to write an if condition inside a select statement of the present
I mean something likeb.inventory_item_id in( select distinct inventoryid from lcm.sis_inventario_new where fec_envio > to_date('28/01/2010','DD/MM/YYYY'))
select b.inventory_item_id as id, b.segment1 as c, b.segment2 as "Código", b.description as "Descripción", tl.description as "Descripción Larga", b.attribute1 as "Descripción Corta", c.segment1 as "Departamento",c.segment2 as "Familia", c.segment3 as "Subfamilia", b.creation_date as "Creado", b.INVENTORY_ITEM_STATUS_CODE as "Status", case b.attribute5 when '4' then 'Si' else 'No' end as "Pesado", case b.inventory_item_id when in select distinct inventoryid from lcm.sis_inventario_new where fec_envio > to_date('28/01/2010','DD/MM/YYYY')) then 'Si' else 'No' end as "Existe"
There are a number of ways, and the best solution for you will depend on several factors, including the index, the number of rows in the tables, etc..
Go using analytical functions;
with b as ( select rownum inventory_item_id from dual connect by rownum <=2), lcm as ( select 1 inventoryid, to_date('28/01/2000', 'DD/MM/YYYY') fec_envio from dual union all select 1, to_date('31/12/2010', 'DD/MM/YYYY') from dual union all select 2, to_date('28/01/2000', 'DD/MM/YYYY') from dual union all select 2, to_date('28/01/2008', 'DD/MM/YYYY') from dual) select b.inventory_item_id id, case when max(fec_envio) over(partition by b.inventory_item_id) > to_date('28/01/2010', 'DD/MM/YYYY') then 'Si' else 'No' end as existe from b, lcm where b.inventory_item_id = lcm.inventoryid; ID EXISTE ---------- ------ 1 Si 1 Si 2 No 2 No
Maybe you are looking for
-
AOL toolbar aol - 2.2 took my update for firefox 33.0.2
Windows 7. I can't find a way to get rid of the AOL toolbar. It does not appear in the Add-ons, such as a toolbar or my list of program windows or anywhere else. Everytime I open a new empty tab, it opens in AOL. I don't know how I got to a version o
-
Notification shadow Bug XT1064
I found a bug where I can't get out of the shadow of notification down. Hit the sleep/wake button and the sleep/wake and then again then allows the notification shade down, to work around the problem.
-
How to: save images on an SD card
Original title: I need to format my SD card, which will remove everything on it. Is there a way I can save the pictures on it? My camera says my SD card needs formatted. I can not use it on any of my computers beacause of Windows it must be formatted
-
windows update My computer keeps trying to install 14 updates, but when it gets to the point where the computer restarts returned back without installing them. Get an Error 80070020, I am unable to find out exactly what to do. Every day for a few wee
-
Pavilion g6 2226tu: 'no hard drive installed' error in material diagnostics UEFI
My pc is very slow and freezing much n after troubleshooting and consulted technicians on the chat, I went to the recovery. It's everything is OK with recovery but the same problem was there. N all of a sudden today I tried to restart it when it froz