Visualizzazione post con etichetta Oracle. Mostra tutti i post
Visualizzazione post con etichetta Oracle. Mostra tutti i post

mercoledì 13 marzo 2024

DBeaver

Hi all

Today I want speak about one of the best DB Client tool in the market : DBeaver .





Why it's so good : 

1) It's an open source project, here github page. 

2) It's multi DB, instead to have many DB client, one for every DB. 

3) It's fast and light.

Before to discover it, I'm using for Oracle DB, ToaD and SQLDeveloper, both of them don't satisfy any of points above.

Actually I am using it for Oracle, Sqlite, Mysql and PostgreSQL.  

Actually, when I write this post, last version is 24.0.0, new versions are released with a great frequency and behind it there are a large community.   

So download it and enjoy.

Stay tuned. 

martedì 8 marzo 2022

Three ways to get error message/stack in PL/SQL

Hi All

Today I speak about how manage errors in PLSQL.

This link speaks about three ways to manage errors in PLSQL, it's very clear and complete.

Basically, exists three forms to manage it :

  • SQLERRM
  • DBMS_UTILITY.FORMAT_ERROR_STACK
  • UTL_CALL_STACK API (From Oracle 12c version)
I invite you to read the link for more details.

Stay tuned.





mercoledì 21 gennaio 2015

ORACLE DBA SCRIPT

Hi all

Today i want report this link http://oracle-base.com/dba/scripts.php that contains an interesting repository of  oracle sql script.

Scripts are divided for release and type.


Very useful are script to monitoring database in the first section.

Stay tuned.

lunedì 13 maggio 2013

Hierarchical data in a relational database

Hi All

Today an interesting article about how represents hierarchical data in a relational database.

 http://fungus.teststation.com/~jon/treehandling/TreeHandling.htm

Interesting this concept :




Every node must have a node identify and a "Child of" identify. So the key of every object is formed by two keys :

  • ID_NODE
  • CHILD_OF

For example (represents image above) :

ID_NODE  CHILD_OF
1
1
2
1
3
1
4
2
5
3
6
5


Stay tuned.







martedì 2 aprile 2013

Oracle Nested Table - Create, Insert and Select

Hi all

Today i want to speak about oracle nested table.
Basically you can define in oracle a field that is a table inserted in other table. In Oracle system tables there are two tables used to manage this particular type of columns :
  • USER_NESTED_TABLES              : Nested Table List
  • USER_NESTED_TABLE_COLS    : Nested Table List Columns


Now an example to test it.

1) Creation a Type :

CREATE OR REPLACE TYPE VALUELIST AS TABLE OF VARCHAR2(20);

2) Creation Table :

CREATE TABLE NESTED_TABLE
(  ID            NUMBER           NOT NULL,
   FIELD1   VALUELIST)
NESTED TABLE FIELD1 STORE AS field1_tab;

3) Inserting values in table :

INSERT INTO nested_table VALUES (1, valuelist('Red'));
INSERT INTO nested_table VALUES (2, valuelist('White', 'Brown'));
INSERT INTO nested_table VALUES (3, valuelist('Blue', 'Orange','Yellow'));

4) Select values :

SELECT id, COLUMN_VALUE FROM nested_table t1, TABLE(t1.field1) t2;

5) Result :

ID    COLUMN_VALUE
1 Red
2 White
2 Brown
3 Blue
3 Orange
3 Yellow

In select statement you must reference a pseudo-column called "COLUMN_VALUE". To select values from a nested table, always you must explain mother table too.

Stay tuned.

martedì 26 marzo 2013

Oracle OCI C - Wrapper OCILIB

Hi all

Today i want report a great open source project.
I've used and improved it for several years in many personal and professional processes.

For me is the best Oracle OCI C wrapper, easy to use and with a very good documentation.


I test it on several environment : HP/UX PaRisc, Itanium, Linux, Windows XP,7 and with differents ORACLE DB versions : 9,10,11.

I recommend it, you can find it in this link.

Stay tuned

venerdì 22 marzo 2013

Oracle Function to get a specific field from a String contains fields characters delimited



Hi All

Today a simple function to extract a field from a String contains characters delimited fields.
I want use regexp_substr function but there are some problems for null fields to extract, so i develop this simple function.

CREATE OR REPLACE FUNCTION
  get_field (iString IN VARCHAR2, iSeparator IN VARCHAR2, field_num IN NUMBER)
RETURN VARCHAR2
IS
   oField VARCHAR2(1024);
   position_field NUMBER;
   position_field_start NUMBER;
   position_field_end NUMBER;
BEGIN

  IF field_num = 1 THEN
     position_field :=  INSTR(iString,iSeparator);
     IF position_field > 0 THEN
        SELECT SUBSTR(iString,1,INSTR(iString,iSeparator)-1) INTO oField FROM DUAL;
     ELSE
        oField := iString;
     END IF;
  ELSE
      position_field_start :=  INSTR(iString,iSeparator,1,field_num-1);
      position_field_end :=  INSTR(iString,iSeparator,1,field_num);

      IF position_field_start > 0 THEN
      
            IF position_field_end = 0 THEN
               position_field_end := length(iString)+1;
            END IF;
           SELECT SUBSTR(iString,position_field_start+1,position_field_end-position_field_start-1) INTO oField FROM DUAL;
      ELSE
         oField := null;
      END IF; 
  END IF;

  RETURN (oField);
END;

For example you have this string '10;12;34;233;12' delimited by ';' character and you wont get third field.
You can call this oracle function in this way :

SELECT GET_FIELD('10;12;34;233;12',';',3) FROM DUAL;

Results will be : '34'.

I hope can help someone with same problem.

Stay tuned


mercoledì 19 ottobre 2011

Script sql for sqlldr

Hi

This is a script sql to create a dat and a ctl file to load data on an oracle table from a user to another user.

I searched this on internet without success so i had wrote it.

Enjoy :

--
-- Created by Giovanni Palleschi - Ver. 1.0 - 10/10/2011
--
-- This script sql permits to create files dat and ctl for sqlldr oracle utility
-- Script accepts in input two parameters :
--
-- 1) Table Name
-- 2) Condition to extract
--
-- Ej. sqlplus pippo/pluto @gpgen_sqlloader.sql TABLE1 "1=1"
--
-- In this mode will be extracted all rows from table TABLE1.
-- Script will produce two files :
--
-- ./TABLE1.dat
-- ./TABLE1.ctl
--
--
set echo off
set termout off
set feedback off
SET serverout ON size unlimited
set linesize 8192
set pagesize 0
set verify off
set heading off

host echo ' Start Generacion sqlloader files for table &1 and condition &2'
host echo ' '
host echo ' '
host echo ' ......... Working ......... '
host echo ' '
host echo ' '

spool ./gen_dat.wrk

DECLARE

-- TO MODIFY

Separator VARCHAR2(1) := CHR(29);
DateFormat VARCHAR2(20) := 'YYYYMMDD HHMISS';

CURSOR UserTabColumns_cursor ( TableName IN VARCHAR2 )
IS
SELECT
COLUMN_ID,
COLUMN_NAME,
DATA_TYPE,
DATA_LENGTH
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = TableName ORDER BY COLUMN_ID;
recUserTabColumns UserTabColumns_cursor%ROWTYPE;

BEGIN

DBMS_OUTPUT.PUT_LINE('###QUERY###SET LINESIZE 8192');
DBMS_OUTPUT.PUT_LINE('###QUERY###SET PAGESIZE 0');
DBMS_OUTPUT.PUT_LINE('###QUERY###SET HEADING OFF');
DBMS_OUTPUT.PUT_LINE('###QUERY###SELECT ');

DBMS_OUTPUT.PUT_LINE('###CTRL###LOAD DATA');
DBMS_OUTPUT.PUT_LINE('###CTRL###INFILE ''./&1..dat''');
DBMS_OUTPUT.PUT_LINE('###CTRL###BADFILE ''./LOG/&1..bad''');
DBMS_OUTPUT.PUT_LINE('###CTRL###DISCARDFILE ''./LOG/&1..dsc''');
DBMS_OUTPUT.PUT_LINE('###CTRL###APPEND');
DBMS_OUTPUT.PUT_LINE('###CTRL###INTO TABLE &1');
DBMS_OUTPUT.PUT_LINE('###CTRL###FIELDS TERMINATED BY '''|| Separator || '''');
DBMS_OUTPUT.PUT_LINE('###CTRL###TRAILING NULLCOLS');
DBMS_OUTPUT.PUT_LINE('###CTRL###(');

OPEN UserTabColumns_cursor('&1');
LOOP
FETCH UserTabColumns_cursor INTO recUserTabColumns;
EXIT WHEN UserTabColumns_cursor%NOTFOUND;

IF recUserTabColumns.COLUMN_ID > 1 THEN
DBMS_OUTPUT.PUT_LINE('###QUERY###||''' || Separator || '''||');
DBMS_OUTPUT.PUT_LINE('###CTRL###,');
END IF;

IF recUserTabColumns.DATA_TYPE = 'DATE' THEN
DBMS_OUTPUT.PUT_LINE('###QUERY### to_char(' || recUserTabColumns.COLUMN_NAME || ',''' || DateFormat || ''')');
DBMS_OUTPUT.PUT_LINE('###CTRL###' || recUserTabColumns.COLUMN_NAME || ' DATE ' || '"' || DateFormat ||'"');
ELSIF recUserTabColumns.DATA_TYPE IN ('LONG RAW','LONG','RAW') THEN
DBMS_OUTPUT.PUT_LINE('###CTRL### ' || recUserTabColumns.COLUMN_NAME);
DBMS_OUTPUT.PUT_LINE('###QUERY### ''''');
ELSIF recUserTabColumns.DATA_TYPE in ('VARCHAR2','NVARCHAR2','NCHAR','CHAR') THEN
DBMS_OUTPUT.PUT_LINE('###QUERY### REPLACE(' || recUserTabColumns.COLUMN_NAME || ',CHR(10),'' '')');
DBMS_OUTPUT.PUT_LINE('###CTRL### ' || recUserTabColumns.COLUMN_NAME || ' CHAR(' || recUserTabColumns.DATA_LENGTH || ')');
ELSE
DBMS_OUTPUT.PUT_LINE('###QUERY### ' || recUserTabColumns.COLUMN_NAME);
DBMS_OUTPUT.PUT_LINE('###CTRL### ' || recUserTabColumns.COLUMN_NAME);
END IF;

END LOOP;
CLOSE UserTabColumns_cursor;
DBMS_OUTPUT.PUT_LINE('###QUERY###FROM &1 WHERE &2;');
DBMS_OUTPUT.PUT_LINE('###CTRL###)');

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20001,
'Oracle Error MSG: >' || SQLERRM(SQLCODE) || '<');
END;
/
spool off

host grep "###QUERY###" ./gen_dat.wrk > ./gen_dat.wrk2
host sed -e "s/###QUERY###//" -e "s/ *$//" ./gen_dat.wrk2 > ./gen_dat.sql
host grep "###CTRL###" ./gen_dat.wrk > ./gen_dat.wrk2
host sed -e "s/###CTRL###//" -e "s/ *$//" ./gen_dat.wrk2 > ./&1..ctl

spool ./gen_dat.wrk
@./gen_dat.sql
spool off

host sed -e "s/ *$//" ./gen_dat.wrk > ./&1..dat

--host rm -fr ./gen_dat.wrk
--host rm -fr ./gen_dat.wrk2
--host rm -fr ./gen_dat.sql

host echo ' '
host echo ' '
host echo ' End Generacion sqlloader files for table &1 and codition &2 '
host echo ' '
host echo ' sqlldr userid=user/password control=./&1..ctl log=./&1..log'
host echo ' '
host echo ' '
quit;

Stay tuned.

lunedì 22 novembre 2010

UPDATE TABLE A FROM TABLE B IN ORACLE

Hi all

A little big problem, i always forget in oracle how to do an update on a table from data on another table, so i fix it in my blog :

update table1
set field = (
select field
from table2
where table2.id = table1.id
);

Stay tuned.



mercoledì 17 novembre 2010

SP-552 oracle bind variable not declared

Hi all,

About this error we have lost many time. I hope this post can help someone.
My script sql is :


set verify off

set heading off

set linesize 400

spool RIL_388_OP_INS_AnagD4

COLUMN indGruppoiInG NEW_VALUE indGruppoiInG

SELECT max(substr(nome_elemento_associazione,4,4))+1 indGruppoiInG FROM SCTELEM_ASSOC WHERE TIPO_ASSOCIAZIONE = 'GRUPPI_IN' AND NOME_ELEMENTO_ASSOCIAZIONE LIK
E 'GIG%';

SELECT '@INFO AGGIUNTO GRUPPO IN ' || 'GIG' || lpad(to_char(&indGruppoiInG),4,'0') || ' IN CATEGORIA LA UNDELIVERED SERV >' || 'CATG0010' || '<' from dual; COLUMN indGruppoiInG NEW_VALUE indGruppoiInG SELECT max(substr(nome_elemento_associazione,4,4))+1 indGruppoiInG FROM SCTELEM_ASSOC WHERE TIPO_ASSOCIAZIONE = 'GRUPPI_IN' AND NOME_ELEMENTO_ASSOCIAZIONE LIK E 'GIG%'; SELECT '@INFO AGGIUNTO GRUPPO IN ' || 'GIG' || lpad(to_char(&indGruppoiInG),4,'0') || ' IN CATEGORIA LA UNDELIVERED SERV >' || 'CATG0010' || '<' from dual;


spool off


When we have executed this script alone it was OK. But when it was executed after another script, was showed this error :

SP-552 oracle bind variable "indGruppoiInG" not declared

After many controls we have discovered that a previously script seated "set define #", this command (see this link causes previously error.
Solution for this error was put at beginning my script sql, this command :

set define on

To avoid previously different define setting.

Stay tuned.

martedì 18 maggio 2010

CUBE and ROLLUP options in GROUP BY

For my actual project i am studying CUBE and ROLLUP option in GROUP BY.
These options are present from Oracle 8i and are very interesting :

ROLLUP

Rollup enables a SELECT statement to calculate multiple levels of subtotals across a specified group of dimension. Really is an extension of GROUP BY clause.
In this example are summarized totals and sales for Departments and Job Title with each totals for Department.

















CUBE

Cube enables a SELECT statement to calculate subtotals for all possible combinations of a group of dimension.
In this example are summarized totals and sales for Departments and Job Title with each totals for Department and also for each job title.






















Stay connected.

Check Mid Year Objectives

Hi all Today middle year check of my 2026's goals. 1. ENGLISH Improve listening comprehension (So and So)   See at least one or two film...