Friday, May 17, 2013

PL/SQL Working with Cursors


SELECT-INTO

Simple Select
declare
  l_last_name employees.last_name%type;
begin
  select last_name
    into l_last_name
    from employees
    where employee_id=138;
 
    dbms_output.put_line(l_last_name);
end;

Join

declare
  l_last_name employees.last_name%type;
  l_department_name departments.department_name%type;
begin
  select last_name, department_name
  into l_last_name, l_department_name
  from employees e, departments d
  where e.department_id=d.department_id
  and e.employee_id=138;

  dbms_output.put_line(
        l_last_name||
        ' is working in '||
        l_department_name ||
        ' department.');
end;

Cursor FOR Loop


declare
  cursor test_cur
  is
    select * from employees
    where department_id=50;
begin
  for c1
  in test_cur
  loop
    dbms_output.put_line(
      c1.first_name||
      ' '||
      c1.last_name
    );
  end loop;
end;


Friday, March 1, 2013

PL/SQL Functions


function fnc_my_function(p_id number) return number is
    v_counter       number := 0;
   
    begin
       
        select count(k.varsayilan)
        into v_count
        from test_table k
        where id=p_id;
     
        return v_counter;
                                         
        exception
            when no_data_found
            then
            return null ;
       
    end ;

-- Test the function


select package_name.fnc_my_function(65243)
from dual;

Thursday, February 28, 2013

PL/SQL Working with Date Value


select * from table_name where id=181
and column_date=to_date('28.02.2013 10:39:15', 'dd.mm.yyyy hh24:mi:ss');

Tuesday, February 19, 2013

Working with "Paths" in C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProTestService
{
    class Program
    {
         static void Main(string[] args)
         {
             string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
             path = Path.Combine(path.Replace("file:\\", ""), "test.txt");
             using (StreamWriter newTask = new StreamWriter(path, true))
             {
                  newTask.WriteLine("ProTestService calisma zamani--> " +DateTime.Now.ToString());
             }
         }
     }
}


PL/SQL Insert into one table from another by using sequence


insert into table_1
(
  col_1, col_2, col_3
)
select  seq_my_sequence.nextval,
        k.col_2,
        k.col_3,
        from my_schema.table_2 k;

PL/SQL Grant Select on One Table within Schema

grant select on table_name to schema_name;

Monday, February 4, 2013

PL/SQL Using In&In Reverse Options in the Loop


begin
  for v_counter in 0..10 loop
      if mod(v_counter,2)=0 then
            dbms_output.put_line('v_counter='||v_counter);
          end if;
    end loop;
    dbms_output.put_line('Done...');
end;

begin
  for v_counter in reverse 0..10 loop
      if mod(v_counter,2)=1 then
            dbms_output.put_line('v_counter='||v_counter);
          end if;
    end loop;
    dbms_output.put_line('Done..');
end;


*******outputs********
v_counter=0
v_counter=2
v_counter=4
v_counter=6
v_counter=8
v_counter=10
Done...

v_counter=9
v_counter=7
v_counter=5
v_counter=3
v_counter=1
Done..