Saturday 2 may 2009 6 02 /05 /Mag /2009 10:33
To generate rows


select level l    from dual  connect by level <= 5

L

1
2
3
4
5


..and how to retrive only 5(n)  records from a table

SELECT * FROM
(
  SELECT rownum rn, u.*
     FROM users u
)
WHERE rn = 5;

Di rosario vigilante - Pubblicato in : Oracle Pl/Sql
Scrivi un commento - Vedi 0 commenti
Saturday 2 may 2009 6 02 /05 /Mag /2009 10:31
1) SELECT NVL(LENGTH(TRANSLATE('&str','A0123456789','A')),0) AS num_chars FROM   DUAL
 
2) SELECT length(regexp_replace('1p9j99','[[:digit:]]','')) FROM dual;


result:

123 should return 0
12A3 should return 1
1p9j99 should return 2
Di rosario vigilante - Pubblicato in : Oracle Pl/Sql
Scrivi un commento - Vedi 0 commenti
Saturday 2 may 2009 6 02 /05 /Mag /2009 10:25
If you'd be able to replicate all of Oracle's (or your) rules concerning numbers but it might be possible to validate using regular expressions and avoid context switching;

with t as (
   select '123' c1 from dual union all
   select ' 123 ' from dual union all
   select '12 3' from dual union all
   select '12.34.5 ' from dual union all
   select '12.34' from dual)
select c1,
   case when regexp_replace(trim(c1),'^([[:digit:]]*\.?[[:digit:]]*)?') is null
      then 'TRUE'
      else 'FALSE'
   end number_test
from t


Result:

C1    NUMBER_TEST

123 TRUE

123 TRUE

12 3 FALSE

12.34.5 FALSE

12.34 TRUE


Di rosario vigilante - Pubblicato in : Oracle Pl/Sql
Scrivi un commento - Vedi 0 commenti
Sunday 26 april 2009 7 26 /04 /Apr /2009 20:09

What do 'Query Hits' and 'Query Options' mean in the context of a block in 

Oracle Forms? 

 

 

Use SET_BLOCK_PROPERTY(<block name or id>, QUERY_HITS, <number>);  

in an On-Count transactional trigger to tell Oracle Forms how  

many records the query (that you are handling yourself) will return. 

When the On-Count trigger completes execution, Oracle Forms issues the 

standard query hits message:  

 

   "FRM-#####: Query will retrieve <number> records." 

 

 

Use GET_BLOCK_PROPERTY(<block name or id>, QUERY_HITS); 

to return the number of records that have been retrieved by the query. 

 

GET_BLOCK_PROPERTY(.., QUERY_OPTIONS); lets your transactional trigger know 

whether it is supposed to be doing a normal query, a COUNT(*) type query, or a 

lock record query. 

 


 

How can you save the count of the number of records retrieved by an 

EXECUTE_QUERY in a variable? 

 

This value is contained in the following Forms message that is displayed on 

the message line after a COUNT_QUERY is executed: 

 

FRM-40355: Query will retrieve <number> records. 

 

   

For example, you have a base table block based on the 'dept' scott/tiger 

table.   

 

In a PRE-QUERY trigger for the block, include the following code: 

 

   BEGIN 

     /* Restore the query criteria */ 

     :dept.deptno := :GLOBAL.deptno; 

     :dept.dname  := :GLOBAL.dname; 

     :dept.loc    := :GLOBAL.loc; 

   END; 

 

 

In an ON-COUNT trigger for the block, include the following code:  

 

   BEGIN 

     /* ON-COUNT trigger replaces default COUNT-QUERY functionality, */ 

     /* so you must still call COUNT_QUERY in this trigger.          */  

     COUNT_QUERY; 

 

     :GLOBAL.rows_fetched := GET_BLOCK_PROPERTY('dept', QUERY_HITS); 

   END; 

 

 

In a KEY-EXEQRY trigger for the block, include the following code: 

        

   BEGIN 

 

     /* Save the query criteria before getting cleared by COUNT_QUERY */ 

     :GLOBAL.deptno := :dept.deptno; 

     :GLOBAL.dname  := :dept.dname; 

     :GLOBAL.loc    := :dept.loc; 

 

     /* Executing COUNT_QUERY will call the ON-COUNT trigger */ 

     COUNT_QUERY;  

 

     EXECUTE_QUERY; 

  END; 

  

  

COUNT_QUERY clears the block, and queries the database to count the number of  

records that will be retrieved.  Because the block is cleared when COUNT_QUERY 

is executed, the query criteria must be restored in the PRE-QUERY trigger.    

The solution example above will work for queries with or without query 

criteria.  Both EXECUTE_QUERY and COUNT_QUERY fire the PRE_QUERY trigger, thus 

the additional query criteria can be enforced by setting the values in the 

PRE-QUERY trigger. 

 

The query hits value can be assigned to a local variable, global variable or 

parameter using the GET_BLOCK_PROPERTY(QUERY_HITS) function, as in the above 

example.  Note that GET_APPLICATION_PROPERTY(QUERY_HITS) returns a character 

value.   

 

By default, COUNT_QUERY prints an FRM-40355 message with the number of hits on 

the message line.  To prevent this message, write an ON-MESSAGE trigger to 

trap FRM-40355. 

 

If the value of QUERY_HITS is set while records are being retrieved from a 

query ( like in the KEYEXE-QRY trigger for example ), QUERY_HITS specifies the 

number or records that have been retrieved.  This value may be set to 0 even 

though records are retrieved.  Thus, you should use the ON-COUNT trigger to 

set the value by calling COUNT_QUERY, and then assign the value using 

GET_APPLICATION_PROPERTY( QUERY_HITS ). 

Di rosario vigilante
Scrivi un commento - Vedi 0 commenti
Sunday 26 april 2009 7 26 /04 /Apr /2009 19:56
FUNCTION query_count (p_block_name VARCHAR2) RETURN NUMBER
IS
  cnt NUMBER;
BEGIN
  GO_BLOCK(p_block_name);
  COUNT_QUERY;
  cnt := GET_BLOCK_PROPERTY(p_block_name, QUERY_HITS);
  IF FORM_SUCCESS THEN
    RETURN (cnt);
  ELSE
    MESSAGE('Error in getting Query Hits for block '||:SYSTEM.CURRENT_BLOCK);
    RAISE FORM_TRIGGER_FAILURE;
  END IF;
END;



WHEN-BUTTON-PRESSED trigger of 'Details' button

DECLARE
   v_cnt NUMBER;
BEGIN
   v_cnt := query_count(<detail block name>);
   IF (v_cnt = 0) THEN
     p_show_alert('No Details exist.');
   ELSE
     GO_BLOCK(<detail block name>);
     EXECUTE_QUERY;
   END IF;
 END;

Di rosario vigilante - Pubblicato in : Oracle Forms
Scrivi un commento - Vedi 0 commenti

Presentazione

Categorie

Calendario

January 2012
M T W T F S S
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
<< < > >>
Crea un blog gratis su over-blog.com - Contatti - C.G.U. - Remunerazione in diritti d'autore - Segnala abusi