Oracle, Web, Script, SQLserver, Tips & Trick

July 14, 2020

Query to get previous data for several years

Filed under: oracle — sikathabis @ 8:24 pm
Tags: ,

I’ve 3 categories to show data from loan master,
1. Date opening loan range 3 until 5 years
2. Date opening loan range 5 until 10 years
3. Date opening loan > 10 years

This is the script to show all data:

select 'PRODUK 604 range 3 s/d 5 tahun' KATEGORI, kd_kntr, kd_produk, kd_sub_produk, kd_val,no_rek, nm_nas, sld_akhir, sisa_bunga, tgl_akad_kredit 
from ln_master
where kd_produk=6 and kd_sub_produk=4 and kd_val=0 and tgl_akad_kredit < trunc(add_months(sysdate,-(3*12))) and tgl_akad_kredit =trunc(add_months(sysdate,-(5*12)))
union
select 'PRODUK 604 range 5 s/d 10 tahun' KATEGORI, kd_kntr, kd_produk, kd_sub_produk, kd_val,no_rek, nm_nas, sld_akhir, sisa_bunga, tgl_akad_kredit
from ln_master
where kd_produk=6 and kd_sub_produk=4 and kd_val=0 and tgl_akad_kredit < trunc(add_months(sysdate,-(5*12))) and tgl_akad_kredit =trunc(add_months(sysdate,-(10*12)))
union
select 'PRODUK 604 range > 10 tahun' KATEGORI, kd_kntr, kd_produk, kd_sub_produk, kd_val, no_rek, nm_nas, sld_akhir, sisa_bunga, tgl_akad_kredit
from ln_master
where kd_produk=6 and kd_sub_produk=4 and kd_val=0
and tgl_akad_kredit < trunc(add_months(sysdate,-(10*12)));

January 12, 2020

Script to generate DDL from all schema except sys, system, etc.

Filed under: oracle — sikathabis @ 11:35 pm
Tags: ,
set heading off;
set echo off;
Set pages 1000;
set long 50000;
SET linesize 150;
spool d:\exec_Myddl.sql;
select 'set heading off; set echo off;Set pages 1000;set long 50000; SET linesize 150; spool d:\My_ddl.sql;' from dual;
select 'select DBMS_METADATA.GET_DDL(''TABLE'','''||table_name||''','''||owner||''') from dual;' from all_tables
where owner not in ('SYS','SYSTEM','SYSMAN','DBSNMP','OUTLN','MDSYS','ORDDATA','APPQOSSYS','GSMADMIN_INTERNAL','XDB',
'DBSFWUSER','WMSYS','OJVMSYS','CTXSYS','LBACSYS','OLAPSYS','LBACSYS','DVSYS','HR','DEV_WLS','DEV_OPSS',
'DEV_IAU','DEV_STB','SCOTT','DEV_WLS_RUNTIME','ORDSYS');
select 'spool off;' from dual;
spool off;
@d:\exec_myddl.sql;
/

NOTE: The exec_mydll.sql file is automate to generate script DDL, and the result is my_ddl.sql

May 8, 2019

How to connect Form/Report dev6i to Oracle Database 12c

Filed under: dev6i,oracle,oracle:12c — sikathabis @ 2:21 am
Tags: , , ,

We have database 10.2.0.5, want to convert to 12.2.0.1, the step are:
– exp from 10.2.0.5
– imp to 12.2.0.1
import Oracle 12.2.0.1 has been completed.

And then the first problem is oracle form crash when connecting to oracle 12.2.0.1

After searching, the solution come from this website:
https://www.youtube.com/watch?v=V0Achdev4gA

CONNECT AS SYSDBA
CONNECT SYSTEM USER (SYSTEM/(OWN YOUR DATABASE PASSWORD))
SHUTDOWN IMMEDIATE;
STARTUP RESTRICT;
ALTER DATABASE CHARACTER SET INTERNAL_USE WE8MSWIN1252;
SHUTDOWN;
STARTUP MOUNT;
SHUTDOWN;
STARTUP RESTRICT;
SHUTDOWN;
STARTUP;

After solving the first problem, then the second problem is coming, ORA-28040: No matching authentication protocol

For second problem, this reference is the solution:
http://logic.edchen.org/how-to-resolve-ora-28040-no-matching-authentication-protocol/

Adding SQLNET.ALLOWED_LOGON_VERSION_SERVER=8 to sqlnet.ora in 12.1 database server (not the old client).

Connecting successfulle but still got malformed TTC package message, will solved later ..

SQL*Plus: Release 8.0.6.0.0 – Production on Wed May 8 15:24:46 2019

(c) Copyright 1999 Oracle Corporation. All rights reserved.

Enter password:
ERROR:
ORA-03137: malformed TTC packet from client rejected: [kpoal8Check-5] [0]
[0x000000000] [0x000000000] [0] [0] [2080] []

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 – 64bit Production

SQL>



February 2, 2018

How to fix Cannot load OCI DLL: D:\oracle\instantclient_10_2\oci.dll

Filed under: oracle,toad — sikathabis @ 7:34 am
Tags: , ,

We have Oracle database 11.2.0.4 (red hat linux 64bit) and the client connect from Windows 10 64bit

Firstable, on the client we are using Oracle client 10.2.0.5 32 bit and setting ORACLE_HOME by environment variables using this tutorial:
https://sikathabis.wordpress.com/2013/09/12/menjalankan-toad-dengan-oracle-client-basic-lite-for-windows/

But we have a problem, the toad cannot find the setting ORACLE_HOME, after we searching how to fix it, then we set the ORACLE_HOME on the regedit:
Clipboard03
Second problem is show message “Cannot load OCI DLL: d:\oracle\instantclient_10_2\oci.dll” and then try to fix it by using Oracle Instant Client 32bit with same version Oracle Database 11.2.0.4, and …… the toad connected from windows 10

September 14, 2017

How to connect oracle 12c from toad 9.7

Filed under: oracle,oracle:12c,toad — sikathabis @ 3:34 am
Tags: , ,

You must have Oracle Client 10g and then replace 12c
https://sikathabis.wordpress.com/2013/09/12/menjalankan-toad-dengan-oracle-client-basic-lite-for-windows/

Example
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.111)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orclpdb)))

December 2, 2016

How to get http from cmd (dev 6i)

Filed under: dev6i,dos,oracle,windows — sikathabis @ 8:05 pm
Tags: , , , ,

I have an application using oracle developer 6i (dev 6i). The application must communicate with the website to get the result. For example: If the application click the button then will access http: // localhost /show, and then the result “It works” showing to the application

I found winhttpjs.bat ( https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/winhttpjs.bat )

CMD> call winhttpjs.bat http://localhost/show -saveTo result.txt

If the result

CMD> Status: 200 OK

then file result.txt contained the result of website It work’s

If the result

CMD>  A connection with the server could not be established

then file result.txt contained The system cannot find the file specified.

To get the result for dev6i I’m using HOST to get the result and TEXT_IO for retrive text file (result.txt)

Download ~ winhttpjs-bat (erase .doc)

September 6, 2016

How to convert full name to first, middle and last name on oracle

Filed under: oracle — sikathabis @ 8:57 am
Tags: ,

/* Sql to generate or convert fullname to firstname, middlename and lastname */

with name_list as
(select ‘1’ NO, ‘ACEP’ name from dual
union
select ‘2’ NO, ‘TAUFIK HIDAYAT’ name from dual
union
select ‘3’ NO, ‘DEPAN TENGAH BELAKANG’ name from dual
union
select ‘4’ NO, ‘DONO KASINO INDRO WARKOP’ name from dual)
select no, name
, case when length(name) – length(replace(name,’ ‘,null)) 0 then
substr(trim(name), 1, instr(trim(name), ‘ ‘) – 1) else name end AS FIRST_NAME
, case when length(name) – length(replace(name,’ ‘,null)) >1 then
rtrim(substr(trim(substr(name, instr(name, ‘ ‘) + 1)), 1, instr(substr(trim(substr(name, instr(name, ‘ ‘) + 1)), 1, length(name)), ‘ ‘)-1)) else ” end AS MIDDLE_NAME
, case when length(name) – length(replace(name,’ ‘,null)) >1 then
substr(trim(substr(name, instr(name,’ ‘,1,2) + 1)), 1, length(name))
when length(name) – length(replace(name,’ ‘,null)) >0 then
substr(trim(substr(name, instr(name, ‘ ‘) + 1)), 1, length(name)) else ” end AS LAST_NAME
from name_list order by 1;

–Output

NO   NAME                     FIRST_NAME    MIDDLE_NAME    LAST_NAME
1    ACEP                     ACEP        
2    TAUFIK HIDAYAT           TAUFIK        HIDAYAT
3    DEPAN TENGAH BELAKANG    DEPAN         TENGAH         BELAKANG
4    DONO KASINO INDRO WARKOP DONO          KASINO         INDRO WARKOP

Reference : http://stackoverflow.com/questions/371490

 

July 26, 2016

Contoh PL/SQL pengambilan nama dari separator koma (,)

Filed under: oracle — sikathabis @ 7:59 pm
Tags: ,

Contoh:

DECLARE
KALIMAT varchar2(100):=’DD_MASTER,LN_MASTER_AUDIT,TRAN_HIST,TASPEN’;
kata varchar2(100):=null;
c number:=0;
BEGIN
FOR i in 1..length(KALIMAT)
LOOP
if substr(kalimat,i,1)=’,’ then
c:=c+1;
end if;
END LOOP;
(more…)

June 9, 2016

Print using default printer on local computer (Oracle Developer 6i, windows)

Filed under: dev6i,oracle,windows — sikathabis @ 7:29 am
Tags: , , , , ,

this example, I want to show you how to automate print using default printer on local computer.

PROCEDURE GENERATE_VALIDATION (ID1 number, ID2 number, ID3 DATE) IS
    PL_ID PARAMLIST;
    filename varchar2(255);
    teks varchar2(255);
    IN_FILE TEXT_IO.FILE_TYPE;
BEGIN
    pl_id := Create_Parameter_List('TEMP'); 
    ADD_PARAMETER(PL_ID,'ID_1',TEXT_PARAMETER,ID1);
    ADD_PARAMETER(PL_ID,'ID_2',TEXT_PARAMETER,ID2);
    ADD_PARAMETER(PL_ID,'ID_3',TEXT_PARAMETER,ID3);
--this statement for get default printer and generate to text file
    host('CMD /C wmic printer where default=''TRUE'' get name > '||filename,NO_SCREEN);
--because wmic generate 3 lines, this statement for get only line where the 
--default printer located

    host('CMD /C Powershell "Get-Content '||filename||' | Select-Object -Index 1" > '||filename||'.txt', NO_SCREEN );
    begin
        IN_FILE  := TEXT_IO.FOPEN(filename||'.txt', 'r');   
        TEXT_IO.GET_LINE(IN_FILE,TEKS);
        --Trim TEKS, because there is spaces after default printer name
        TEKS := LTRIM(RTRIM(TEKS));
        TEXT_IO.FCLOSE(IN_FILE);
    exception when others then
        TEXT_IO.FCLOSE(IN_FILE);
    end;  

--erase temporary files

    host('CMD /R DEL '||filename||'.*',NO_SCREEN);    

--if there's default printer then automate print default printer on local computer

    if TEKS is null then
         ADD_PARAMETER(PL_ID,'DESTYPE',TEXT_PARAMETER,'PRINTER');
         ADD_PARAMETER(PL_ID,'DESNAME',TEXT_PARAMETER,TEKS);
--if there's no default printer then show your report
    else
         ADD_PARAMETER(PL_ID,'DESTYPE',TEXT_PARAMETER,'SCREEN');
    end if;     
    Add_Parameter(pl_id,'PARAMFORM', TEXT_PARAMETER, 'NO');
    Add_Parameter(pl_id,'PRINTJOB',  TEXT_PARAMETER,'YES'); 

    Run_Product(REPORTS,'VALIDATION', SYNCHRONOUS, RUNTIME,FILESYSTEM, pl_id, NULL);     
    Destroy_Parameter_List(pl_id);
END;

Reference: https://technet.microsoft.com/en-us/library/hh849895.aspx | https://adamstech.wordpress.com/2010/11/1 | http://stackoverflow.com/questions/17217476..

Notes: For windows XP/2003 you must install powershell, here’s the links:

  1. Microsoft .NET Framework 2.0 Service Pack 1 (x86)
  2. Update for Windows XP (KB968930): includes Windows PowerShell 2.0 and Windows Remote Management (WinRM) 2.0
  3. Update for Windows 2003

 

February 17, 2016

How to create Script to generate a table structure in oracle

Filed under: oracle — sikathabis @ 9:13 am
Tags: ,

–Script

select  tc.table_name "TABLE",
        column_id ID,
        rtrim(column_name) COLUMN_NAME, 
        rtrim(data_type) ||
        rtrim(decode(data_type,'DATE',null,'LONG',null,
               'NUMBER',decode(to_char(data_precision),null,null,'('),
               '(')) ||
        rtrim(decode(data_type,
               'DATE',null,
               'CHAR',data_length,
               'VARCHAR2',data_length,
               'NUMBER',decode(to_char(data_precision),null,null,
                 to_char(data_precision) || ',' || to_char(data_scale)),
               'LONG',null,
               ''))||
        rtrim(decode(data_type,'DATE',null,'LONG',null,
               'NUMBER',decode(to_char(data_precision),null,null,')'),
               ')')) || ' ' || ' ' DATA_TYPE,
        rtrim(decode(nullable,'N','NOT NULL',null)) OTHERS
from    dba_tab_columns tc,
        dba_objects o
where   o.owner = tc.owner
and     o.object_name = tc.table_name
and     o.object_type = 'TABLE' 
and     o.owner = 'USERDATABASE';

–Example result

TABLE    ID   COLUMN_NAME   DATA_TYPE     OTHERS
ACUAN    1    ID            NUMBER        NOT NULL
ACUAN    2    MIN_RATING    NUMBER(22,5)  NOT NULL
ACUAN    3    MAX_RATING    NUMBER(22,5)  NOT NULL
ACUAN    4    RISK_RATING   CHAR(10)      NOT NULL
KD_TRAN  1    ID            VARCHAR2(20)  NOT NULL
KD_TRAN  2    KD_TRAN       VARCHAR2(4)   NOT NULL

Next Page »

Blog at WordPress.com.

Pureblood

DONT WANNA BE NUMBER ONE

Teknologi Pendidikan

Just another WordPress.com weblog

BLOG KATAKAMI

Jurnalisme Yang Dapat Dipercaya

Tonk Kosonk Baonk Bunyinya

Penampungan Serapah Tanpa Sumpah

Qey050489's Blog

Ayo Bangkit sobat..!!!!!

B. S. Totoraharjo

Orang Desa Yang Mencintai Desa dan Kebudayaannya

culturekitchen foodlab

New Food and Art in Yogyakarta

Wahyu Catur Wibowo

Musafir Dunia Maya

SQL.... Still Learning

My Reference on SQL Server

arihdyacaesar

"Tuhan tidak menuntut kita untuk menang. Tuhan hanya meminta kita untuk berjuang tanpa henti.” -ean-

neinframe

Street Photography is like a box of a chocolates, you're never know what you're gonna get - Thomas Leuthard -

Be a good Moeslim

Menuju Pribadi Muslim Sejati yang Bertaqwa

TuanSUFI

Manajemen Sholat, renungan spiritual, Teknologi Informasi

Pelangi di khatulistiwa....

Mari berbagi kebaikan, pengalaman dan senyum denganku

Angkasa13

Ceritanya saya, Pikirannya saya, Hatinya saya

sikathabis

sikathabis semua informasi disini