I'm running mysql 5.0 and have created a trigger. Roughly as follows:
SET #temp =(SELECT STATEMENT);
IF(#temp = 'true') THEN
-code block 1-
ELSE
-code block 2-
END IF;
When I run my select statement alone it returns 'true' however in the code above 'code block 2' is being executed. Any idea why?
If your select statement is returning a boolean value then this should work:
SET #temp =(SELECT STATEMENT);
IF(#temp = true) THEN
-code block 1-
ELSE
-code block 2-
END IF;
It looks like #temp contains way more than 'true'. Without any additional information, this seems it should be re-written so you aren't searching through strings. However, this may be what you are looking for (if 'true' is in the return string):
IF (INSTR(#temp, 'true') > 0) THEN
-code block 1-
ELSE
-code block 2-
END IF
Related
In scheme settings page in section Login Processing, field Authentication Function is set to AUTORYZACJA (function name)
Field logout URL: wwv_flow_custom_auth_std.logout?p_this_flow=&APP_ID.&p_next_flow_page_sess=4155:PUBLIC_PAGE
here is my function:
create or replace FUNCTION AUTORYZACJA (p_username in VARCHAR2, p_password in VARCHAR2)
return BOOLEAN
is
v_pwd_baza varchar2(4000);
v_liczba number;
begin
select count(*) into v_liczba from UZYTKOWNICY where upper(login) = upper(p_username);
if v_liczba > 0 then
select password into v_pwd_baza from UZYTKOWNICY where upper(login) = upper(p_username);
if p_password = v_pwd_baza then
return true;
else
return false;
end if;
else
return false;
end if;
end;
Loging using schema with this function does not work. Error is "invalid login credentials". I don't know what to do.
I will appreciate your help with this situation.
You should also always use hashed passwords, don't store them in plain text.
See something like http://apexawy.blogspot.com.au/2011/07/custom-authentication-scheme.html
The ora-06553 you received was because you tried to reference a boolean in SQL (the return value) - SQL has no awareness of booleans. You would need to test using something like
begin
if autoryzacja('login','password') then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
/
Add debug logging to your function. This should show you where the problem is occurring.
If you are in apex 4.1 use a statement like:
apex_debug_message.log_message('username is: ' || p_username ||
' and password is ' || p_password);
For apex 4.2, use:
apex_debug.message('username is: ' || p_username || ' and password is '
|| p_password);
A statement like this at the beginning of the function, plus one each place you are assigning a value and inside each if should show you where things are going wrong.
Then click debug on the developer tool bar and try to login. After it fails click view debug and you should see your debug messages in the log.
I have a stored procedure being called from an .aspx.cs page. I have a parameter that sometimes cannot be sent when the sproc is called. Because of this I'm doing the following:
IF #variable is null
BEGIN
...do this...
END
Else
...do that...
My problem is in the IF statement. As far as I can tell when I use any of the following:
if #parameterVariable = null
if #parameterVariable = ''
if #parameterVariable <= 0
Nothing happens!? When I debug the sproc in SSMS I find that (even though the parameter is empty (no user selection)) that the cursor goes to and runs the code in the ELSE statement. Am I doing something wrong?
Thanks!
use optional parameter:
CREATE PROCEDURE uspTest
#param1 varchar(50) = null,
AS
BEGIN
SELECT col1, col2
FROM Table1
WHERE
((#Param1 IS NULL) OR (col1 = #Param1))
END
if #parameterVariable = null is wrong.
Change it to if #parameterVariable IS NULL.
Here is a SQL Fiddle demonstrating this: http://www.sqlfiddle.com/#!6/6cb42/1
when debugging in SMSS, you must check the box that says "Pass null value". otherwise your value is an empty string or somesuch.
I use the pattern you suggest all the time, and it works well for me.
i suggest you to read this page => ANSI NULLS
actually if #var = null is not wrong, everything depends on the value of ANSI_NULLS :)
I keep getting a error when i run this code, What wrong with the code?
create or replace function f_vars(line varchar2,delimit varchar2 default ',')
return line_type is type line_type is varray(1000) of varchar2(3000);
sline varchar2 (3000);
line_var line_type;
pos number;
begin
sline := line;
for i in 1 .. lenght(sline)
loop
pos := instr(sline,delimit,1,1);
if pos =0 then
line_var(i):=sline;
exit;
endif;
string:=substr(sline,1,pos-1);
line_var(i):=string;
sline := substr(sline,pos+1,length(sline));
end loop;
return line_var;
end;
LINE/COL ERROR
20/5 PLS-00103: Encountered the symbol "LOOP" when expecting one of
the following:
if
22/4 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
end not pragma final instantiable order overriding static
member constructor map
Stack Overflow isn't really a de-bugging service.
However, I'm feeling generous.
You have spelt length incorrectly; correcting this should fix your first error. Your second is caused by endif;, no space, which means that the if statement has no terminator.
This will not correct all your errors. For instance, you're assigning something to the undefined (and unnecessary) variable string.
I do have more to say though...
I cannot over-emphasise the importance of code-style and whitespace. Your code is fairly unreadable. While this may not matter to you now it will matter to someone else coming to the code in 6 months time. It will probably matter to you in 6 months time when you're trying to work out what you wrote.
Secondly, I cannot over-emphasise the importance of comments. For exactly the same reasons as whitespace, comments are a very important part of understanding how something works.
Thirdly, always explicitly name your function when ending it. It makes things a lot clearer in packages so it's a good habit to have and in functions it'll help with matching up the end problem that caused your second error.
Lastly, if you want to return the user-defined type line_type you need to declare this _outside your function. Something like the following:
create or replace object t_line_type as object ( a varchar2(3000));
create or replace type line_type as varray(1000) of t_line_type;
Adding whitespace your function might look something like the following. This is my coding style and I'm definitely not suggesting that you should slavishly follow it but it helps to have some standardisation.
create or replace function f_vars ( PLine in varchar2
, PDelimiter in varchar2 default ','
) return line_type is
/* This function takes in a line and a delimiter, splits
it on the delimiter and returns it in a varray.
*/
-- local variables are l_
l_line varchar2 (3000) := PLine;
l_pos number;
-- user defined types are t_
-- This is a varray.
t_line line_type;
begin
for i in 1 .. length(l_line) loop
-- Get the position of the first delimiter.
l_pos := instr(l_line, PDelimiter, 1, 1);
-- Exit when we have run out of delimiters.
if l_pos = 0 then
t_line_var(i) := l_line;
exit;
end if;
-- Fill in the varray and take the part of a string
-- between our previous delimiter and the next.
t_line_var(i) := substr(l_line, 1, l_pos - 1);
l_line := substr(l_line, l_pos + 1, length(l_line));
end loop;
return t_line;
end f_vars;
/
Given the following SP ...
CREATE PROCEDURE [dbo].[trytest1]
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT 'Testing 1'
DECLARE #int1 INTEGER
DECLARE #int2 INTEGER
DECLARE #int3 INTEGER
SET #int1 = 0
SET #int2 = 0
BEGIN TRY
SELECT 'Testing 2'
SET #int3 = #int1 / #int2
SELECT 'Testing 3'
END TRY
BEGIN CATCH
SELECT 'Testing 4'
END CATCH
SET #int3 = #int1 + #int2
SELECT 'Testing 5'
Executing this gives ...
Testing 1
Testing 2
Testing 4
Testing 5
Return Value -6
Catch catches divide by zero, but execution continues after catch block
Im curious why even though query executed successfully and
continued after the trycatch normally, the return value is -6. Will it stay -6 forever?
And, while I'm here, just curious, is it possible to continue execution in Try Block (ie select 'Testing 3')
Thanks
that's the standard behavior on all exception handling mechanisms. You have a TRY and a CATCH and code in between. If you have an exception in the code, it stops from running and go to the CATCH block.
If you want the SELECT 'Testing 3' to be executed, it must be placed outside the TRY...CATCH block.
If you dont want to execute anything else on the proc, you either put everything on the TRY...CATCH block OR exists the execution on the catch block
Inside MySQL I have written a Procedure where I want to run a loop like this:
While (Cond) Do
...(Body1)
...
If (Condition2)
continue ;
...(Body2)
...
end while ;
Under the while loop I want the full body to run in case where Condition2 is not met (ie Body1 and Body2).
Currently, when Condition 2 is met, it just executes Body1 and then continues(Check Cond in While and Continue looping.)
Can someone help with the proper syntax to perform the above?
BEGIN
WHILE cond1 DO
CALL body1;
IF (NOT cond2) THEN
CALL body2;
END IF;
END WHILE;
END;