How do I select from a nested table column in Oracle using go? - oracle

I am using go1.10.1 and querying Oracle 11.2.0.4. My local Oracle client is a 12.2 instant client. The go Oracle driver is goracle 2.5.4.
I am querying a table with a nested table (id column) that I need to retrieve as a list or some other iterable object. The nested table is simply a table of numbers.
CREATE TYPE id_type IS TABLE OF NUMBER;
CREATE TABLE account
(account_name VARCHAR2(1024),
id id_type)
NESTED TABLE id STORE AS id_tab;
Can I use a native go type to retrieve the nested table or do I need to use a type in the goracle driver?
Can I use the standard database/sql package or do I need something additional like github.com/jmoiron/sqlx?

Related

how to store an integer value in to sql table

i created this table and i want to be able to add Integer value of 99 in to Assgn_Id and Ben_Id. so i am very confident with my create table query.
Create table Advisor (
Advisor# Integer,
AdvisorName Varchar2(15),
Assgn_Id Integer,
Ben_Id Integer);
my second query is where i get confused. after i inserted the values into the table it seems like it work fine, but when i describe the table i see Number(38) datatype into both columns instead of Integers(99).
Insert Into Advisor (Assgn_Id, Ben_Id)
Values(99, 99);
Integer, INT, smallint are ansi defined data types - that Oracle has implemented as a number
I like to use integer for my tables because I'm lazy, it's easier to type.
From the docs..
SQL statements that create tables and clusters can also use ANSI data
types and data types from the IBM products SQL/DS and DB2. Oracle
recognizes the ANSI or IBM data type name that differs from the Oracle
Database data type name. It converts the data type to the equivalent
Oracle data type, records the Oracle data type as the name of the
column data type, and stores the column data in the Oracle data type
based on the conversions shown in the tables that follow.

Difference between TABLE and PL/SQL TABLE in ALL_ARGUMENTS view

While fetching data by query
select * from ALL_ARGUMENTS
It will return two types in DATA_TYPE column
1- TABLE
2- PL/SQL TABLE
I have checked through containing procedure, both types are declared in a similar way.
What is the difference between them?
Example -
Have declaration
TYPE Bom_Revision_Tbl_Type IS TABLE OF Bom_Revision_Rec_Type - PL/SQl TABLE
OBJECT_NAME PKG NAME ARGUMENT_NAME DATA_TYPE
PROCESS_BOM BOM_BO_PUB P_BOM_REVISION_TBL PL/SQL TABLE
TYPE inv_ebi_name_value_pair_tbl IS TABLE OF inv_ebi_name_value_pair_rec - SQL TABLE
OBJECT_NAME PKG NAME ARGUMENT_NAME DATA_TYPE
ID_TO_VALUE INV_EBI_ITEM_HELPER P_PK_COL_NAME_VAL_PAIRS TABLE
There are three collection types in PL/SQL.
Your Bom_Revision_Tbl_Type is an associative array:
An associative array (formerly called PL/SQL table or index-by table) is a set of key-value pairs. Each key is a unique index, used to locate the associated value with the syntax variable_name(index).
It's defined with an index by clause. That is still reported in all_arguments as a "PL/SQL table", using the old name for that collection type.
Your inv_ebi_name_value_pair_tbl type is a nested table.
The documentation explains the differences between them, and when each type is appropriate; associative arrays:
An associative array is appropriate for:
A relatively small lookup table, which can be constructed in memory each time you invoke the subprogram or initialize the package that declares it
Passing collections to and from the database server
and nested tables:
A nested table is appropriate when:
The number of elements is not set.
Index values are not consecutive.
You must delete or update some elements, but not all elements simultaneously.
Nested table data is stored in a separate store table, a system-generated database table. When you access a nested table, the database joins the nested table with its store table. This makes nested tables suitable for queries and updates that affect only some elements of the collection.
You would create a separate lookup table, with multiple entries for each row of the main table, and access it through join queries.

how to select data from two tables of different databases using dblinks in oracle?

i have a table t1 in database A and another table t2 in another database B.
how can we select data from them without using qualifiers directly..
just as database1.table1.something.
You should be able to query it with fully qualified names such as SCHEMA.TABLE#DBLINK.
If you don't want to use the #DBLINK notation while querying from database A you can mask the #DBLINK in a view (In database A) and query that view instead.
CREATE OR REPLACE VIEW remote_table [(column_list)]
AS select * FROM SCHEMA.TABLE#DBLINK;

How to create a table identical to other table in structure and constraints in Oracle?

I want to create a table (lets say table_copy) which has same columns as other table (lets call it table_original) in Oracle database, so the query will be like this :
create table table_copy as (select * from table_original where 1=0);
This will create a table, but the constraints of table_original are not copied to table_copy, so what should be done in this case?
Only NOT NULL constraints are copied using Create Table As Syntax (CTAS). Others should be created manually.
You might however query data dictionary view to see the definitions of constraints and implement them on your new table using PL/SQL.
The other tool that might be helpful is Oracle Data Pump. You could import the table using REMAP_TABLE option specifying the name for the new table.
Use a database tool to extract the DDL needed for the constraints (SQL Developer does the job). Edit the resulting script to match the name of the new class.
Execute the script.
If you need to do this programmatically you can use a statement like this:
DBMS_METADATA.GET_DDL('TABLE','PERSON') from DUAL;

OOP concepts in oracle 11.g

i have a question related to Object Orienting programming in oracle database(11.g),generally i have studyed how to create object types or how to create table from existing object,but i am stoped on one topic,namely,suppose that we have created following type
create or replace type mono.Item_type as object(
item_id integer,
part REF mono.Part_type,
quantity integer);
where Part_type is already existed object type.
i know that i can create table from this object like this:
create table tablename of Item_type,for instance
create table item_list of Item_type
what what would be different,if instead of this,we use
create or replace type mono.Item_List as table of Item_type;
here inspite of this,that we use type keyword,we are creating table again and what is different between create table tablename of Item_type and
create or replace type mono.Item_List as table of Item_type;?
When you use create table tablename of Item_type, you're creating a table in the DB.
This table is a structure that can be used to store user's data .
When you use create or replace type mono.Item_List as table you're defining a new Datatype (similar to array).
This Datatype can be used as a type of a column in a DB table or as a type of a variable in plsql code.

Resources