Let’s say we have the following bookmark table and we want to add an unique constraint on the url column:

CREATE TABLE bookmark (
    id          NUMBER(10, 0),
    url         VARCHAR2(500 CHAR) ,
    PRIMARY KEY ( id )
);

INSERT INTO bookmark ( id, title, url, is_public) VALUES (1, 'https://www.bookmarks.dev');
INSERT INTO bookmark ( id, title, url, is_public) VALUES (2, 'https://www.codepedia.org');
INSERT INTO bookmark ( id, title, url, is_public) VALUES (3, 'https://www.bookmarks.dev');

Normally you would use the following ALTER TABLE command to add a unique constraint on the url column

ALTER TABLE bookmark ADD CONSTRAINT unique_url UNIQUE (url);

-- but you get an ORA-02299 saying the "unique_url" cannot be validated, because the table has duplicate key values

In this case and if you have existing data, that might not be unique you will get an ORA: error, if you execute the command before. However, you can overcome this if you use one of the following:

-- tell oracle not to validate the existing data at the time of the creation of the uniqueconstraint
ALTER TABLE bookmark ADD CONSTRAINT unique_url UNIQUE (url) DEFERRABLE NOVALIDATE;

-- create the unique constraint "disabled" and "enable" after that with the "NOVALIDATE" option
ALTER TABLE bookmark ADD CONSTRAINT unique_url UNIQUE (url) DISABLE;
ALTER TABLE bookmark ENABLE NOVALIDATE CONSTRAINT unique_url;

To see the created constraint and its attributes use the following command(s):

-- show all constraint for the table
SELECT * FROM user_constraints WHERE table_name = 'BOOKMARK'; -- note upper case

-- show our created unique constraint
SELECT * FROM user_constraints WHERE table_name = 'BOOKMARK'
   AND CONSTRAINT_NAME ='UNIQUE_URL';  -- note also here the upper case

To drop the unique constraint use the following command:

ALTER TABLE bookmark DROP CONSTRAINT unique_url;

Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Create an example table in an existing Oracle schema, which holds data about bookmarks. Add some comments as metadata to the table and to a column:

CREATE TABLE bookmark (
    id                 NUMBER(10, 0), -- number 10 digits before the decimal and 0 digits after the decimal
    title              VARCHAR2(255 CHAR) NOT NULL, -- String with a maximum length of 255 charachters
    url                VARCHAR2(500 CHAR) UNIQUE NOT NULL, -- holds unique values across the table data
    category      VARCHAR2(500 CHAR) NOT NULL, -- holds unique values across the table data
    is_public      NUMBER(1, 0) NOT NULL, -- plays the role of a boolean '0'-false, '1'-true ,
    created_at   DATE NOT NULL, --  when the entry is created
    PRIMARY KEY( id )
);

COMMENT ON TABLE bookmark IS
    'Table holding data about bookmarks';

COMMENT ON COLUMN bookmark.is_public IS
    'Boolean like 1-is public accessible, 0-is private';

With the table now created, insert values in it with the following syntax

INSERT INTO bookmark ( id, title, url, category, is_public, created_at )
VALUES (
    1,
    'BookmarksDev - Bookmarks and Code Snippets Manager',
    'https://www.bookmarks.dev',
    'developer-tools',
    1,
    TO_DATE( '2021-01-01', 'YYYY-MM-DD' )
);

INSERT INTO bookmark ( id, title, url, category, is_public, created_at )
VALUES (
    2,
    'CodepediaOrg - Share code knowledge',
    'https://www.codepedia.org',
    ' blog',
    1,
    SYSDATE -- current time in oracle
);

SELECT * FROM bookmark;

To remove the table, all rows from the table, table indexes and domain indexes are removed with the following command

DROP TABLE bookmark;

Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

if is a control flow tag, that can change the information Liquid shows using programming logic:


{% if page.title %}
  {% if page.jsonld %}
    {% include {{page.jsonld}}.html %}
  {% else %}
    {% include postJSONLD.html %}
  {% endif %}
{% else %}
  {% include homeJSONLD.html %}
{% endif %}

Reference - https://shopify.github.io/liquid/tags/control-flow/


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use the page.categories variable and select index 0 of the array:


  {% if page.categories[0] != "snippets" %}
    {% include promote-bookmarks.dev.html %}
  {% endif %}

Reference - https://jekyllrb.com/docs/variables/


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Convert the array into String using Collectors.joining() method of the stream package:

import java.util.stream.Collectors;
import java.util.stream.Stream;

class GenerateStringFromArray {
  public static void main(String[] args) {

    String[] values = {"Bookmarks.dev -", "Bookmarks", "and", "code snippets", "manager"};

    String text = Stream.of(values)
        .map(Object::toString) // in this case you can remove the map, but useful for complexer objects
        .collect(Collectors.joining(" "));

    System.out.println(text);
  }
}

Result

"Bookmarks.dev - Bookmarks and code snippets manager"

Reference - https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.