Generate a table with number sequence in sql
=========
1 Pre-defined collection types in Oracle
---------
select to_number(column_value) as num from
table(sys.dbms_debug_vc2coll(1,2,3,4,5,6,7,8,9));
select to_number(column_value) as num from
table(sys.KU$_VCNT(1,2,3,4,5,6,7,8,9));
select column_value as num from
table(sys.KU$_OBJNUMSET(1,2,3,4,5,6,7,8,9));
2 Join: pure sql
---------
select a.i+b.i+c.i+d.i+1 as num
from
(select 0 i from dual union all select 1 from dual) a,
(select 0 i from dual union all select 2 from dual) b,
(select 0 i from dual union all select 4 from dual) c,
(select 0 i from dual union all select 8 from dual) d
order by num;
3 How to make number dynamic?
---------
?
3.1 Define function with collection type as return value
-----------------
It's not only sql.
And myaybe it's not correct or appropriate for dynamic.
However, I like it.
First, define a type:
create or replace type T_NUM_TAB as TABLE OF NUMBER;
Then, define the function:
CREATE OR REPLACE FUNCTION NUM_COLLECT (
NUM_START IN NUMBER,
NUM_END IN NUMBER,
NUM_STEP IN NUMBER DEFAULT 1)
RETURN T_NUM_TAB
AS
l_tab T_NUM_TAB := T_NUM_TAB();
l_idx NUMBER;
BEGIN
l_idx := NUM_START;
WHILE l_idx <= NUM_END LOOP
l_tab.extend;
l_tab(l_tab.last) := l_idx;
l_idx := l_idx + NUM_STEP;
END LOOP;
RETURN l_tab;
END;
Now, use it as follows:
SQL> select * from table(num_collect(2,10,2));
COLUMN_VALUE
------------
2
4
6
8
10
Is it a good idea to take sql string as parameter for the function?
分享到:
相关推荐
在这个"generate_sequence.rar"压缩包中,包含了四个MATLAB脚本文件,它们都是为了生成特定类型的马尔科夫序列。让我们逐一了解这些文件的功能: 1. **generate_sequence1.m**:这个脚本很可能是用来生成一阶...
Because a clustered index determines the sequence in which rows are stored in a table, there can only be one clustered index for a table at a time. Performance Considerations Keeping your clustered ...
SQL Multi Script™ Unlimited: execute multiple scripts against multiple SQL Servers with a single click SQL Comparison SDK ™: automate functionality with our APIs SQL Object Level Recovery Native™:...
SQL Data Generator - generate test data for database tables, SQL Server. SQL Multi Script - allows you to quickly and easily create complex scripts for SQL Server. SQL Refactor - helps the user to ...
SQL Multi Script™ Unlimited: execute multiple scripts against multiple SQL Servers with a single click SQL Comparison SDK ™: automate functionality with our APIs SQL Object Level Recovery Native™:...
to generate unbalanced targets with good prefixes but bad suffixes, and thus performance suffers when dealing with long sequences. We propose a simple yet effective approach to overcome this ...
Generate mybatis sql based on mybatis interface method name like spring data jpa, with this, you don't have to write most sql for non join query support generate statement with if test Database ...
In this paper, we show an extension of the model proposed by Sabourdy, combining various implicit surfaces with soft blending capacities in a CSG tree....through a limited number of parameters.
Get started on mastering... Knowing how to write good queries is the foundation for all work done in SQL, and it is a foundation that Clare Churcher's book, Beginning SQL Queries, 2nd Edition, lays well.
SQL Multi Script™ Unlimited: execute multiple scripts against multiple SQL Servers with a single click SQL Comparison SDK ™: automate functionality with our APIs SQL Object Level Recovery Native™:...
SQL Multi Script™ Unlimited: execute multiple scripts against multiple SQL Servers with a single click SQL Comparison SDK ™: automate functionality with our APIs SQL Object Level Recovery Native™:...
This is the final part of a three-part series on using LINQ to SQL: Part 1: Mapping Tables to Objects Part 2: Adding/Updating/Deleting Data Part 3: WPF Data Binding with LINQ to SQL These tutorials ...
Boost SQL coding in a convenient scripting environment Analyze and improve T-SQL code quality Design tables and rebuild them without losing data Compare databases, synchronize schemas and data Tackle ...
db_generate.sql# phpMyAdmin MySQL-Dump # http://phpwizard.net/phpMyAdmin/ # # -------------------------------------------------------- # # Table structure for table 'mantis_bug_table' # DROP TABLE ...
Intent locks improve performance because SQL Server examines intent locks only at the table level to determine whether a transaction can safely acquire a lock on that table. This removes the ...
It will introspect a database table (or many tables) and will generate artifacts that can be used to access the table(s). This lessens the initial nuisance of setting up objects and configuration ...
Swap bit i and j in a 64 bit number Chapter 19. Reverse the order of bits in an unsigned integer Chapter 20. Convert an integer to a string and a string to an integer Chapter 21. Convert a number ...