Friday, July 8, 2016

How to show Post Text dynamically in Text Field in Oracle APEX and in HTML on Focus using jQuery and CSS?

In Oracle Apex-

Click below link to see demo-
https://apex.oracle.com/pls/apex/f?p=S_MYDEMO:POSTXT:&APP_SESSION.:::::

Create page items as text field P3_TEXT1, then create dynamic action
as Get Focus > Items > name
Create True action > Set Value
give some value e.g., *
select affected element as jquery selector > .t-Form-itemText--post
Create True action > Execute JavaScript Code
$(".apex-item-text").focus(function (){
$(".t-Form-itemText--post").css('display','none');
    $(this).next(".t-Form-itemText--post").css('display','inline').show();
    $(this).next(".t-Form-itemText--post").animate({ color: "rgb( 150, 10, 160 )"},'slow');
});

It's Done.

HTML Example:

<html>
<head>
<style>
#sp {display:none;color:red;}
</style>
<script type="text/javascript">
$("input").focus(function (){
$(this).next("#sp").css('display','inline').blink(2000);
});
</script>
</head>
<body>
<p>Field 1<input type="text" /><span id="sp">&nbsp;mandatory</span></p>
<p>Field 2<input type="text" /><span id="sp">&nbsp;mandatory</span></p>
</body>
</html>


Thursday, July 7, 2016

How to send mail in UNIX Shell Script?



#!/bin/bash
RETVAL=`<<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
SELECT 'shivam' FROM dual;
EXIT;
EOF`
if [ -z "$RETVAL" ]; then
  echo "No rows returned from database" | mailx  -s "TEXT...... is corrupted" shivam.kumar91@gmail.com
  exit 0
else
  echo $RETVAL
fi

How to Create Exception in PL/SQL?

First Declare your exception name in Declaration section-
my_excp EXCEPTION

Then need to Raise your defined exception inside Begin section-
RAISE my_excp;

And last, Catch it in Exception section and and link the exception to a user-defined error number-
WHEN my_excp THEN
....

Below is the example of how to do-

DECLARE
my_excp EXCEPTION;
v_int1 NUMBER := 0;

BEGIN

IF v_int1 <> 3 THEN
RAISE my_excp;
END IF;

EXCEPTION

WHEN my_excp THEN
raise_application_error (-20009,'this is my exception');
END;

*** The Error number must be between -20000 and -20999

Note: DBMS_OUTPUT.PUT_LINE('test'); -- this will not work with raise_application_error



How to change or toggle image onClick ?


Take two different images to toggle.
we can achieve this functionality by using javascript or by jQuery.

HTML-

<img src="images/arrow-up.png" onclick="hide_f(this)" style="display:none;" class="class_1" id="minus_2" />

<img src="images/arrow-down.png" onclick="show_f(this)" class="class_1" id="plus_2" />

Javascript-

Using function names-

function show_f(ele) {
document.getElementById("minus_2").style.display = "block";
document.getElementById("plus_2").style.display = "none";
}
function hide_f(elem) {
var id2 = elem.id;
document.getElementById("minus_2").style.display = "none";
document.getElementById("plus_2").style.display = "block";
}

jQuery-

Using jQuery functions-

jQuery(function ($) {
        $(document).ready(function(){
   $("#plus_2, #minus_2").click(function(){
    $("#minus_2, #plus_2").toggle();
   });
 });
});

Tuesday, July 5, 2016

How to find the value before or after Comma "," in Oracle sql?

using REGEXP_SUBSTR we can find out values before or after comma.


Here I am extracting the value before comma based on occurrence. The below code searches for a comma, return one or more occurrences of non-comma characters


SELECT REGEXP_SUBSTR ( 'KUMAR,SHIVAM,MYTHASS' , '[^,]+' , 1, 1) FROM DUAL;

The above code will extract the first occurrence of non-comma character.

If you want to extract the second occurrence of non-comma character, you need to find the second appearance-

SELECT REGEXP_SUBSTR ( 'KUMAR,SHIVAM,MYTHASS' , '[^,]+' , 1, 2) FROM DUAL;

Same way you can find Nth appearance of non-comma character.