Wednesday, May 23, 2012

QTP Action Template

Whenever you open QTP new action you have to type few lines as comments, function call, execute repository etc. Here is the solution to automate it.

Following are the simple points to make it happen.

  • Create a simple text file and place your structured reusable code in the file.
    • e.g.
      '**************************************
      '    Purpose : This test case does the following:
      '        #    TODO describe about this action
      '    Assumptions    : -
      '    Effects : -
      '    Inputs : -
      '    Returns : -
      '    Author : <Author Name>
      '**************************************

      ' Force explicit variable declaration.
      Option Explicit

      ' load function library scripts
      funcCallMe(param1)

      '**************************************************
      ' Purpose: This function to be called for this action.
      '**************************************************
      Function funcCallMe(ByVal arg1)
          'TODO place your code here
      End Function
  •  Save the created text file as "ActionTemplate.mst"(must be the same name, only name recognized by QTP as Action Template) inside the directory "QTP_HOME/dat".
Now, if you will open a new test then the lines from created Template will be included in your Test.

Thursday, March 15, 2012

Eclipse: permGen or Maven error on console

Please add the following in the eclipse shortcut or eclipse.ini

For Shortcut:  place following lines in the shortcut target

"\eclipse.exe" -vm "\bin\javaw" -vmargs -Xms256m -Xmx768m -XX:PermSize=256M -XX:MaxPermSize=512M 

For eclipse.ini: place following lines in eclipse.ini
-vm 
"\bin\javaw" 
-vmargs 
-Xms256m 
-Xmx768m 
-XX:PermSize=256M 
-XX:MaxPermSize=512M

Replace the followings:
- Eclipse home
- JDK home


Tuesday, August 23, 2011

Duplicate rows from Oracle table

Remove duplicated including rows having "null"values

DELETE
FROM table_name t1
WHERE t1.rowid > ANY
  (SELECT t2.rowid
  FROM table_name t2
  WHERE (t1.col1 = t2.col1
  OR (t1.col1   IS NULL
  AND t2.col1   IS NULL))
  AND (t1.col2   = t2.col2
  OR (t1.col2   IS NULL
  AND t2.col2   IS NULL))
  );

Find and delete duplicate rows

DELETE
FROM table_name t1
WHERE rowid <>
  (SELECT MAX(rowid)
  FROM table_name t2
  WHERE t1.col1 = t2.col1
  AND t1.col2   = t2.col2
  );

Sunday, May 8, 2011

Oracle: Function to concatenate column output

 Type:

create or replace
TYPE        "STRINGAGGTYPE"                                          as object
    (
       theString varchar2(4000),
   
       static function
            ODCIAggregateInitialize(sctx IN OUT StringAggType )
            return number,
   
       member function
           ODCIAggregateIterate(self IN OUT StringAggType ,
                                value IN varchar2 )
           return number,
  
      member function
           ODCIAggregateTerminate(self IN StringAggType,
                                  returnValue OUT  varchar2,
                                  flags IN number)
           return number,
  
      member function
           ODCIAggregateMerge(self IN OUT StringAggType,
                              ctx2 IN StringAggType)
           return number
   );

Function:

create or replace
FUNCTION stringAgg(input varchar2 )
    RETURN varchar2
    PARALLEL_ENABLE AGGREGATE USING StringAggType;
Now, you can run a query like this:
select deptno, stringAgg(ename) enames from emp group by deptno;
Result:
DEPTNO  ENAMES
----------  ------------------------------
        10  CLARK,KING,MILLER
        20  SMITH,FORD,ADAMS,SCOTT,JONES
        30  ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD

Oracle: functions to join and split strings in sql



Join:


create or replace
function join
(
    p_cursor sys_refcursor,
    p_del varchar2 := ','
) return varchar2
is
    l_value   varchar2(32767);
    l_result  varchar2(32767);
begin
    loop
        fetch p_cursor into l_value;
        exit when p_cursor%notfound;
        if l_result is not null then
            l_result := l_result || p_del;
        end if;
        l_result := l_result || l_value;
    end loop;
    return l_result;
end join;
 /

Now, you can run a query like this:
select join(cursor(select ename from emp))from dual;
Split:

create or replace TYPE "SPLIT_TBL" as table of varchar2(32767);
/

create or replace
FUNCTION split(
      p_list VARCHAR2,
      p_del  VARCHAR2 := ',' )
    RETURN split_tbl pipelined
  IS
    l_idx pls_integer;
    l_list VARCHAR2(32767):= p_list;
  BEGIN
    LOOP
      L_IDX   :=INSTR(L_LIST,P_DEL);
      IF l_idx > 0 THEN
        pipe row(SUBSTR(l_list,1,l_idx-1));
        l_list:= SUBSTR(l_list,l_idx  +LENGTH(p_del));
      ELSE
        pipe row(l_list);
        EXIT;
      END IF;
    END LOOP;
    RETURN;
  END split;
 /


Now, you can run a query like this:  


SQL> select * fromtable(split('one,two,three'));


one
two
three

Ref: create functions to join and split strings in sql

Wednesday, September 29, 2010

Problem with Oracle 11.2.0.1

Following works on oracle 10g not on oracle11g.

SELECT column1,
 column2
FROM
 (SELECT 1 column1,2 column2,3 column3 FROM dual
 )
GROUP BY column1;


I found the same issue on Oracle Technology Forum (OTN). It seems there is a bug in Oracle 11.2.0.1.
this would be fixed by suggested workaround in the oracle forum.

Following should be set by Database administrator.
    set "_optimizer_group_by_placement"=FALSE

Reference: http://forums.oracle.com/forums/thread.jspa?threadID=1128695