EVRS settings for Scan Profile of KTA

Tags

, , ,

Sample of EVRS settings

_DoSkewCorrectionPage_
_Do90DegreeRotation_4
_DoScaleImageToDPI_300
_DoColorDropOut_
_DoEnhancedBinarization_
_DoBlankPageDetection_
_DoColorDetection_
_DoEdgeCleanup_
_DoBackgroundSmoothing_
_DoHoleFill

eVRS command string modules

This section contains information on eVRS settings and properties strings that can be used in TotalAgility Scan/VRS profile (on the Advanced tab of the extended properties).

Most of the eVRS image processing settings are unavailable by default, but appropriate keywords included in the operations string enable the corresponding settings. In the operations string a leading “_” character indicates the start of a new keyword or parameter. The trailing “_” character may be followed by a setting value: a string in <> or one or more numeric values.

The following table describes the eVRS strings.

KeywordeVRS StringDescription
DO_HEALTH_ANALYSIS_DoHealthAnalysis_Activates scanner health analysis.
DO_HOLE_FILL_DoHoleFillFills punch holes on document edges in order to match the surrounding page background. Performed for dark backgrounds only.
DO_BLANK_PAGE_DETECTION_DoBlankPageDetection_Detects if the page is blank so that it could be deleted by the application. Capable of ignoring punch holes. In Duplex mode, it is capable of ignoring bleed-through from the opposite side.Note If EVRS cannot detect the page boundaries within the input image, it is not possible to detect either the presence or the absence of any content within it.
DO_COLOR_DETECTION_DoColorDetection_Limits binarization to only those pages that do not contain any color.
DO_COLOR_DROPOUT_DoColorDropOut_Activates detection and removal of the most common foreground color within the page.
DO_SKEW_CORRECTION_PAGE_DoSkewCorrectionPage_Deskews to page.
DO_SKEW_CORRECTION_ALT_DoSkewCorrectionAlt_Deskews to content.
DO_CROP_CORRECTION_DoCropCorrection_Crops to minimize the bounding box around the final position of the page after deskew.
DO_NO_PAGE_DETECTION_DoNoPageDetection_Informs EVRS that the incoming image has been already deskewed and cropped, so no page detection is necessary.
DO_BINARIZATION_DoBinarization_Converts the image to binary.
DO_ENHANCED_BINARIZATION_DoEnhancedBinarization_Combines noise reduction ability of lower resolution images with smoother character contours characteristic of higher resolutions.Useful for creation of binary images with resolutions above 300 DPI.
DO_GRAY_OUTPUT_DoGrayOutput_Converts the image to grayscale.
DO_SCANNER_BKG_FILL_DoScannerBkgFill_Fills scanner background touching the border of the final image with average color of the page. Used mainly to fill missing corners or other rips in the page. Performed for dark backgrounds only.
DO_CONTOUR_CLEANING_DoContourCleaning_Adds a little margin to the scanner area filled during SCANNER_BKG_FILL.
DO_90_DEGREE_ROTATION_Do90DegreeRotation_nPerforms image rotation in 90 degree increments or automatically, based on image content where n:1=90 degrees counterclockwise;2=180;3=270 and4=automatic.
DO_ROTATE_NONE_Do90DegreeRotation_0
DO_ROTATE_90_Do90DegreeRotation_3
DO_ROTATE_180_Do90DegreeRotation_2
DO_ROTATE_270_Do90DegreeRotation_1
DO_ROTATE_AUTO_Do90DegreeRotation_4
DO_ROTATE_AUTO_PLUS_90_Do90DegreeRotation_7DO_ROTATE_90 after AUTO
DO_ROTATE_AUTO_PLUS_180_Do90DegreeRotation_6DO_ROTATE_180 after AUTO
DO_ROTATE_AUTO_PLUS_270_Do90DegreeRotation_5DO_ROTATE_270 after AUTO
DO_ROTATE_AUTO_PLUS_LAND_L_Do90DegreeRotation_8If in Portrait after AUTO, additionally DO_ROTATE_90
DO_ROTATE_AUTO_PLUS_LAND_R_Do90DegreeRotation_9If in Portrait after AUTO, additionally DO_ROTATE_270
DO_ZONE_MASKING_DoZoneMasking_Specifies the position and specific parameters of the zone of interest to be preserved in the returned image.
DO_EDGE_CLEANUP_DoEdgeCleanup_Cuts a small frame around the final image to clean the fringes of the page.Note You must specify both _DoSkewCorrectionPage_ and _DoCropCorrection_ for _DoEdgeCleanup_ to have any effect.
DO_DESPECK_DoDespeck_nRemoves speckles on the image to improve image quality. N=4 is the typical despeck size for the sample program. The valid range is 1 to 50, with the higher settings removing larger speckles in the output image.
DO_SHARPEN_DoSharpen_nSharpens processed color or gray image, where n:1= a little,2= more,3= most.
DO_FIND_GRAPHIC_LINES_DoFindGraphicLines_Finds horizontal and vertical graphic lines in the image.
DO_REMOVE_GRAPHIC_LINES_DoRemoveGraphicLines_Finds and removes graphic lines from the processed binary image.
DO_BACKGROUND_SMOOTHING_DoBackgroundSmoothing_Smoothen page background for color and grayscale images.
DO_MERGE_FRONT_BACK_DoMergeFrontBack_Merges both sides of a page scanned in duplex into a single image.
FINAL_IMAGE_SMALLER_PIXEL_DIM_FinalImageSmallerPixelDim_nSpecifies pixel size n of the smaller side of the final image.
FINAL_IMAGE_LARGER_PIXEL_DIM_FinalImageLargerPixelDim_nSpecifies pixel size n of the larger side of the final image.
FINAL_IMAGE_DPI_FinalImageDPI_nSpecifies DPI n of the final image.
IMAGING_DEVICE_TYPE_DeviceType_nSpecifies the image origin, where n:0= scanner (default)2= mobile cameraNote When processing the mobile camera images, usually the DPI is not set correctly or is missing from the image metadata. In such cases, eVRS returns an error. To avoid this, add _DeviceType_2 to the eVRS processing string.

To load properties of a processing module, use the operation string “_LoadInlineSetting_<PropertyName=”XXXX” Value=”YY” Comment=”ZZZZ”/>”. The strings XXXX, YY and ZZZZ indicate property name, value and comments.

Export a generated PDF via .NET method instead of Export node

Tags

, , ,

12831

It is possible in KTA to export a generated PDF without using the Export node.

To do this, we utilise the CaptureDocumentService.GetDocumentFile method. This method returns an object of type Stream. As stream isn’t a supported type in KTA, this has to be called from .NET code.

Please find a sample below on how this could be achieved.

    CaptureDocumentService cds2 = new CaptureDocumentService();
    string documentId = "6A3ADB9C-00E9-4CB3-A516-A48400964E36";

    using (Stream stream = cds2.GetDocumentFile("CF804840115111D48C6100104B71BD07", null,
documentId, "pdf"))
    {
        stream.CopyTo(new FileStream(@"c:\exported\test1.pdf", FileMode.Create,
FileAccess.Write));
    }

See the following article for possible caveats:
Why might requesting a PDF from the CaptureDocumentService.GetDocumentFile API return an unexpected result?

Keywords: Stream, .Net code

Debugging .NET Assemblies in KTA

Tags

, , ,

Visual Studio can be used to debug .NET assemblies in KTA.3011154

Debugging an External Process

When debugging a DLL loaded by a separate process, such as .NET assemblies used in KTA processes and forms, you will need to tell Visual Studio to attach to that process. This is done by clicking “Attach to Process…” in the Debug menu. 

AttachToProcess

Determining Correct Process to Debug

The process you need to debug is the process that is loading your assembly and executing the .NET activity or action that you have configured. If you are trying to debug a non-interactive activity in a process, like a .NET process activity, then this is being processed by the Core Worker Service, so you would attach the debugger to Agility.Server.Core.WorkerService.exe.

If you are debugging something that is running from an interactive form, such as a .NET form action, then this is being processed by the IIS Application Pool process, which means you would need to attach to w3wp.exe. However, it is common to have multiple IIS Application Pool processes running on a system, and it is important to attach to the correct one. To determine which process ID is the correct instance of w3wp.exe, run the following command from an elevated command prompt to see which process ID belongs to each Application Pool:

%windir%\system32\inetsrv\appcmd.exe list wp
clipboard_e592e98a1af7e2442fef7a6ac25f0bb14.png

If on a distributed installation, debugging will need to be done on the system running the relevant process.

Where is the DLL file?

If using a local reference, then the DLL file is wherever you have specified. To update it after creating a new build, it will likely be needed to restart the relevant process (Core Worker, or IIS App Pool) so the DLL can be replaced and so the new build can be loaded.

If the DLL has been added to the KTA assembly store, ensure that it has a strong name and an incrementing assembly version as documented here. Upon first use of a specific version of the DLL in the store, the DLL will be downloaded and used locally from the generated assemblies folder (C:\ProgramData\Kofax\TotalAgility\Generated Assemblies\.NET Assemblies). The name will be “OriginalName_YYYY-MM-DD hh-mm-ss.dll”

Stopping at a Breakpoint

Once Visual Studio attached to the correct process, if all else is well, the debugger will break on breakpoints in your code. Unrelated to KTA, there are many possible pitfalls that can interfere with successful debugging.  Most issues will need to be approached with Visual Studio-centric troubleshooting that is beyond the scope of this article, however, the KTA specific details in this article may assist that troubleshooting.

Debugger Does Not Stop at Breakpoint

The simplest reason for the debugger to not stop at a breakpoint is that the code at that point is not actually being run. Double check configuration in KTA to ensure that it is actually running the KTA action that uses the assembly. Double check that the code execution will definitely reach your breakpoint. Consider adding a breakpoint to the first line of the top level function being called by KTA. 

The simplest technical problem that prevents stopping at a breakpoint is that debug symbols, in the form of a matching PDB file, could not be loaded. The breakpoint may show an exclamation mark with the message “The breakpoint will not currently be hit. No symbols have been loaded for this document.” If the DLL has not been loaded at all, then simply initiate whatever action in KTA that would use this assembly so that it loads. If it still shows this message then this suggests that it was not able to load a matching DLL and PDB file.

Is the DLL loaded, and does the DLL match the PDB?

After attaching to a process with Visual Studio, the loaded DLLs can be seen by opening the Modules window (Debug > Windows > Modules). Sort by name to find the DLL of interest. This will also show whether the debug symbols (PDB) are loaded for the DLL, which is required for debugging to work. If they are not loaded, then more detail can be seen by right clicking on the DLL and clicking “Symbol Load Information…”. The right click menu also has a Load Symbols command which allows specifying a PDB file from a different location.

ModulesWindowWithSymbolLoadInformation

If the symbol load information specifies “PDB does not match image”, the most common problem is that the DLL has been rebuilt in Visual Studio (which produces an updated PDB file), without being updated in KTA. The debugger must have the PDB file that is an exact match for the DLL.

Example Debugging Steps

  1. Build a DLL with a strong name and an incrementing assembly version as documented here.
  2. Add or Update this DLL in KTA Assembly Store in the KTA Designer under Integration > .NET Assemblies
  3. Configure a button on a form to call a function from this DLL, and Release the form.
  4. Navigate to the form and click the button, which causes the DLL to be loaded into KTA’s IIS App Pool process
  5. From an elevated command prompt, run the following command to confirm the correct App Pool process
    %windir%\system32\inetsrv\appcmd.exe list wp
  6. In Visual Studio, Debug > Attach to Process…, then select the w3wp process with the process ID of the TotalAgility App Pool.
  7. Open the Modules window (Debug > Windows > Modules), and sort by name to find the DLL, which should confirm that both the DLL and symbols have been loaded.
  8. Set a breakpoint in the function configured to be called by the form.
  9. Navigate to the form and click the button, which should cause the debugger to stop at the breakpoint.

Why might requesting a PDF from the CaptureDocumentService.GetDocumentFile API return an unexpected result?

Tags

, , ,

307306

Question / Problem: 

The KTA API function CaptureDocumentService.GetDocumentFile takes a fileType parameter and will try to return the requested file type if available.  Notably, when requesting a PDF, this could return the original document source if it was created from a PDF, or it can return a PDF that has previously been created from a PDF Generation activity.  PDFs are not created on demand by this API, so one of these must exist for data to be returned.  This also means that it is possible to get a PDF from this API that does not represent the current state of the document.  This is best explained by an example:

  • Imagine you import two single-page PDFs as two documents, therefore the document/source file is a single page PDF for each. 
  • The job goes through Image Processing, so each job has a single page object (tiff), and the document/source files remain a single page PDF for each. 
  • Now imagine the documents are merged in Validation or by API: There is now a single document with two page objects (tiffs).
  • What happened to the two source documents (each a single page PDF)? They are unchanged, which is to say the document being merged into (merge destination) STILL has the same single page PDF. The document that was the merge source is deleted after the merge, so the second single page PDF no longer exists.
  • You can still retrieve this document’s source PDF, but it is no longer a logical representation of the merged document (single page PDF, two page tiff document).
  • Now if you run this merged document through PDF generation, it will create a two page PDF. However, instead of replacing the source document, this is stored as a Document Extension (Kofax.CEBPM.PdfRepresentation).
  • Now that there are two PDFs that represent the document in different ways, which should be returned when you call GetDocumentFile(sessionId, null, docID, ”PDF”)?

Answer / Solution: 

Ideally, more specific API functions can be used to get the specific data needed.  Frequently GetDocumentFile is used to try to get the PDF that was generated in a PDF Generation activity.  There are two ways to target this data more specifically.

  1. CaptureDocumentService.GetBinaryExtension can be called for a given document ID with a name value of “Kofax.CEBPM.PdfRepresentation”.  This will directly retrieve the PDF that was generated for this document.
  2. CaptureDocumentService.DeleteSourceFile can be called if the source file is no longer needed.  Then a subsequent call to GetDocumentFile can no longer consider returning a source PDF file, and can only consider a generated PDF.

However if the goal is instead to specifically get the original source file, then the CaptureDocumentService.GetSourceFile function can be used. 

Applies to:  

ProductVersion
KTAAll

Round off a number upto 2 decimal place using JavaScript

Tags

, ,

Round off a number upto 2 decimal place using JavaScript

A number can be rounded off to 2 decimal places using 2 approaches:

Method 1: Using the toFixed() method:
The toFixed() method is used to return a string representation of a number up to a certain number of digits after the decimal point. The number is rounded and the fractional part is padded if necessary to make it the specified length. It takes one parameter, that is the number of digits. This is an integer value between 0 to 20.

The toFixed() method is used with a value of 2 to round off a number upto 2 decimal places.

Syntax:

rounded_number = number.toFixed(2)

Example:

filter_noneedit

play_arrow

brightness_4

<!DOCTYPE html>
<html>
 
<head>
    <title>
      Round off a number upto 2 
      decimal place using JavaScript
  </title>
</head>
 
<body>
    <h1 style="color: green">
      GeeksforGeeks
  </h1>
    <b>Round off a number upto 2 
      decimal place using JavaScript
  </b>
    <p>Original floating point: 3.14159265359</p>
    <p>
      Rounding off to 2 decimal places: <span class="output">
      </span>
  </p>
 
    <button onclick="roundOff()">
      Round off to 2 places
  </button>
    <script type="text/javascript">
        function roundOff() {
            pi = 3.14159265359;
 
            twoPlaces = pi.toFixed(2);
 
            document.querySelector(
              '.output').textContent = twoPlaces;
        }
    </script>
</body>
 
</html>

Output:

  • Before clicking the button:
  • After clicking the button:

Method 2: Using the Math.round() method:
The Math.round() method is used to round a number its nearest integer value. It takes one parameter which is the number to be rounded.

The number is first multiplied by 100 to shift the decimal place so that it does not lose its value during the rounding off. The Math.round() method is applied to this number and the final result is divided by 100. This moves the decimal point back to its place as before. This number is the final rounded off number.

Syntax:

rounded_number = Math.round(number * 100) / 100

Example:

filter_noneedit

play_arrow

brightness_4

<!DOCTYPE html>
<html>
 
<head>
    <title>
      Round off a number upto 2
      decimal place using JavaScript
  </title>
</head>
 
<body>
    <h1 style="color: green">
      GeeksforGeeks
  </h1>
    <b>Round off a number upto 2 
      decimal place using JavaScript
  </b>
    <p>
      Original floating point: 3.14159265359
  </p>
    <p>Rounding off to 2 decimal places: <span class="output">
      </span>
  </p>
 
    <button onclick="roundOff()">
      Round off to 2 places
  </button>
    <script type="text/javascript">
        function roundOff() {
            pi = 3.14159265359;
 
            twoPlaces = 
              Math.round(pi * 100) / 100;
 
            document.querySelector(
              '.output').textContent = twoPlaces;
        }
    </script>
</body>
 
</html>

Output:

  • Before clicking the button:
  • After clicking the button:

 

https://www.geeksforgeeks.org/round-off-a-number-upto-2-decimal-place-using-javascript/

Oracle Date Query

Tags

, ,

 

Date Query sample

SELECT SYSDATE,
CAST(sys_extract_utc(systimestamp) as DATE) UTCDATE,
RTRIM( TO_CHAR( systimestamp AT TIME ZONE ‘Asia/Singapore’, ‘YYYY-MM-DD HH24:MI:SS’ )) CDATE
FROM DUAL

 

Time Zones
List of Time Zones set linesize 121
col tzname format a30
col tzabbrev format a30

SELECT *
FROM gv$timezone_names;

CURRENT_TIMESTAMP
Current Timestamp CURRENT_TIMESTAMP
SELECT CURRENT_TIMESTAMP FROM dual;
DBTIMEZONE
Current Time Zone DBTIMEZONE RETURN VARCHAR2;
ALTER SESSION SET time_zone = local;

SELECT DBTIMEZONE FROM dual;

SELECT CURRENT_TIMESTAMP FROM dual;

ALTER SESSION SET TIME_ZONE = '-5:0';

SELECT DBTIMEZONE FROM dual;

SELECT CURRENT_TIMESTAMP FROM dual;

ALTER SESSION SET time_zone = local;

SELECT systimestamp FROM dual;

SELECT systimestamp AT TIME ZONE dbtimezone FROM dual;

DUMP
Returns the number of bytes and datatype of a value DUMP(<value>)
SELECT DUMP(SYSTIMESTAMP) FROM dual;
EXTRACT
Extracts and returns the value of a specified datetime field from a datetime or interval value expression Values That Can Be Extracted:

YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
TIMEZONE_HOUR
TIMEZONE_MINUTE
TIMEZONE_REGION
TIMEZONE_ABBR

EXTRACT (<type> FROM <datetime | interval>)

SELECT EXTRACT(YEAR FROM DATE '2009-03-15') FROM dual;

conn oe/oe@pdbdev

SELECT EXTRACT(hour FROM order_date) "Hour"
FROM orders;

FROM_TZ
Converts a timestamp value at a time zone to a TIMESTAMP WITH TIME ZONE value FROM_TZ(t IN TIMESTAMP_UNCONSTRAINED, timezone IN VARCHAR2)
RETURN TIMESTAMP_TZ_UNCONSTRAINED;
SELECT FROM_TZ(TIMESTAMP '2019-03-15 08:00:00', '3:00')
FROM dual;

SELECT FROM_TZ(TIMESTAMP '2019-03-15 19:30:00', '3:00')
FROM dual;

GREATEST
Return the Latest Timestamp GREATEST(pattern IN TIME_UNCONSTRAINED) RETURN TIME_UNCONSTRAINED;
GREATEST(pattern IN TIME_TZ_UNCONSTRAINED) RETURN TIME_TZ_UNCONSTRAINED;
GREATEST(pattern IN TIMESTAMP_UNCONSTRAINED) RETURN TIMESTAMP_UNCONSTRAINED;
GREATEST(pattern IN TIMESTAMP_TZ_UNCONSTRAINED) RETURN TIMESTAMP_TZ_UNCONSTRAINED;
GREATEST(pattern IN TIMESTAMP_LTZ_UNCONSTRAINED) RETURN TIMESTAMP_LTZ_UNCONSTRAINED;
TBD
LEAST
Return the Earliest Timestamp LEAST(pattern IN TIME_UNCONSTRAINED) RETURN TIME_UNCONSTRAINED;
LEAST(pattern IN TIME_TZ_UNCONSTRAINED) RETURN TIME_TZ_UNCONSTRAINED;
LEAST(pattern IN TIMESTAMP_UNCONSTRAINED) RETURN TIMESTAMP_UNCONSTRAINED;
LEAST(pattern IN TIMESTAMP_TZ_UNCONSTRAINED) RETURN TIMESTAMP_TZ_UNCONSTRAINED;
LEAST(pattern IN TIMESTAMP_LTZ_UNCONSTRAINED) RETURN TIMESTAMP_LTZ_UNCONSTRAINED;
TBD
LOCALTIMESTAMP
Current date and time in the session time zone in a value of data type TIMESTAMP. The difference between this function and CURRENT_TIMESTAMP is that LOCALTIMESTAMP returns a TIMESTAMP value while CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value LOCALTIMESTAMP RETURN TIMESTAMP_UNCONSTRAINED;
ALTER SESSION SET TIME_ZONE = '-5:00';

SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM dual;

ALTER SESSION SET TIME_ZONE = '-8:00';

SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM dual;

CREATE TABLE local_test (col1 TIMESTAMP WITH LOCAL TIME ZONE);

-- the following statement fails because the mask does not include the TIME ZONE portion of the return type of the function
INSERT INTO local_test VALUES
(TO_TIMESTAMP(LOCALTIMESTAMP, 'DD-MON-RR HH.MI.SSXFF'));

-- the following statement uses the correct format mask to match the return type of LOCALTIMESTAMP
INSERT INTO local_test VALUES
(TO_TIMESTAMP(LOCALTIMESTAMP, 'DD-MON-RR HH.MI.SSXFF PM'));

SELECT * FROM local_test;

SESSIONTIMEZONE
Returns the value of the current session’s time zone SESSIONTIMEZONE RETURN VARCHAR2;
SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM dual;

ALTER SESSION SET TIME_ZONE = '-5:00';

ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM dual;

ALTER SESSION SET time_zone = local;

SYS_AT_TIMEZONE
Returns the Timestamp at the named timezone SYS_AT_TIME_ZONE(t time_tz_unconstrained, i VARCHAR2)
RETURN time_tz_unconstrained;

SYS_AT_TIME_ZONE(t timestamp_tz_unconstrained, i VARCHAR2)
RETURN timestamp_tz_unconstrained;

SELECT tzname FROM v$timezone_names;

SELECT STANDARD.SYS_AT_TIME_ZONE(SYSTIMESTAMP, 'US/Pacific')
FROM dual;

SELECT STANDARD.SYS_AT_TIME_ZONE(SYSTIMESTAMP, 'Asia/Singapore')
FROM dual;

SELECT STANDARD.SYS_AT_TIME_ZONE(SYSTIMESTAMP, 'Asia/Kuwait')
FROM dual;

SYS_EXTRACT_UTC
Returns Coordinated Universal Time (UTC, formerly Greenwich Mean Time) from a Timestamp SYS_EXTRACT_UTC(t IN TIMESTAMP_TZ_UNCONSTRAINED)
RETURN TIMESTAMP_UNCONSTRAINED;
SELECT SYS_EXTRACT_UTC(TIMESTAMP '2004-03-28 11:30:00.00 -08:00')
FROM dual;
SYSTIMESTAMP
Current Date Time as a Timestamp SYSTIMESTAMP RETURN TIMESTAMP_TZ_UNCONSTRAINED;
SELECT SYSTIMESTAMP FROM dual;

SELECT SYSTIMESTAMP AT TIME ZONE 'Japan' FROM dual;

TRUNC
Returns the date only TRUNC(<value>)
SELECT TO_CHAR(SYSTIMESTAMP) FROM dual;

SELECT TO_CHAR(TRUNC(SYSTIMESTAMP)) FROM dual;

TZ_OFFSET
Returns the Time Zone Offset TZ_OFFSET(region IN VARCHAR2) RETURN VARCHAR2;
SELECT TZ_OFFSET('US/Eastern') FROM dual;
Timestamp Data Type Demos
Timestamp (Without Time Zone) CREATE TABLE ts_test (
TIMESTAMP,
TIMESTAMP(0),
TIMESTAMP(9));

desc ts_test

INSERT INTO ts_test
(x, y, z)
VALUES
(timestamp'2007-08-08 09:00:00.123456789',
timestamp'2007-08-08 09:00:00.123456789',
timestamp'2007-08-08 09:00:00.123456789');

set linesize 121
col x format a30
col y format a21
col z format a31

SELECT * FROM ts_test;

INSERT INTO ts_test
(x, y, z)
VALUES
(localtimestamp, localtimestamp, localtimestamp);

SELECT * FROM ts_test;

SELECT VSIZE(x), VSIZE(y), VSIZE(z)
FROM ts_test;

Table With Time Zone CREATE TABLE tswtz_test (
msg VARCHAR2(40),
x   TIMESTAMP WITH TIME ZONE);

desc tswtz_test

ALTER SESSION SET TIME_ZONE = '-6:00';

col x foramt a35

INSERT INTO tswtz_test
(msg, x)
VALUES
('literal TS without TZ', timestamp'2004-08-08 09:00:00.123456789');

INSERT INTO tswtz_test
(msg, x)
VALUES
('SysTimeStamp (has TZ from DB)', systimestamp);

INSERT INTO tswtz_test
(msg, x)
VALUES
('LocalTimeStamp (has NO TZ)', LocalTimeStamp);

INSERT INTO tswtz_test
(msg, x)
VALUES
('Current_Timestamp (has TZ from client)', Current_Timestamp);

SELECT * FROM tswtz_test;

/* Lastly, notice the behavior of CURRENT_DATE and SYSDATE Current_Date is a lot like SYSDATE but is timezone sensitive. */

SELECT TO_CHAR(CURRENT_DATE, 'dd-mon-yyyy hh24:mi:ss'),
TO_CHAR(sysdate, 'dd-mon-yyyy hh24:mi:ss')
FROM dual;

ALTER SESSION SET time_zone = local;

SELECT TO_CHAR(CURRENT_DATE, 'dd-mon-yyyy hh24:mi:ss'),
TO_CHAR(sysdate, 'dd-mon-yyyy hh24:mi:ss')
FROM dual;

Extract Timestamp Components col TR format a10

SELECT
EXTRACT(year FROM systimestamp) EY,
EXTRACT(month FROM systimestamp) EM,
EXTRACT(day FROM systimestamp) ED,
EXTRACT(hour FROM systimestamp) EH,
EXTRACT(minute FROM systimestamp) EM,
EXTRACT(second FROM systimestamp) ES,
EXTRACT(timezone_hour FROM systimestamp) TH,
EXTRACT(timezone_minute FROM systimestamp) TM,
EXTRACT(timezone_region FROM systimestamp) TR,
EXTRACT(timezone_abbr FROM systimestamp) TA
FROM dual;

Extract Current Timestamp Components col TR format a10

SELECT
EXTRACT(year FROM current_timestamp) EY,
EXTRACT(month FROM current_timestamp) EM,
EXTRACT(day FROM current_timestamp) ED,
EXTRACT(hour FROM current_timestamp) EH,
EXTRACT(minute FROM current_timestamp) EM,
EXTRACT(second FROM current_timestamp) ES,
EXTRACT(timezone_hour FROM current_timestamp) TH,
EXTRACT(timezone_minute FROM current_timestamp) TM,
EXTRACT(timezone_region FROM current_timestamp) TR,
EXTRACT(timezone_abbr FROM current_timestamp) TA
FROM dual;

Extract Current Timestamp Components after altering the time zone col TR format a10

ALTER SESSION SET time_zone = 'US/Eastern';

SELECT
EXTRACT(year FROM current_timestamp) EY,
EXTRACT(month FROM current_timestamp) EM,
EXTRACT(day FROM current_timestamp) ED,
EXTRACT(hour FROM current_timestamp) EH,
EXTRACT(minute FROM current_timestamp) EM,
EXTRACT(second FROM current_timestamp) ES,
EXTRACT(timezone_hour FROM current_timestamp) TH,
EXTRACT(timezone_minute FROM current_timestamp) TM,
EXTRACT(timezone_region FROM current_timestamp) TR,
EXTRACT(timezone_abbr FROM current_timestamp ) TA
FROM dual;

set serveroutput on

DECLARE
t TIMESTAMP WITH TIME ZONE:=timestamp'2005-01-01 01:01:01 US/Pacific';
BEGIN
dbms_output.put_line(extract(timezone_abbr from t));
dbms_output.put_line(extract(timezone_region from t));
END;
/

ALTER SESSION SET time_zone = local;

Time Math
Time Math Demo SELECT current_timestamp + INTERVAL '5' year(1)
FROM dual;

SELECT current_timestamp + INTERVAL '10:30' MINUTE TO SECOND
FROM dual;

-- this will fail ... there is no Feb. 29th in 2010
SELECT timestamp'2011-02-29 00:00:00' + INTERVAL '1' year(1)
FROM dual;

SELECT timestamp'2011-02-28 00:00:00' + INTERVAL '1' year(1)
FROM dual;

SELECT add_months(timestamp'2012-02-29 00:00:00',12)
FROM dual;

-- math with intervals
SELECT a.duration_1 + b.duration_1 + c.duration_1
FROM tint_test a, tint_test b ,tint_test c
WHERE a.msg = 'my plane ride'
AND b.msg LIKE '%vacat%'
AND c.msg like '%life';

-- but not aggregations
SELECT SUM(duration_1)
FROM tint_test;

 

Timezone Lists:

A Time Zones

The following table contains a list of time zones supported by Oracle Real-Time Collaboration. See “Property to Configure Time Zones” for details about setting the default time zone for a Web Conferencing system.

Table A-1 Real-Time Collaboration Time Zones

Internal Name External User Visible Name
Pacific/Pago_Pago (-11:00) Pago Pago
Pacific/Honolulu (-10:00) Hawaii
America/Anchorage (-09:00) Alaska
America/Vancouver (-08:00) Canada Pacific Time
America/Los_Angeles (-08:00) US Pacific Time
America/Tijuana (-08:00) Tijuana
America/Edmonton (-07:00) Canada Mountain Time
America/Denver (-07:00) US Mountain Time
America/Phoenix (-07:00) Arizona
America/Mazatlan (-07:00) Mazatlan
America/Winnipeg (-06:00) Canada Central Time
America/Regina (-06:00) Saskatchewan
America/Chicago (-06:00) US Central Time
America/Mexico_City (-06:00) Mexico City
America/Guatemala (-06:00) Guatemala
America/El_Salvador (-06:00) El Salvador
America/Managua (-06:00) Managua
America/Costa_Rica (-06:00) Costa Rica
America/Montreal (-05:00) Canada Eastern Time
America/New_York (-05:00) US Eastern Time
America/Indianapolis (-05:00) East Indiana
America/Panama (-05:00) Panama
America/Bogota (-05:00) Bogota
America/Lima (-05:00) Lima
America/Halifax (-04:00) Canada Atlantic Time
America/Puerto_Rico (-04:00) Puerto Rico
America/Caracas (-04:00) Caracas
America/Santiago (-04:00) Santiago
America/St_Johns (-03:30) Newfoundland
America/Sao_Paulo (-03:00) Sao Paulo
Atlantic/Azores (-01:00) Azores
Etc./UTC (00:00) Universal Time
UTC (00:00) Universal Time
Atlantic/Reykjavik (00:00) Reykjavik
Europe/Dublin (00:00) Dublin
Europe/London (00:00) London
Europe/Lisbon (00:00) Lisbon
Africa/Casablanca (00:00) Casablanca
Africa/Nouakchott (00:00) Nouakchott
Europe/Oslo (+01:00) Oslo
Europe/Stockholm (+01:00) Stockholm
Europe/Copenhagen (+01:00) Copenhagen
Europe/Berlin (+01:00) Berlin
Europe/Amsterdam (+01:00) Amsterdam
Europe/Brussels (+01:00) Brussels
Europe/Luxembourg (+01:00) Luxembourg
Europe/Paris (+01:00) Paris
Europe/Zurich (+01:00) Zurich
Europe/Madrid (+01:00) Madrid
Europe/Rome (+01:00) Rome
Africa/Algiers (+01:00) Algiers
Africa/Tunis (+01:00) Tunis
Europe/Warsaw (+01:00) Warsaw
Europe/Prague (+01:00) Prague Bratislava
Europe/Vienna (+01:00) Vienna
Europe/Budapest (+01:00) Budapest
Europe/Sofia (+02:00) Sofia
Europe/Istanbul (+02:00) Istanbul
Europe/Athens (+02:00) Athens
Asia/Nicosia (+02:00) Nicosia
Asia/Beirut (+02:00) Beirut
Asia/Damascus (+02:00) Damascus
Asia/Jerusalem (+02:00) Jerusalem
Asia/Amman (+02:00) Amman
Africa/Tripoli (+02:00) Tripoli
Africa/Cairo (+02:00) Cairo
Africa/Johannesburg (+02:00) Johannesburg
Europe/Moscow (+03:00) Moscow
Asia/Baghdad (+03:00) Baghdad
Asia/Kuwait (+03:00) Kuwait
Asia/Riyadh (+03:00) Riyadh
Asia/Bahrain (+03:00) Bahrain
Asia/Qatar (+03:00) Qatar
Asia/Aden (+03:00) Aden
Africa/Khartoum (+03:00) Khartoum
Africa/Djibouti (+03:00) Djibouti
Africa/Mogadishu (+03:00) Mogadishu
Asia/Dubai (+04:00) Dubai
Asia/Muscat (+04:00) Muscat
Asia/Yekaterinburg (+05:00) Yekaterinburg
Asia/Tashkent (+05:00) Tashkent
Asia/Calcutta (+05:30) India
Asia/Novosibirsk (+06:00) Novosibirsk
Asia/Almaty (+06:00) Almaty
Asia/Dacca (+06:00) Dacca
Asia/Krasnoyarsk (+07:00) Krasnoyarsk
Asia/Bangkok (+07:00) Bangkok
Asia/Saigon (+07:00) Vietnam
Asia/Jakarta (+07:00) Jakarta
Asia/Irkutsk (+08:00) Irkutsk
Asia/Shanghai (+08:00) Beijing, Shanghai
Asia/Hong_Kong (+08:00) Hong Kong
Asia/Taipei (+08:00) Taipei
Asia/Kuala_Lumpur (+08:00) Kuala Lumpur
Asia/Singapore (+08:00) Singapore
Australia/Perth (+08:00) Perth
Asia/Yakutsk (+09:00) Yakutsk
Asia/Seoul (+09:00) Seoul
Asia/Tokyo (+09:00) Tokyo
Australia/Darwin (+09:30) Darwin
Australia/Adelaide (+09:30) Adelaide
Asia/Vladivostok (+10:00) Vladivostok
Australia/Brisbane (+10:00) Brisbane
Australia/Sydney (+10:00) Sydney Canberra
Australia/Hobart (+10:00) Hobart
Asia/Magadan (+11:00) Magadan
Asia/Kamchatka (+12:00) Kamchatka
Pacific/Auckland (+12:00) Auckland

 

 

In this article, we’ll look at the FROM_TZ, TZ_OFFSET, TO_TIMESTAMP_TZ, and NEW_TIME functions in Oracle, explain how they work, and see some examples.

There are several timezone-related functions in Oracle, which I have described in this article.

 

Purpose of the Oracle Timezone Functions

FROM_TZ

The purpose of the FROM_TZ function is to convert a TIMESTAMP value and a specified TIME ZONE to a TIMESTAMP WITH TIME ZONE value.

It seems like a simple data conversion function, but it’s a good one to know, especially if you work with dates and timestamps a lot.

TZ_OFFSET

The purpose of the TZ_OFFSET function is to display a number that indicates the number of hours from UTC that a specified time is.

You can specify a few different parameters, which I’ll explain shortly.

TO_TIMESTAMP_TZ

The purpose of the TO_TIMESTAMP_TZ function is to convert a STRING into a TIMESTAMP WITH TIME ZONE data type. It’s similar to the TO_TIMESTAMP function.

What is a TIMESTAMP WITH TIME ZONE data type?

Well, it’s a type of DATE which has a few components:

  • A date (day, month, and year)
  • A time (hours, minutes, and seconds)
  • A time zone (number of hours and minutes difference from GMT)

Because there is a need in many systems to store timezone information, Oracle has provided this data type. The timezone part is represented as a time value (hours and minutes) that is the number of hours and minutes before or after GMT.

So, “+7:00” is 7 hours after GMT (Bangkok time) and “-5:00” is 5 hours before GMT (US Eastern Time).

Understanding the TIMESTAMP WITH TIME ZONE data type is the hard part. Converting a string to this data type is pretty simple once you understand the data type.

NEW_TIME

The NEW_TIME function converts a date from one timezone to another timezone.

Get Your SQL Cheat Sheet

Three pages of SQL commands to save/print for easy reference

GET MY CHEAT SHEET

 

Oracle FROM_TZ Function Syntax and Parameters

The syntax of the FROM_TZ function is:

FROM_TZ ( timestamp_value, timezone_value )

The parameters of the FROM_TZ function are:

  • timestamp_value (mandatory): This is the timestamp value that will be converted.
  • timezone_value (mandatory): This is the timezone that the timestamp will be converted in to.

The return type of the FROM_TZ function is a TIMESTAMP WITH TIME ZONE type.

 

Oracle TZ_OFFSET Syntax and Parameters

The syntax of the TZ_OFFSET function is:

TZ_OFFSET ( timezone_name | time_value | SESSIONTIMEZONE | DBTIMEZONE )

This function has one parameter, but you can specify different values for the parameter.

The parameters of the Oracle TZ_OFFSET function are:

  • timezone_name (optional): This is the name of the timezone to use (e.g. US/Eastern). See the section below on how to get a list of valid timezones.
  • time_value (optional): You can enter an offset value from UTC, which will simply return itself. It can be entered in the format of ‘+/- hh:mm’.
  • SESSIONTIMEZONE (optional): You can pass the SESSIONTIMEZONE function as a parameter to get the timezone offset of the current session.
  • DBTIMEZONE (optional): You can pass the DBTIMEZONE function as a parameter to get the timezone offset of the database.

 

Oracle TO_TIMESTAMP Function Syntax and Parameters

The syntax of the Oracle TO_TIMESTAMP_TZ is:

TO_TIMESTAMP_TZ ( input_string [, format_mask] [, nls_param] )

The parameters of the TO_TIMESTAMP_TZ function are:

  • input_string (mandatory): This is the string that is to be converted to the TIMESTAMP WITH TIME ZONE data type.
  • format_mask (optional): This is the format of the input_string, as the input_string can be in many different formats. If this is not supplied, then the input_string must be in the same format as the default TIMESTAMP WITH TIME ZONE data type.
  • nlsparam (optional): If this string is supplied, you can specify the language in which the month and day names and abbreviations are returned.

Some more notes on this function:

  • The input type can be any of CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
  • The return type is TIMESTAMP WITH TIME ZONE.

 

Oracle NEW_TIME Function Syntax and Parameters

The syntax of the NEW_TIME function is:

NEW_TIME ( input_date, timezone1, timezone2 )

The parameters of the NEW_TIME function are:

  • input_date (mandatory): The date, including time, that is to be converted.
  • timezone1 (mandatory): The timezone of the specified input_date value.
  • timezone2 (mandatory): The timezone to convert the input_date to.

The return type is always DATE.

 

What is the FROM_TZ Timezone List?

There is a range of values you can set for the TIMEZONE parameter of the FROM_TZ function.

You can find a list of valid time zone names by querying the V$TIMEZONE_NAMES view.

SELECT * FROM V$TIMEZONE_NAMES;
TZNAME TZABBREV
Africa/Abidjan LMT
Africa/Abidjan GMT
Africa/Accra LMT
Africa/Accra GMT
Africa/Accra GHST
Africa/Addis_Ababa LMT

 

What are the Valid Timezone Names in Oracle?

To get a list of all of the valid timezone names in an Oracle database, you can query the V$TIMEZONE_NAMES view.

SELECT * FROM V$TIMEZONE_NAMES;
TZNAME TZABBREV
Africa/Abidjan LMT
Africa/Abidjan GMT
Africa/Accra LMT
Africa/Accra GMT
Africa/Accra GHST
Africa/Addis_Ababa LMT

 

How Can I Use Oracle TZ_OFFSET with Daylight Saving?

To use daylight savings with TZ_OFFSET, you need t o specify the timezone name when using this function.

Oracle has knowledge of what timezones map to what timezone offsets. So, to use daylight savings with this function, you need to specify a daylight savings timezone.

For example, the timezone name of ‘US/Eastern EDT’ relates to Daylight Savings time in US East, and ‘US/Eastern’ or ‘US/Easter EST’ relates to standard time in US East.

 

Can I Convert TZ_OFFSET to a Number?

Yes, you can, using a series of SIGN and SUBSTR functions.

 

What Is The Default Oracle TO_TIMESTAMP_TZ Format?

I mentioned earlier that the format_mask is optional. If you don’t supply it, you must specify the input_string in the default TIMESTAMP WITH TIME ZONE format.

But what is that format?

You can find it by looking at the NLS_DATABASE_PARAMETERS view, for the parameter “NLS_TIMESTAMP_TZ_FORMAT”

SELECT *
FROM NLS_DATABASE_PARAMETERS
WHERE PARAMETER = 'NLS_TIMESTAMP_TZ_FORMAT';

Result:

PARAMETER VALUE
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR

As you can see, the default value for TIMESTAMP WITH TIME ZONE is shown there. If you omit the format_mask, this is the format you must specify the input_string in.

 

What Formats Can I Use For The TO_TIMESTAMP_TZ Function?

Just like with many other Oracle functions, you can use the standard format identifiers.

Parameter Explanation
YYYY Four digit year
MM Month (01-12, where JAN = 01)
MON Abbreviated name of month
MONTH Name of month, padded with blanks to length of 9 characters
DD Day of month (1-31)
HH Hour of day (1-12)
HH12 Hour of day (1-12)
HH24 Hour of day (0-23)
MI Minute (0-59)
SS Second (0-59)

 

NEW_TIME Timezone Values

The NEW_TIME function can only take a limited range of timezones as inputs.

If you want to use more time zones, you can combine the FROM_TZ function and a date value (such as input_date or another date).

The timezone1 and timezone2 parameters can be any of these values:

  • AST, ADT: Atlantic Standard or Daylight Time
  • BST, BDT: Bering Standard or Daylight Time
  • CST, CDT: Central Standard or Daylight Time
  • EST, EDT: Eastern Standard or Daylight Time
  • GMT: Greenwich Mean Time
  • HST, HDT: Alaska-Hawaii Standard Time or Daylight Time.
  • MST, MDT: Mountain Standard or Daylight Time
  • NST: Newfoundland Standard Time
  • PST, PDT: Pacific Standard or Daylight Time
  • YST, YDT: Yukon Standard or Daylight Time

 

Examples of the FROM_TZ Function

Here are some examples of the FROM_TZ function. I find that examples are the best way for me to learn about code, even with the explanation above.

 

Example 1

This is a simple example of the FROM_TZ function.

SELECT
FROM_TZ(TIMESTAMP '2016-07-13 19:20:14', '02:00') AS tz_test
FROM dual;

Result:

TZ_TEST
13-JUL-16 07.20.14.000000000 PM +02:00

This result shows the same date and time, but includes the time zone, as it’s a TIMESTAMP WITH TIME ZONE data type.

 

Example 2

SELECT
FROM_TZ(TIMESTAMP '2016-07-13 04:06:55', '-11:00') AS tz_test
FROM dual;

Result:

TZ_TEST
13-JUL-16 04.06.55.000000000 AM -11:00

 

Examples of the TZ_OFFSET Function

Here are some examples of the TZ_OFFSET function. I find that examples are the best way for me to learn about code, even with the explanation above.

 

Example 1 – Timezone Name

This example uses a timezone name as the parameter.

SELECT
TZ_OFFSET('US/Eastern') AS tz_test
FROM dual;

Result:

TZ_TEST
-04:00

 

Example 2 – Hours and Minutes

This example uses an hours and minutes value as the input.

SELECT
TZ_OFFSET('-02:00') AS tz_test
FROM dual;

Result:

TZ_TEST
-02:00

 

Example 3 – SESSIONTIMEZONE

This example uses the SESSIONTIMEZONE function as a parameter.

SELECT
TZ_OFFSET(SESSIONTIMEZONE) AS tz_test
FROM dual;

Result:

TZ_TEST
+10:00

 

Example 4 – DBTIMEZONE

This example uses the DBTIMEZONE function as a parameter.

SELECT
TZ_OFFSET(DBTIMEZONE) AS tz_test
FROM dual;

Result:

TZ_TEST
+0:00

 

Example 5 – Convert to Number

This example shows the session time zone, as well as the session time zone converted to a number using TO_NUMBER.

SELECT
TZ_OFFSET(SESSIONTIMEZONE) AS tz_test,
SIGN(TO_NUMBER(SUBSTR(TZ_OFFSET(SESSIONTIMEZONE), 1, 3))) * (
  TO_NUMBER(SUBSTR(TZ_OFFSET(SESSIONTIMEZONE), 2, 2)) +
  TO_NUMBER(SUBSTR(TZ_OFFSET(SESSIONTIMEZONE), 5, 2)) / 60
) AS tz_offset_num
FROM dual;

Result:

TZ_TEST TZ_OFFSET_NUM
+10:00 10

 

 

Examples of the TO_TIMESTAMP_TZ Function

Here are some examples of the TO_TIMESTAMP_TZ function. I find that examples are the best way for me to learn about code, even with the explanation above.

 

Example 1

This example uses the default TIMESTAMP WITH TIME ZONE format, as I have not supplied a format_mask.

SELECT
TO_TIMESTAMP_TZ('8-DEC-15 10:04:01 AM +2:00') AS TS_TEST
FROM dual;

Result:

TS_TEST
08-DEC-15 10.04.01.000000000 AM +02:00

As you can see, the data looks the same, but it will be stored as a different data type. It follows the default pattern, which is “DD-MON-RR HH.MI.SSXFF AM TZR”.

 

Example 2

This example uses a timezone which is later than GMT.

SELECT
TO_TIMESTAMP_TZ('8-DEC-2015 02:44 AM +6:00', 'DD-MON-YYYY HH:MI AM TZH:TZM') AS TS_TEST
FROM dual;

Result:

TS_TEST
08-DEC-15 02.44.00.000000000 AM +06:00

The data is stored in a timezone that is +6 hours.

 

Example 3

This example uses a timezone which is earlier than GMT.

SELECT
TO_TIMESTAMP_TZ('12-DEC-2015 6:51 PM -11:00', 'DD-MON-YYYY HH:MI AM TZH:TZM') AS TS_TEST
FROM dual;

Result:

TS_TEST
12-DEC-15 06.51.00.000000000 PM -11:00

The data is stored in a timezone that is -11 hours.

 

Examples of the NEW_TIME Function

Here are some examples of the NEW_TIME function. I find that examples are the best way for me to learn about code, even with the explanation above.

 

Example 1 – Using SYSDATE

In this example, I’ve used the SYSDATE function and converted it to a different timezone.

SELECT SYSDATE,
NEW_TIME(SYSDATE, 'GMT', 'PST') AS newtime_test
FROM dual;

Result:

SYSDATE NEWTIME_TEST
21/SEP/16 20/SEP/16

You can see here that both of the outputs are dates only, no time. This is because of my default output settings, and because I haven’t changed the output using a function such as TO_CHAR.

Example 2 – Using SYSTIMESTAMP

Let’s try another example using SYSTIMESTAMP instead of SYSDATE

SELECT
SYSTIMESTAMP,
NEW_TIME(SYSTIMESTAMP, 'GMT', 'PST') AS newtime_test
FROM dual;

Result:

SYSTIMESTAMP NEWTIME_TEST
21/SEP/16 05:09:25.300000000 AM +10:00 20/SEP/16

This example shows SYSTIMESTAMP showing date and time, but NEW_TIME does not.

Example 3 – Formatting Output

Let’s try using NEW_TIME again, but formatting the output.

SELECT

SYSTIMESTAMP,
TO_CHAR(NEW_TIME(SYSTIMESTAMP, ‘GMT’, ‘PST’), ‘dd-mm-yy hh:mi:ss AM’) AS newtime_test
FROM dual;
Result:

SYSDATE NEWTIME_TEST
21/SEP/16 05:09:55.610000000 AM +10:00 20-09-16 09:09:55 PM

As you can see, the times are different. The GMT time is showing as 5AM, and the time converted to PST is 9PM. This is an 8 hour difference.

Similar Functions

Some functions which are similar to these timezone functions are:

  • TO_TIMESTAMP: This function converts a string into a TIMESTAMP data type, which is similar, but has no time zone information.
  • TO_DATE: This function converts a string into a date data type.

You can find a full list of Oracle SQL functions here.

How to export/import PuTTy sessions list?

Tags

, , ,

 

Export

cmd.exerequire elevated prompt:

Only sessions:

regedit /e "%USERPROFILE%\Desktop\putty-sessions.reg" HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

All settings:

regedit /e "%USERPROFILE%\Desktop\putty.reg" HKEY_CURRENT_USER\Software\SimonTatham

Powershell:

Only sessions:

reg export HKCU\Software\SimonTatham\PuTTY\Sessions ([Environment]::GetFolderPath("Desktop") + "\putty-sessions.reg")

All settings:

reg export HKCU\Software\SimonTatham ([Environment]::GetFolderPath("Desktop") + "\putty.reg")

Import

Double-click on the *.reg file and accept the import.

Alternative ways:

cmd.exerequire elevated command prompt:

regedit /i putty-sessions.reg
regedit /i putty.reg

PowerShell:

reg import putty-sessions.reg
reg import putty.reg

Notedo not replace SimonTatham with your username.

Note: It will create a reg file on the Desktop of the current user.

Note: It will not export related SSH keys.

 

Oracle XML Functions

Tags

, , ,

Oracle XML Functions (Version 11.1)

All Oracle functions http://psoug.org/reference/builtin_functions.html
APPENDCHILDXML
Note: Run these demos top to bottom without using COMMIT or ROLLBACK.

Appends a user-supplied value onto the target XML as the child of the node indicated by an XPath expression
APPENDCHILDXML(XMLType_Instance>, <XPath_string>,
<value_expression>, <namespace_string>)
conn oe/oe

UPDATE warehouses
SET warehouse_spec = APPENDCHILDXML(warehouse_spec,
‘Warehouse/Building’, XMLType(‘<Owner>Grandco</Owner>’))
WHERE EXTRACTVALUE(warehouse_spec, ‘/Warehouse/Building’) = ‘Rented’;

col “Prop.Owner” format a30

SELECT warehouse_id, warehouse_name,
EXTRACTVALUE(warehouse_spec, ‘/Warehouse/Building/Owner’) “Prop.Owner”
FROM warehouses
WHERE EXISTSNODE(warehouse_spec, ‘/Warehouse/Building/Owner’) = 1;

DELETEXML

Deletes the node or nodes matched by the XPath expression in the target XML
DELETEXML(XMLType_Instance>, <XPath_string>, <namespace_string>)
— must follow APPENDCHILDXML demo (above)

SELECT warehouse_id, warehouse_spec
FROM warehouses
WHERE warehouse_id IN (2,3);

UPDATE warehouses
SET warehouse_spec=DELETEXML(warehouse_spec,’/Warehouse/Building/Owner’)
WHERE warehouse_id = 2;

col warehouse_spec format a60

SELECT warehouse_id, warehouse_spec
FROM warehouses
WHERE warehouse_id IN (2,3);

DEPTH
Returns the number of levels in the path specified by the UNDER_PATH condition with the same correlation variable DEPTH(correlation_integer)
conn oe/oe

SELECT PATH(1), DEPTH(2)
FROM RESOURCE_VIEW
WHERE UNDER_PATH(res, ‘/sys/schemas/OE’, 1)=1
AND UNDER_PATH(res, ‘/sys/schemas/OE’, 2)=1;

EXISTSNODE
Determines whether traversal of an XML document using a specified path results in any nodes EXISTSNODE(XMLType_Instance>, <XPath_string>, <namespace_string>)
conn oe/oe

SELECT warehouse_id, warehouse_name
FROM warehouses
WHERE EXISTSNODE(warehouse_spec, ‘/Warehouse/Docks’) = 1;

EXTRACT
Applies a VARCHAR2XPath string and returns an XMLType instance containing an XML fragment EXTRACT(XMLType_Instance>, <XPath_string>, <namespace_string>)
conn oe/oe

col “Number of Docks” format a30

SELECT warehouse_name,
EXTRACT
(warehouse_spec, ‘/Warehouse/Docks’) “Number of Docks”
FROM warehouses
WHERE warehouse_spec IS NOT NULL;


Demo using the capability in a non-XML environment
rollback;

conn uwclass/uwclass

CREATE TABLE t(
line  NUMBER(3),
site  VARCHAR2(4),
phase VARCHAR2(5),
test  VARCHAR2(25));

INSERT INTO t VALUES (1, ‘0100’, ‘*’,’1111111111111111111111111′ );
INSERT INTO t VALUES (2, ‘0100’, ‘=’,’2222222222222222222222222′ );
INSERT INTO t VALUES (3, ‘0100’, ‘=’,’3333333333333333333333333′ );
INSERT INTO t VALUES (4, ‘0100’, ‘*’,’4444444444444444444444444′ );
INSERT INTO t VALUES (5, ‘0100’, ‘=’,’5555555555555555555555555′ );
INSERT INTO t VALUES (6, ‘0200’, ‘*’,’6666666666666666666666666′ );

col text format a75

SELECT group_key AS “Line#”, site, EXTRACT(XMLAGG(xmlelement(“V”, test)), ‘/V/text()’) AS text
FROM (
SELECT line, site, SUM(to_number(TRANSLATE(phase, ‘*=’, ’10’)))
OVER (ORDER BY line) AS group_key, test
FROM t)
GROUP BY site, group_key;

EXTRACTVALUE
Takes as arguments an XMLType instance and an XPath expression and returns a scalar value of the resultant node EXTRACTVALUE(XMLType_Instance>, <XPath_string>, <namespace_string>)
conn oe/oe

col docks format a30

SELECT warehouse_name,
EXTRACTVALUE(e.warehouse_spec, ‘/Warehouse/Docks’) “Docks”
FROM warehouses e
WHERE warehouse_spec IS NOT NULL;

INSERTCHILDXML

Inserts a user-supplied value into the target XML at the node indicated by the XPath expression
INSERTCHILDXML(XMLType_Instance>, <XPath_string>,
<child_expression>, <value_expression>, <namespace_string>)
conn oe/oe

set long 1000000

SELECT warehouse_spec
FROM warehouses
WHERE warehouse_id = 3;

UPDATE warehouses
SET warehouse_spec = INSERTCHILDXML(warehouse_spec,
‘/Warehouse/Building’, ‘Owner’, XMLType(‘<Owner>LesserCo</Owner>’))
WHERE warehouse_id = 3;

SELECT warehouse_spec
FROM warehouses
WHERE warehouse_id = 3;

INSERTXMLBEFORE

Inserts a user-supplied value into the target XML before the node indicated by the XPath expression
INSERTXMLBEFORE(XMLType_Instance>, <XPath_string>,
<value_expression>, <namespace_string>)
conn oe/oe

SELECT warehouse_name, EXTRACT(warehouse_spec,
‘/Warehouse/Building/Owner’) “Owners”
FROM warehouses
WHERE warehouse_id = 3;

UPDATE warehouses
SET warehouse_spec = INSERTXMLBEFORE(warehouse_spec,
‘/Warehouse/Building/Owner[2]’,
XMLType(‘<Owner>ThirdOwner</Owner>’))
WHERE warehouse_id = 3;

SELECT warehouse_name, EXTRACT(warehouse_spec,
‘/Warehouse/Building/Owner’) “Owners”
FROM warehouses
WHERE warehouse_id = 3;

PATH
Returns the relative path that leads to the resource specified in the parent condition. PATH(<correlation_integer>)
See the main CONNECT_BY page or the CONNECT_BY definition page.
SYS_DBURIGEN
Generates a URL of datatype DBURIType to a particular column or row object SYS_DBURIGEN(<column_or_attribute | rowid>, <‘text()>’);
conn oe/oe

SELECT SYS_DBURIGEN(employee_id, email)
FROM employees
WHERE employee_id = 206;

SYS_XMLAGG
Aggregates all of the XML documents or fragments represented by expr and produces a single XML document. It adds a new enclosing element with a default name ROWSET SYS_XMLAGG(<expression>, <format>)
conn oe/oe

SELECT SYS_XMLAGG(SYS_XMLGEN(last_name))
FROM employees
WHERE last_name LIKE ‘R%’;

SYS_XMLGEN
Takes an expression that evaluates to a particular row and column of the database, and returns an instance of type XMLType containing an XML document SYS_XMLGEN(<expression>, <format>)
conn oe/oe

SELECT SYS_XMLGEN(email)
FROM employees
WHERE employee_id = 205;

UPDATEXML

Takes as arguments an XMLType instance and an XPath-value pair and returns an XMLType instance with the updated value
UPDATEXML(XMLType_Instance>, <XPath_string>,
<value_expression>, <namespace_string>)
conn oe/oe

SELECT warehouse_name,
EXTRACT(warehouse_spec, ‘/Warehouse/Docks’) “Number of Docks”
FROM warehouses
WHERE warehouse_name = ‘San Francisco’;

UPDATE warehouses
SET warehouse_spec = UPDATEXML(warehouse_spec,
‘/Warehouse/Docks/text()’,4)
WHERE warehouse_name = ‘San Francisco’;

SELECT warehouse_name,
EXTRACT(warehouse_spec, ‘/Warehouse/Docks’) “Number of Docks”
FROM warehouses
WHERE warehouse_name = ‘San Francisco’;

XMLAGG

Takes a collection of XML fragments and returns an aggregated XML document. Any arguments that return null are dropped from the result
XMLAGG(XMLType_Instance> <ORDER BY CLAUSE>)
conn oe/oe

set long 100000

SELECT XMLELEMENT(“Department”, XMLAGG(XMLELEMENT(“Employee”,
e.job_id||’ ‘||e.last_name) ORDER BY last_name)) AS “Dept_list”
FROM employees e
WHERE e.department_id = 30;

XMLCAST (new in 11g)
XMLCast casts value_expression to the scalar SQL datatype specified by datatype. XMLCAST(<value_expression> AS <data_type>)
TBD
XMLCDATA

Generates a CDATA section by evaluating value_expr
XMLCDATA(<value_expression>)
conn oe/oe

SELECT XMLELEMENT(“PurchaseOrder”,
XMLAttributes(dummy AS “pono”),
XMLCdata(‘<!DOCTYPE po_dom_group [
<!ELEMENT po_dom_group(student_name)*>
<!ELEMENT po_purch_name (#PCDATA)>
<!ATTLIST po_name po_no ID #REQUIRED>
<!ATTLIST po_name trust_1 IDREF #IMPLIED>
<!ATTLIST po_name trust_2 IDREF #IMPLIED>
]>’)) “XMLCData”
FROM DUAL;

XMLCOLATTVAL
Creates an XML fragment and then expands the resulting XML so that each XML fragment has the name column with the attribute name XMLCOLATTVAL(<value_expression> AS c_alias)
conn oe/oe

SELECT XMLELEMENT(“Emp”,
XMLCOLATTVAL(e.employee_id, e.last_name, e.salary)) “Emp Element”
FROM employees e
WHERE employee_id = 204;

XMLCOMMENT
Generates an XML comment using an evaluated result of value_expr XMLCOMMENT(<value_expression>)
conn oe/oe

SELECT XMLCOMMENT(‘OrderAnalysisComp imported, reconfigured, disassembled’) AS “XMLCOMMENT”
FROM DUAL;

XMLCONCAT
Takes as input a series of XMLType instances, concatenates the series of elements for each row, and returns the concatenated series XMLCONCAT(<XMLType_instance>)
conn oe/oe

SELECT XMLCONCAT(XMLELEMENT(“First”, e.first_name),
XMLELEMENT(“Last”, e.last_name)) AS “Result”
FROM employees e
WHERE e.employee_id > 202;

XMLDIFF

The XMLDiff function is the SQL interface for the XmlDiff C API.
XMLDIFF(XMLType_document, XMLType_document, <integer>, <string>)
SELECT XMLDIFF(
XMLTYPE(‘<?xml version=”1.0″
<bk:book xmlns:bk=”http://nosuchsite.com”&gt;
<bk:tr>
<bk:td>
<bk:chapter>
Chapter 1.
</bk:chapter>
</bk:td>
<bk:td>
<bk:chapter>
Chapter 2.
</bk:chapter>
</bk:td>
</bk:tr>
</bk:book>’),
XMLTYPE(‘<?xml version=”1.0″
<bk:book xmlns:bk=”http://nosuchsite.com”&gt;
<bk:tr>
<bk:td>
<bk:chapter>
Chapter 1.
</bk:chapter>
</bk:td>
<bk:td/>
</bk:tr>
</bk:book>’))
FROM DUAL;
XMLELEMENT (missed earlier)
XMLElement takes an element name for identifier or evaluates an element name for EVALNAME value_expr, an optional collection of attributes for the element, and arguments that make up the content of the element. XMLELEMENT(
SELECT XMLELEMENT(“Emp”, XMLELEMENT(“Name”, e.job_id||’ ‘||e.last_name),
XMLELEMENT(“Hiredate”, e.hire_date)) AS “Result”
FROM employees e
WHERE employee_id > 200;
XMLEXISTS (new in 11g)
XMLExists checks whether a given XQuery expression returns a nonempty XQuery sequence. If so, the function returns TRUE; otherwise, it returns FALSE. XMLEXISTS(XQuery_string PASSING [BY VALUE] expression [AS IDENTIFIER])
TBD
XMLFOREST
Converts each of its argument parameters to XML, and then returns an XML fragment that is the concatenation of these converted arguments XMLFOREST(<value_expression> AS c_alias)
conn oe/oe

SELECT XMLELEMENT(“Emp”, XMLFOREST(e.employee_id, e.last_name, e.salary)) “Emp Element”
FROM employees e
WHERE employee_id = 204;

XMLISVALID
Checks if the input instance conforms to a specified XML schema. It does not change the validation status of the XML instance. If any argument is  NULL, the result is NULL. If validation fails, then 0 is returned. XMLIsValid(XMLType_inst [, schemaurl [, elem]])
CREATE TABLE po_tab OF XMLTYPE (CHECK (XMLIsValid(object_value) = 1))
XMLSchema “http://www.example.com/schemas/ipo.xsd&#8221; ELEMENT “purchaseOrder”;
XMLPARSE
Parses and generates an XML instance from the evaluated result of value_expr XMLPARSE(<document | content> <value_expression> [WELLFORMED])
conn oe/oe

SELECT XMLPARSE(CONTENT ‘124 <purchaseOrder poNo=”12435″>
<customerName> Acme Enterprises</customerName>
<itemNo>32987457</itemNo> </purchaseOrder>’ WELLFORMED) AS PO
FROM DUAL;

XMLPATCH (new in 11g)

The XMLPatch function is the SQL interface for the XmlPatch C API. This function patches an XML document with the changes specified. The patched XMLType document is returned.
XMLPATCH(XMLType_document, XMLType_document)
SELECT XMLPATCH(
XMLTYPE(‘<?xml version=”1.0″
<bk:book xmlns:bk=”http://nosuchsite.com”&gt;
<bk:tr>
<bk:td>
<bk:chapter>
Chapter 1.
</bk:chapter>
</bk:td>
<bk:td>
<bk:chapter>
Chapter 2.
</bk:chapter>
</bk:td>
</bk:tr>
</bk:book>’)
,
XMLTYPE(‘<?xml version=”1.0″
<xd:xdiff xsi:schemaLocation=”http://xmlns.oracle.com/xdb/xdiff.xsd
http://xmlns.oracle.com/xdb/xdiff.xsd&#8221;
xmlns:xd=”http://xmlns.oracle.com/xdb/xdiff.xsd&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xmlns:bk=”http://nosuchsite.com”&gt;
<?oracle-xmldiff operations-in-docorder=”true” output-model=”snapshot”
diff-algorithm=”global”
<xd:delete-node xd:node-type=”element”
xd:xpath=”/bk:book[1]/bk:tr[1]/bk:td[2]/bk:chapter[1]”/>
</xd:xdiff>’)
)
FROM DUAL;
XMLPI
Generates an XML processing instruction using identifier and optionally the evaluated result of value_expr XMLPI(<name> <identifier>, <value_expression>)
conn oe/oe

SELECT XMLPI(NAME “Order analysisComp”, ‘imported, reconfigured, disassembled’) AS “XMLPI”
FROM DUAL;

XMLQUERY
See XMLQuery Web Page
XMLROOT
Create a new XML value by providing version and standalone properties in the XML root information (prolog) of an existing XML value XMLROOT(<value_expression>, VERSION <value_expression | NO VALUE>,
[STANDALONE <YES | NO | NO VALUE>])
conn oe/oe

SELECT XMLROOT(XMLType(‘<poid>143598</poid>’), VERSION ‘1.0’,STANDALONE YESAS “XMLROOT”
FROM DUAL;

XMLSEQUENCE
Takes as input an XMLType instance and returns a varray of the top-level nodes in the XMLType. XMLSEQUENCE(<XMLType_Instance>)
conn oe/oe

SELECT EXTRACT(warehouse_spec, ‘/Warehouse’) AS “Warehouse”
FROM warehouses
WHERE warehouse_name = ‘San Francisco’;

SELECT VALUE(p)
FROM warehouses w,
TABLE(XMLSEQUENCE(EXTRACT(warehouse_spec, ‘/Warehouse/*’))) p
WHERE w.warehouse_name = ‘San Francisco’;

Takes as input a REFCURSOR instance, with an optional instance of the XMLFormat object, and returns as an XMLSequence type an XML document for each row of the cursor XMLSEQUENCE(<sys_refcursor_instance, format>)
TBD
XMLSERIALIZE
Creates a string or LOB containing the contents of value_expr. XMLSERIALIZE(<DOCUMENT | CONTENT> <value_expression> AS <datatype>)
conn oe/oe

SELECT XMLSERIALIZE(CONTENT XMLTYPE(‘<Owner>Grandco</Owner>’))
FROM DUAL;

XMLTABLE
See XMLTABLE Web Page
XMLTRANSFORM

Takes as arguments an XMLType instance and an XSL style sheet, which is itself a form of XMLType instance. It applies the style sheet to the instance and returns an XMLType.
XMLTRANSFORM(<XMLType_instance>, <XMLType_instance)
— do not run this demo as part of the OE series as the implicit commit
— in CREATE TABLE will change your OE schema permanently.

conn oe/oe

CREATE TABLE xsl_tab (col1 XMLTYPE);

INSERT INTO xsl_tab
VALUES (
XMLTYPE.createxml(‘<?xml version=”1.0″ <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:output encoding=”utf-8″/> <!– alphabetizes an xml tree –>
<xsl:template match=”*”> <xsl:copy>
<xsl:apply-templates select=”*|text()”>
<xsl:sort select=”name(.)” data-type=”text” order=”ascending”/>
</xsl:apply-templates> </xsl:copy> </xsl:template>
<xsl:template match=”text()”>
<xsl:value-of select=”normalize-space(.)”/>
</xsl:template> </xsl:stylesheet> ‘));

SELECT XMLTRANSFORM(w.warehouse_spec, x.col1).GetClobVal()
FROM warehouses w, xsl_tab x
WHERE w.warehouse_name = ‘San Francisco’;

http://psoug.org/reference/xml_functions.html

Complete list of environment variables on Windows 10

Tags

, ,

Use these environment variables to quickly browse Windows 10 locations on any computer.

 

https://pureinfotech.com/list-environment-variables-windows-10/